Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarthou Benoît
PRE
Commits
0de904ee
Commit
0de904ee
authored
Jul 19, 2017
by
sarthou
Browse files
Working on upsample, fixing the indexing problem, all clear but ZDisp, coding clamp is next step
parent
a24b73a8
Changes
4
Show whitespace changes
Inline
Side-by-side
InpaintingAlgorithm/algorithm/inpainting/dataSources/decorators/IDSDDownsampling.cpp
View file @
0de904ee
...
...
@@ -104,6 +104,10 @@ void IDSDDownsampling::MatlabUpsampleShiftMatrix(){
PaddedMatrix
<
int
>
*
GridY
=
new
PaddedMatrix
<
int
>
(
toDim
);
PaddedMatrix
<
int
>
*
GridZ
=
new
PaddedMatrix
<
int
>
(
toDim
);
PaddedMatrix
<
int
>
*
CoordX
=
new
PaddedMatrix
<
int
>
(
toDim
);
PaddedMatrix
<
int
>
*
CoordY
=
new
PaddedMatrix
<
int
>
(
toDim
);
PaddedMatrix
<
int
>
*
CoordZ
=
new
PaddedMatrix
<
int
>
(
toDim
);
// Creating Meshgrid
for
(
int
i
=
0
;
i
<
toDim
->
GetSizeX
();
i
++
){
for
(
int
j
=
0
;
j
<
toDim
->
GetSizeY
();
j
++
){
...
...
@@ -117,12 +121,6 @@ void IDSDDownsampling::MatlabUpsampleShiftMatrix(){
}
}
}
// std::cout << "GridX"<<std::endl;
// GridX->Mprint();
// std::cout << "GridY"<<std::endl;
// GridY->Mprint();
// std::cout << "GridZ"<<std::endl;
// GridZ->Mprint();
PaddedMatrixIt
nextVolIt
=
PaddedMatrixIt
(
toDim
);
do
{
...
...
@@ -130,6 +128,10 @@ void IDSDDownsampling::MatlabUpsampleShiftMatrix(){
fromXDispData
[
fromDim
->
DeterminePosition
(
GridX
->
GetData
()[
nextVolIt
.
GetPosition
()],
\
GridY
->
GetData
()[
nextVolIt
.
GetPosition
()],
GridZ
->
GetData
()[
nextVolIt
.
GetPosition
()])];
// CoordX->GetData()[nextVolIt.GetPosition()] = GridX->GetData()[nextVolIt.GetPosition()];
// CoordY->GetData()[nextVolIt.GetPosition()] = GridY->GetData()[nextVolIt.GetPosition()];
// CoordZ->GetData()[nextVolIt.GetPosition()] = GridZ->GetData()[nextVolIt.GetPosition()];
toYDispData
[
nextVolIt
.
GetPosition
()]
=
downsamplingRate
*
\
fromYDispData
[
fromDim
->
DeterminePosition
(
GridX
->
GetData
()[
nextVolIt
.
GetPosition
()],
\
GridY
->
GetData
()[
nextVolIt
.
GetPosition
()],
GridZ
->
GetData
()[
nextVolIt
.
GetPosition
()])];
...
...
@@ -145,6 +147,13 @@ void IDSDDownsampling::MatlabUpsampleShiftMatrix(){
}
while
(
nextVolIt
.
Next
());
// for(int nbFrame=0;nbFrame < toDim->GetSizeZ();nbFrame++)
// {
// CoordX->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/coord/Cpp_UA_CoordX_F"+std::to_string(nbFrame));
// CoordY->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/coord/Cpp_UA_CoordY_F"+std::to_string(nbFrame));
// CoordZ->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/coord/Cpp_UA_CoordZ_F"+std::to_string(nbFrame));
// }
}
PaddedMatrixDim
*
const
IDSDDownsampling
::
GetDim
(){
...
...
InpaintingAlgorithm/main.cpp
View file @
0de904ee
...
...
@@ -63,19 +63,19 @@ int main(){
for
(
int
nbFrame
=
0
;
nbFrame
<
downsampledDataSource
.
GetDim
()
->
GetSizeZ
();
nbFrame
++
)
{
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
/matlab_upsample/M_upsampleBefor
e_DispX_
L2_
F"
\
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
_ant/UA_matlab/M_UA_Ant
e_DispX_F"
\
+
std
::
to_string
(
nbFrame
)
+
".csv"
,
frame_x
,
1
);
downsampledDataSource
.
GetDispX
()
->
SetFrame
(
frame_x
,
nbFrame
);
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
/matlab_upsample/M_upsampleBefor
e_DispY_
L2_
F"
\
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
_ant/UA_matlab/M_UA_Ant
e_DispY_F"
\
+
std
::
to_string
(
nbFrame
)
+
".csv"
,
frame_y
,
1
);
downsampledDataSource
.
GetDispY
()
->
SetFrame
(
frame_y
,
nbFrame
);
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
/matlab_upsample/M_upsampleBefor
e_DispZ_
L2_
F"
\
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
_ant/UA_matlab/M_UA_Ant
e_DispZ_F"
\
+
std
::
to_string
(
nbFrame
)
+
".csv"
,
frame_z
,
1
);
downsampledDataSource
.
GetDispZ
()
->
SetFrame
(
frame_z
,
nbFrame
);
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
/matlab_upsample/M_upsampleBefor
e_DispA_
L2_
F"
\
openCVIO
.
LoadMatrixFromCSV
(
"Data/upsample
_ant/UA_matlab/M_UA_Ant
e_DispA_F"
\
+
std
::
to_string
(
nbFrame
)
+
".csv"
,
frame_a
,
1
);
downsampledDataSource
.
GetDispA
()
->
SetFrame
(
frame_a
,
nbFrame
);
}
...
...
@@ -89,10 +89,10 @@ int main(){
for
(
int
nbFrame
=
0
;
nbFrame
<
downsampledDataSource
.
GetDim
()
->
GetSizeZ
();
nbFrame
++
)
{
downsampledDataSource
.
GetDispX
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
/test_methodCpp/Out
_DispX_
L1_
F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispY
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
/test_methodCpp/Out
_DispY_
L1_
F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispZ
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
/test_methodCpp/Out
_DispZ_
L1_
F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispA
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
/test_methodCpp/Out
_DispA_
L1_
F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispX
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
_ant/Cpp_UA
_DispX_F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispY
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
_ant/Cpp_UA
_DispY_F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispZ
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
_ant/Cpp_UA
_DispZ_F"
+
std
::
to_string
(
nbFrame
));
downsampledDataSource
.
GetDispA
()
->
GetFrame
(
nbFrame
)
->
MprintToCSV
(
"Data/upsample
_ant/Cpp_UA
_DispA_F"
+
std
::
to_string
(
nbFrame
));
}
std
::
cout
<<
"End of upsample test"
<<
std
::
endl
;
...
...
MATLAB Inpainting/interpolate_disp_field.m
View file @
0de904ee
...
...
@@ -44,6 +44,16 @@ function[dispFieldOut] = interpolate_disp_field(dispFieldIn,imgVolFine,scaleStep
elseif
(
strcmp
(
interpType
,
'nearest'
))
sizeDispField
=
size
(
dispFieldIn
);
sizeImgVolFine
=
size
(
imgVolFine
);
cd
matlab_debug
/
little_upsample
for
nbframe
=
1
:
98
csvwrite
(
strcat
(
'M_UA_Ante_DispX_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldIn
(
1
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Ante_DispY_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldIn
(
2
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Ante_DispZ_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldIn
(
3
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Ante_DispA_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldIn
(
4
,:,:,
nbframe
)));
end
cd
..
/
..
%get the interpolated coordinates
if
(
sizeDispField
(
end
)
==
sizeImgVolFine
(
end
))
%no temporal subsampling
[
xCoordsFine
,
yCoordsFine
,
tCoordsFine
]
=
meshgrid
(
1
:
sizeImgVolFine
(
3
),
1
:
sizeImgVolFine
(
2
),
1
:
sizeImgVolFine
(
end
));
...
...
@@ -66,6 +76,7 @@ function[dispFieldOut] = interpolate_disp_field(dispFieldIn,imgVolFine,scaleStep
dispFieldY
=
squeeze
(
dispFieldIn
(
2
,:,:,:));
dispFieldT
=
squeeze
(
dispFieldIn
(
3
,:,:,:));
%interpolate the shift volume
linInds
=
sub2ind
(
size
(
dispFieldX
),
yCoordsInterp
,
xCoordsInterp
,
tCoordsInterp
);
dispFieldXinterp
=
reshape
(
scaleStep
*
dispFieldX
(
linInds
),
sizeDispFieldOut
(
2
:
4
));
...
...
@@ -76,6 +87,8 @@ function[dispFieldOut] = interpolate_disp_field(dispFieldIn,imgVolFine,scaleStep
dispFieldTinterp
=
reshape
(
scaleStep
*
dispFieldT
(
linInds
),
sizeDispFieldOut
(
2
:
4
));
end
saveDispTbeforeClamp
=
squeeze
(
dispFieldTinterp
(:,:,
68
));
%clamp the shift field
minBarrierX
=
ceil
(
patchSize
(
1
)/
2
)
*
ones
(
sizeDispFieldOut
(
2
:
4
));
maxBarrierX
=
(
sizeDispFieldOut
(
3
)
-
ceil
(
patchSize
(
1
)/
2
))
*
ones
(
sizeDispFieldOut
(
2
:
4
));
...
...
@@ -91,9 +104,33 @@ function[dispFieldOut] = interpolate_disp_field(dispFieldIn,imgVolFine,scaleStep
dispFieldOut
(
2
,:,:,:)
=
max
(
min
(
dispFieldYinterp
,
maxBarrierY
-
yCoordsFine
),
minBarrierY
-
yCoordsFine
);
dispFieldOut
(
3
,:,:,:)
=
max
(
min
(
dispFieldTinterp
,
maxBarrierT
-
tCoordsFine
),
minBarrierT
-
tCoordsFine
);
saveDispTafterClamp
=
squeeze
(
dispFieldOut
(
3
,:,:,
68
));
%size(saveDispXafterClamp)
cd
matlab_debug
/
little_upsample
/
for
nbframe
=
1
:
98
csvwrite
(
strcat
(
'M_CoordX_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
xCoordsInterp
(:,:,
nbframe
));
csvwrite
(
strcat
(
'M_CoordY_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
yCoordsInterp
(:,:,
nbframe
));
csvwrite
(
strcat
(
'M_CoordZ_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
tCoordsInterp
(:,:,
nbframe
));
end
csvwrite
(
'M_DispZ_BeforeClamp_F68.csv'
,
saveDispTbeforeClamp
);
csvwrite
(
'M_DispZ_AfterClamp_F68.csv'
,
saveDispTafterClamp
);
cd
..
/
..
%deal with the last field : the patch distance
dispFieldTemp
=
squeeze
(
dispFieldIn
(
4
,:,:,:));
dispFieldOut
(
4
,:,:,:)
=
reshape
(
dispFieldTemp
(
linInds
(:)),
sizeDispFieldOut
(
2
:
4
));
cd
matlab_debug
/
little_upsample
for
nbframe
=
1
:
98
csvwrite
(
strcat
(
'M_UA_Post_DispX_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldOut
(
1
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Post_DispY_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldOut
(
2
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Post_DispZ_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldOut
(
3
,:,:,
nbframe
)));
csvwrite
(
strcat
(
'M_UA_Post_DispA_F'
,
int2str
(
nbframe
-
1
),
'.csv'
),
squeeze
(
dispFieldOut
(
4
,:,:,
nbframe
)));
end
cd
..
/
..
'end'
end
end
\ No newline at end of file
dispcompare.py
View file @
0de904ee
...
...
@@ -6,7 +6,6 @@ MatlabPath = "Data/matlab_debug/"
CppPath
=
"Data/debug/"
np
.
set_printoptions
(
threshold
=
np
.
nan
)
# Attention cette partie est à remplir à la main
########Paramètres#####################
# On choisit ici la frame à observer, attention Matlab est en +1
...
...
@@ -92,23 +91,36 @@ def evolution(path,MorC,nbFrame,XYZ,idIter):
return
0
def
upsample_compare
(
Mpath
,
Cpath
,
nbFrame
,
XYZ
,
level
,
OccMask
,
outPath
,
inputMorC
):
def
upsample_compare
(
Mpath
,
Cpath
,
nbFrame
,
XYZ
,
level
,
OccMask
,
outPath
,
inputMorC
,
levelBool
):
"This function is to compare two set of data, in .csv matrices, and produce a visual output (in .png)"
results
=
[]
for
i
in
range
(
nbFrame
):
if
(
inputMorC
==
0
):
temp_matlab
=
np
.
genfromtxt
(
Mpath
+
XYZ
+
"_L"
+
str
(
level
)
+
"_F"
+
str
(
i
)
+
".csv"
,
delimiter
=
','
)
for
i
in
range
(
1
,
nbFrame
):
# Add level in the pathway
if
(
levelBool
==
True
):
endPath
=
"_L"
+
str
(
level
)
+
"_F"
else
:
temp_matlab
=
np
.
genfromtxt
(
Mpath
+
XYZ
+
"_L"
+
str
(
level
)
+
"_F"
+
str
(
i
)
+
".csv"
,
delimiter
=
';'
)
endPath
=
"_F"
# Load matrices from the first path
if
(
inputMorC
==
'Matlab'
):
temp_matlab
=
np
.
genfromtxt
(
Mpath
+
XYZ
+
endPath
+
str
(
i
-
1
)
+
".csv"
,
delimiter
=
','
)
else
:
temp_matlab
=
np
.
genfromtxt
(
Mpath
+
XYZ
+
endPath
+
str
(
i
)
+
".csv"
,
delimiter
=
';'
)
end_m
=
np
.
shape
(
temp_matlab
)[
1
]
temp_matlab
=
temp_matlab
[:,
0
:
end_m
-
1
]
temp_cpp
=
np
.
genfromtxt
(
Cpath
+
XYZ
+
"_L"
+
str
(
level
)
+
"_F"
+
str
(
i
)
+
".csv"
,
delimiter
=
';'
)
# Load matrices for the second path
endPath
=
endPath
+
str
(
i
)
+
".csv"
temp_cpp
=
np
.
genfromtxt
(
Cpath
+
XYZ
+
endPath
,
delimiter
=
';'
)
end
=
np
.
shape
(
temp_cpp
)[
1
]
diff
=
temp_matlab
-
temp_cpp
[:,
0
:
end
-
1
]
# print(diff)
if
(
np
.
sum
(
diff
)
!=
0
):
print
(
"i:"
,
i
)
print
(
100
*
diff
)
plt
.
imsave
(
outPath
+
XYZ
+
"_F"
+
str
(
i
)
+
".png"
,
diff
,
cmap
=
"seismic"
)
diff
[
diff
!=
0
]
=
1
...
...
@@ -162,17 +174,62 @@ if __name__=="__main__":
# plt.imshow(VolOnion[3,:,:,])
# plt.show()
# # upsample compare between Matlab and C++ with new implementation
# upsample_compare("Data/upsample/matlab_upsample/M_upsampleAfter_",\
# "Data/upsample/
test_methodCpp/
CppOut_",98,"
Z
",1,OccMediumMask,"Data/upsample/results/DiffNewFunc_",
0
)
# "Data/upsample/CppOut_",98,"
DispX
",1,OccMediumMask,"Data/upsample/results/DiffNewFunc_",
'Matlab',True
)
# # Upsample compare between C++ old and new implementation
# upsample_compare("Data/upsample/CppOut_",\
# "Data/upsample/test_methodCpp/CppOut_",98,"DispX",1,OccMediumMask,"Data/upsample/results/DiffMethod_",1)
# # Result: Implementation successful, same result in output, the problem is somewhere else.
# # Transformer .csv en image
# for i in range(98):
# img = np.genfromtxt("Data/upsample/test_methodCpp/CppOut_DispX_L1_F"+str(i)+".csv",delimiter=";")
# plt.imsave("Data/upsample/test_methodCpp/test_DispX_L1_F"+str(i)+".png",img,cmap='seismic')
# Displaying Disp and Grad differences for a SR iteration
upsample_compare
(
"Data/search_reconstruct/SR_matlab/M_SR_Post_"
,
\
"Data/search_reconstruct/CppOut_SR_"
,
98
,
"GradY"
,
3
,
OccMediumMask
,
"Data/search_reconstruct/SR_result/Diff_SR_"
,
0
)
# # Displaying Disp and Grad differences for a SR iteration
# upsample_compare("Data/search_reconstruct/SR_matlab/M_SR_Post_",\
# "Data/search_reconstruct/CppOut_SR_",98,"GradY",3,\
# OccMediumMask,"Data/search_reconstruct/SR_result/Diff_SR_",0)
# # Result: Huge difference...
# # Comparing before and after clamp matrices in Matlab algorithm
# im1 = np.genfromtxt("Data/upsample_ant/M_DispX_BeforeClamp_F32.csv",delimiter=',')
# im2 = np.genfromtxt("Data/upsample_ant/M_DispX_AfterClamp_F32.csv",delimiter=',')
#
# plt.imsave("Data/upsample_ant/M_DispX_DiffClamp_F32.png",im1-im2)
# # Result: Exactly the same, clamp unusued
# #Compare the output of data out of C++ algo, after and before
# upsample_compare("Data/upsample_ant/M_UA_Post_","Data/upsample_ant/Cpp_UA_",\
# 98,"DispY",3,OccMediumMask,"Data/upsample_ant/DiffOut_UA_",'Matlab',False)
# # Result: Exactly the same, there is a problem in the analysis
# # Compare just two frames of DispA for more details
# im1 = np.genfromtxt("Data/upsample/matlab_upsample/M_upsampleAfter_DispA_L1_F47.csv",delimiter=',')
# im2 = np.genfromtxt("Data/upsample/CppOut_DispA_L1_F48.csv",delimiter=';')
# end = np.shape(im2)[1]
# plt.imsave("Data/upsample/results/DiffM_NewC_DispA_L1_F48.png",im1-im2[:,0:end-1],cmap='seismic')
# # Result: Ok there is a problem in the indexation of data...
# # Upsample compare of DispA to test the indexation problem
# upsample_compare("Data/upsample/matlab_upsample/M_upsampleAfter_",\
# "Data/upsample/test_methodCpp/CppOut_",98,"DispZ",1,OccMediumMask,"Data/upsample/results/NewIndNewImp_",'Matlab',True)
# # Result: There was indeed an index problem... X,Y and A exactly the same, but problem with the Z, with small peak of differences.
# # Looking differences between coords of upsample (M vs Cpp) to see the problem on Z
# for i in range(98):
# im1 = np.genfromtxt("Data/upsample_ant/coord/M_CoordZ_F"+str(i)+".csv",delimiter=',')
# im2 = np.genfromtxt("Data/upsample_ant/coord/Cpp_UA_CoordZ_F"+str(i)+".csv",delimiter=';')
# end = np.shape(im2)[1]
# print(np.sum(im1-im2[:,0:end-1]-np.ones(np.shape(im1))))
# plt.imsave("Data/upsample_ant/coord/Diff_UA_CoordZ_F"+str(i)+".png",im1-im2[:,0:end-1])
# # Result: Don't seem to have a difference in the coord matrices between matlab and C++, maybe during clamp ?
# Comparing before and after clamp matrices in Matlab algorithm
im1
=
np
.
genfromtxt
(
"Data/upsample_ant/M_DispZ_BeforeClamp_F68.csv"
,
delimiter
=
','
)
im2
=
np
.
genfromtxt
(
"Data/upsample_ant/M_DispZ_AfterClamp_F68.csv"
,
delimiter
=
','
)
plt
.
imsave
(
"Data/upsample_ant/M_DispZ_DiffClamp_F68.png"
,
im1
-
im2
)
# Result: On Z, there is a difference, so clamp might be useful
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment