Commit 8f8711b7 authored by sarthou's avatar sarthou
Browse files

WOrking on divergence lead, and especially the differences in upsample

parent 7a9222f9
...@@ -36,12 +36,18 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa ...@@ -36,12 +36,18 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa
iProfiler->BeforeInpaintingIteration(curLevel, iteration); iProfiler->BeforeInpaintingIteration(curLevel, iteration);
if(curLevel == downsamplingLevels-1 && iteration == 0) if(curLevel == downsamplingLevels-1 && iteration == 0)
{ {
//OnionPeelInitialisation(&downsampledDataSource, iProfiler); OnionPeelInitialisation(&downsampledDataSource, iProfiler);
LoadingInitialisation(&downsampledDataSource,iProfiler); // LoadingInitialisation(&downsampledDataSource,iProfiler);
} }
else{ else{
iSearcher->Search(&detailedOcclusionDataSource, false); iSearcher->Search(&detailedOcclusionDataSource, false);
// openCVIO.GeneralIOForRGB(downsampledDataSource.GetRed(), \
// downsampledDataSource.GetGreen(), downsampledDataSource.GetBlue(),\
// 32, InpaintingIO::IH_DBG_SAVE,\
// "Data/divergence/CppOutDiv_F32_L" + std::to_string(curLevel)+"_I"+std::to_string(iteration));
residual = iReconstructor->Reconstruct(&detailedOcclusionDataSource, false); residual = iReconstructor->Reconstruct(&detailedOcclusionDataSource, false);
} }
iProfiler->AfterInpaintingIteration(curLevel, iteration); iProfiler->AfterInpaintingIteration(curLevel, iteration);
...@@ -50,6 +56,13 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa ...@@ -50,6 +56,13 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa
if(curLevel != 0) if(curLevel != 0)
downsampledDataSource.UpsampleShiftMatrices(); downsampledDataSource.UpsampleShiftMatrices();
for(int i = 0; i < downsampledDataSource.GetDim()->GetSizeZ(); ++i)
openCVIO.GeneralIOForRGB(downsampledDataSource.GetRed(), \
downsampledDataSource.GetGreen(), downsampledDataSource.GetBlue(), i,\
InpaintingIO::IH_DBG_SAVE, "Data/divergence/cpp_divergence/CppOutDiv_L" \
+ std::to_string(curLevel)+"_F"+std::to_string(i));
iProfiler->AfterInpaintingIterations(curLevel); iProfiler->AfterInpaintingIterations(curLevel);
iProfiler->AfterInpaintLevel(curLevel); iProfiler->AfterInpaintLevel(curLevel);
} }
...@@ -78,6 +91,8 @@ void InpaintingConverger::OnionPeelInitialisation(InpaintingDataSource * const i ...@@ -78,6 +91,8 @@ void InpaintingConverger::OnionPeelInitialisation(InpaintingDataSource * const i
iProfiler->AfterInitialisation(); iProfiler->AfterInitialisation();
} }
void InpaintingConverger::LoadingInitialisation(InpaintingDataSource * const iDataSource,InpaintingProfiler * const iProfiler){ void InpaintingConverger::LoadingInitialisation(InpaintingDataSource * const iDataSource,InpaintingProfiler * const iProfiler){
iProfiler->BeforeInitialisation(); iProfiler->BeforeInitialisation();
InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO(); InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO();
......
...@@ -18,12 +18,16 @@ int main(){ ...@@ -18,12 +18,16 @@ int main(){
const std::string videoFileName = "resources/beach_umbrella.avi"; const std::string videoFileName = "resources/beach_umbrella.avi";
const std::string occFileName = "resources/beach_umbrella_occlusion.png"; const std::string occFileName = "resources/beach_umbrella_occlusion.png";
// const std::string videoFileName = "Data/resources/Oreo/Oreo.avi";
// const std::string occFileName = "Data/resources/Oreo/OreoHD-Occlusion.png";
profiler.BeforeInpainting(); profiler.BeforeInpainting();
// Select and parameterize the algorithms // Select and parameterize the algorithms
InpaintingEvaluator evaluationAlgo = InpaintingEvaluator(50, 5, 5, 5); InpaintingEvaluator evaluationAlgo = InpaintingEvaluator(50, 5, 5, 5);
ISRandom searchAlgo = ISRandom(30, &evaluationAlgo); //initiated at 20, but 10 in Matlab code ISRandom searchAlgo = ISRandom(20, &evaluationAlgo); //initiated at 20, but 10 in Matlab code
// ISFull searchAlgo = ISFull(&evaluationAlgo); // ISFull searchAlgo = ISFull(&evaluationAlgo);
IRWeightedAverage reconstructAlgo = IRWeightedAverage(0.75f, 5, 5, 5); IRWeightedAverage reconstructAlgo = IRWeightedAverage(0.75f, 5, 5, 5);
//IRBestPatch reconstructAlgo = IRBestPatch(5, 5, 5); //IRBestPatch reconstructAlgo = IRBestPatch(5, 5, 5);
...@@ -38,23 +42,6 @@ int main(){ ...@@ -38,23 +42,6 @@ int main(){
int sizeX, sizeY, sizeZ; int sizeX, sizeY, sizeZ;
openCVIO.GetVideoDimensions(videoFileName, sizeX, sizeY, sizeZ); openCVIO.GetVideoDimensions(videoFileName, sizeX, sizeY, sizeZ);
/*
PaddedMatrixDim * const testdim = new PaddedMatrixDim(66,17,98);
PaddedMatrixDim * const testdimframe = new PaddedMatrixDim(66,17,1);
PaddedMatrix<float> * const occTestMatrix = new PaddedMatrix<float>(testdim);
PaddedMatrix<float> * const TestFrame = new PaddedMatrix<float>(testdimframe);
// std::cout << "(" << occTestMatrix->GetFrame(27)->GetDimension()->GetSizeX()<<\
// ":"<<occTestMatrix->GetFrame(27)->GetDimension()->GetSizeY() << ":"<<\
// occTestMatrix->GetFrame(27)->GetDimension()->GetSizeZ() <<")"<<std::endl;
// std::cout << typeid(occTestMatrix->GetFrame(27)).name() << std::endl;
openCVIO.LoadMatrixFromCSV("Data/onion_debug/peel_compare/end_peel_disp/M_EndPeel_DispX_27.csv",TestFrame,1);
std::cout << "Affichage"<<std::endl;
occTestMatrix->SetFrame(TestFrame,27);
occTestMatrix->GetFrame(27)->Mprint();
//std::cout << occTestMatrix->GetData()[30294] << std::endl;
*/
PaddedMatrixDim * const dim = new PaddedMatrixDim(sizeX, sizeY, sizeZ, 2, 2, 2); PaddedMatrixDim * const dim = new PaddedMatrixDim(sizeX, sizeY, sizeZ, 2, 2, 2);
PaddedMatrix<float> * const redMatrix = new PaddedMatrix<float>(dim); PaddedMatrix<float> * const redMatrix = new PaddedMatrix<float>(dim);
...@@ -65,6 +52,47 @@ int main(){ ...@@ -65,6 +52,47 @@ int main(){
openCVIO.LoadOcclusionMatrixFromImage(occFileName, occMatrix); openCVIO.LoadOcclusionMatrixFromImage(occFileName, occMatrix);
IDSConcrete baseIPS = IDSConcrete(dim, redMatrix, greenMatrix, blueMatrix, occMatrix); IDSConcrete baseIPS = IDSConcrete(dim, redMatrix, greenMatrix, blueMatrix, occMatrix);
IDSDDownsampling downsampledDataSource = IDSDDownsampling(&baseIPS, 3, 2);
PaddedMatrix<int> * const frame_x = new PaddedMatrix<int>(downsampledDataSource.GetDim());
PaddedMatrix<int> * const frame_y = new PaddedMatrix<int>(downsampledDataSource.GetDim());
PaddedMatrix<int> * const frame_z = new PaddedMatrix<int>(downsampledDataSource.GetDim());
PaddedMatrix<float> * const frame_a = new PaddedMatrix<float>(downsampledDataSource.GetDim());
for(int nbFrame=0;nbFrame<downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
{
openCVIO.LoadMatrixFromCSV("Data/upsample/matlab_upsample/M_upsampleBefore_DispX_L2_F"\
+std::to_string(nbFrame)+".csv",frame_x,1);
downsampledDataSource.GetDispX()->SetFrame(frame_x,nbFrame);
openCVIO.LoadMatrixFromCSV("Data/upsample/matlab_upsample/M_upsampleBefore_DispY_L2_F"\
+std::to_string(nbFrame)+".csv",frame_y,1);
downsampledDataSource.GetDispY()->SetFrame(frame_y,nbFrame);
openCVIO.LoadMatrixFromCSV("Data/upsample/matlab_upsample/M_upsampleBefore_DispZ_L2_F"\
+std::to_string(nbFrame)+".csv",frame_z,1);
downsampledDataSource.GetDispZ()->SetFrame(frame_z,nbFrame);
openCVIO.LoadMatrixFromCSV("Data/upsample/matlab_upsample/M_upsampleBefore_DispA_L2_F"\
+std::to_string(nbFrame)+".csv",frame_a,1);
downsampledDataSource.GetDispA()->SetFrame(frame_a,nbFrame);
}
downsampledDataSource.UpsampleShiftMatrices();
downsampledDataSource.SetCurLevel(1);
for(int nbFrame=0;nbFrame < downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
{
downsampledDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispX_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispY_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispZ_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispA_L1_F"+std::to_string(nbFrame));
}
// Execute the work // Execute the work
inpainter.Inpaint(&baseIPS, &profiler); inpainter.Inpaint(&baseIPS, &profiler);
...@@ -76,7 +104,7 @@ int main(){ ...@@ -76,7 +104,7 @@ int main(){
// Output the new images. // Output the new images.
for(int i = 0; i < baseIPS.GetDim()->GetSizeZ(); ++i) for(int i = 0; i < baseIPS.GetDim()->GetSizeZ(); ++i)
openCVIO.GeneralIOForRGB(baseIPS.GetRed(), baseIPS.GetGreen(), baseIPS.GetBlue(), i, openCVIO.GeneralIOForRGB(baseIPS.GetRed(), baseIPS.GetGreen(), baseIPS.GetBlue(), i,
InpaintingIO::IH_DBG_SAVE, "Data/onion_debug/CppOut_WithMatlabInput30_F" + std::to_string(i)); InpaintingIO::IH_DBG_SAVE, "Data/other_tests/CppOut_Oreo_F" + std::to_string(i));
profiler.AfterInpainting(); profiler.AfterInpainting();
......
...@@ -80,8 +80,34 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin) ...@@ -80,8 +80,34 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
% If we are not at the coarsest level... % If we are not at the coarsest level...
if (ii~=maxLevel) if (ii~=maxLevel)
% ... upsample the previous shift map... % ... upsample the previous shift map...
shiftVol = single(interpolate_disp_field(shiftVol,imgVol,1/scaleStep, patchSize,'nearest'));
% cd matlab_debug/test_upsample
%
% [~,w,l,maxFrame] = size(shiftVol);
% for nbframe=1:maxFrame
% csvwrite(strcat(strcat('M_upsampleBefore_DispX_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleBefore_DispY_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleBefore_DispZ_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleBefore_DispA_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(4,:,:,nbframe),[w,l]));
% end
%
% cd ../..
%
%
%
% shiftVol = single(interpolate_disp_field(shiftVol,imgVol,1/scaleStep, patchSize,'nearest'));
%
% cd matlab_debug/test_upsample
%
% [~,w,l,maxFrame] = size(shiftVol);
% for nbframe=1:maxFrame
% csvwrite(strcat(strcat('M_upsampleAfter_DispX_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleAfter_DispY_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleAfter_DispZ_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_upsampleAfter_DispA_L',int2str(ii),'_F',int2str(nbframe),'.csv')),reshape(shiftVol(4,:,:,nbframe),[w,l]));
% end
%
% cd ../..
% ... and recreate image volume. % ... and recreate image volume.
if (exist('featurePyramid','var')) if (exist('featurePyramid','var'))
[imgVol,gradX,gradY,normGradX,normGradY] = ... [imgVol,gradX,gradY,normGradX,normGradY] = ...
...@@ -139,19 +165,16 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin) ...@@ -139,19 +165,16 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
occVolDilate,... occVolDilate,...
occVolDilate); occVolDilate);
% endfile = strcat('_',strcat(int2str(100*(maxLevel-ii+1)+pp-1),'.csv'));
% imgVolCopy = permute(imgVol,[2 3 4 1]);
% cd matlab_debug %size(imgVolCopy(:,:,32,:))
%
% [~,w,l,maxFrame] = size(shiftVol); % cd matlab_debug/divergence/full_div
% %
% for nbframe=1:maxFrame % imwrite(uint8(squeeze(imgVolCopy(:,:,32,:))),strcat('M_FullDiv_F32_L',int2str(ii),'_I_',int2str(pp),'.png'));
% csvwrite(strcat('M_DispX_',strcat(int2str(nbframe),endfile)),reshape(shiftVol(1,:,:,nbframe),[w,l])); % imwrite(uint8(squeeze(occVolDilate(:,:,32))),strcat('M_OccMask_F32_L',int2str(ii),'_I_',int2str(pp),'.png'))
% csvwrite(strcat('M_DispY_',strcat(int2str(nbframe),endfile)),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat('M_DispZ_',strcat(int2str(nbframe),endfile)),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% end
% %
% cd .. % cd ../../..
% Carry out the reconstruction % Carry out the reconstruction
if (exist('featurePyramid','var')) if (exist('featurePyramid','var'))
...@@ -333,22 +356,19 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin) ...@@ -333,22 +356,19 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
imgOut = imgVol; imgOut = imgVol;
shiftVolOut = shiftVol; shiftVolOut = shiftVol;
size(shiftVolOut) size(shiftVolOut)
% cd ../Data;
% write_image_volume(shiftVolOut,strcat('disp',str((maxLevel-ii)*100 + pp);
% cd ../MATLAB Inpainting
return; return;
end end
write_image_volume(imgVol,strcat('matlab_debug/divergence/M_L',int2str(ii)));
%erase some of the video structures %erase some of the video structures
clearvars imgVol occVolDilate occVolPatchMatch; clearvars imgVol occVolDilate occVolPatchMatch;
patchMatchParams.partialComparison = 0; patchMatchParams.partialComparison = 0;
useAllPatches = 1; useAllPatches = 1;
end
end,
imgOut = imgVol; imgOut = imgVol;
end end
...@@ -10,16 +10,24 @@ np.set_printoptions(threshold=np.nan) ...@@ -10,16 +10,24 @@ np.set_printoptions(threshold=np.nan)
CppPath = "Data/out_cpp_random/D:\\temp\\finalReconstructedImgF" CppPath = "Data/out_cpp_random/D:\\temp\\finalReconstructedImgF"
MatlabPath = "Data/Out_matlab_random/beach_umbrellainpainted_frame_0" MatlabPath = "Data/Out_matlab_random/beach_umbrellainpainted_frame_0"
OccPath = "Data/resources/beach_umbrella_occlusion.png" OccPath = "Data/resources/beach_umbrella_occlusion.png"
OccMediumPath = "Data/divergence/full_div/M_OccMask_F32_L2_I_1.png"
OccSmallPath = "Data/onion_debug/Occ/OccF0.png"
OriFilePath = "Data/resources/beach_umbrella_f" OriFilePath = "Data/resources/beach_umbrella_f"
Rand1Path = "Data/random_compare/OneRandImgF" Rand1Path = "Data/random_compare/OneRandImgF"
Rand2Path = "Data/random_compare/ThreeRandImgF" Rand2Path = "Data/random_compare/ThreeRandImgF"
Cpp10 = "Data/onion_debug/CppOutF" Cpp10 = "Data/onion_debug/CppOutF"
Cpp30 = "Data/onion_debug/CppOut30F" Cpp30 = "Data/onion_debug/CppOut30F"
PeelMatlab = "Data/onion_debug/peel_compare/M_EndPeel_F_frame_" PeelMatlab = "Data/onion_debug/peel_compare/M_EndPeel_F_frame_"
PeelCpp = "Data/onion_debug/peel_compare/Cpp_EndPeel_F" PeelCpp = "Data/onion_debug/peel_compare/Cpp_EndPeel_F"
OccSmallPath = "Data/onion_debug/Occ/OccF0.png"
CppLoadingPath = "Data/onion_debug/CppOut_WithMatlabInput_F" CppLoadingPath = "Data/onion_debug/CppOut_WithMatlabInput_F"
DivCpp = "Data/divergence/cpp_divergence/CppOutDiv_L"
DivMatlab = "Data/divergence/matlab_divergence/M_L"
# print(OccMask) # print(OccMask)
threshold_nbPixDiff = 0.1 threshold_nbPixDiff = 0.1
...@@ -170,16 +178,29 @@ if __name__ == '__main__': ...@@ -170,16 +178,29 @@ if __name__ == '__main__':
OccSmallMask[OccSmallMask<0.1]=0 OccSmallMask[OccSmallMask<0.1]=0
OccSmallMask[OccSmallMask>=0.1]=255 OccSmallMask[OccSmallMask>=0.1]=255
OccMediumMask = io.imread(OccMediumPath,as_grey=True)
OccMediumMask[OccMediumMask<0.1]=0
OccMediumMask[OccMediumMask>=0.1]=255
VolMatlab = np.zeros((98,68,264,3)) VolMatlab = np.zeros((98,68,264,3))
VolCpp = np.zeros((98,68,264,3)) VolCpp = np.zeros((98,68,264,3))
VolOri = np.zeros((98,68,264,3)) VolOri = np.zeros((98,68,264,3))
VolRand1 = np.zeros((98,68,264,3)) # VolRand1 = np.zeros((98,68,264,3))
VolRand2 = np.zeros((98,68,264,3)) # VolRand2 = np.zeros((98,68,264,3))
VolCpp10 = np.zeros((98,68,264,3)) # VolCpp10 = np.zeros((98,68,264,3))
VolCpp30 = np.zeros((98,68,264,3)) # VolCpp30 = np.zeros((98,68,264,3))
VolPeelM = np.zeros((98,17,66,3)) # VolPeelM = np.zeros((98,17,66,3))
VolPeelC = np.zeros((98,17,66,3)) # VolPeelC = np.zeros((98,17,66,3))
VolCppLoad = np.zeros((98,68,264,3)) # VolCppLoad = np.zeros((98,68,264,3))
VolCppDiv1 = np.zeros((98,68,264,3))
VolCppDiv2 = np.zeros((98,34,132,3))
VolCppDiv3 = np.zeros((98,17,66,3))
VolMatlabDiv1 = np.zeros((98,68,264,3))
VolMatlabDiv2 = np.zeros((98,34,132,3))
VolMatlabDiv3 = np.zeros((98,17,66,3))
# Chargement des images dans un volume # Chargement des images dans un volume
for i in range(98): for i in range(98):
if(i<9): if(i<9):
...@@ -194,22 +215,41 @@ if __name__ == '__main__': ...@@ -194,22 +215,41 @@ if __name__ == '__main__':
# img_rand2 = io.imread(Rand2Path+str(i)+".png") # img_rand2 = io.imread(Rand2Path+str(i)+".png")
# img_cpp10 = io.imread(Cpp10+str(i)+".png") # img_cpp10 = io.imread(Cpp10+str(i)+".png")
# img_cpp30 = io.imread(Cpp30+str(i)+".png") # img_cpp30 = io.imread(Cpp30+str(i)+".png")
img_peelM = io.imread(PeelMatlab+str(i)+".png") # img_peelM = io.imread(PeelMatlab+str(i)+".png")
img_peelC = io.imread(PeelCpp+str(i)+".png") # img_peelC = io.imread(PeelCpp+str(i)+".png")
img_load = io.imread(CppLoadingPath+str(i)+".png") # img_load = io.imread(CppLoadingPath+str(i)+".png")
# img_divcpp1 = io.imread(DivCpp+"1_F"+str(i)+".png")
img_divcpp2 = io.imread(DivCpp+"2_F"+str(i)+".png")
img_divcpp3 = io.imread(DivCpp+"3_F"+str(i)+".png")
img_divmatlab1 = io.imread(DivMatlab+"1_F_"+str(i)+".png")
img_divmatlab2 = io.imread(DivMatlab+"2_F_"+str(i)+".png")
img_divmatlab3 = io.imread(DivMatlab+"3_F_"+str(i)+".png")
# print(img_cpp.shape) # print(img_cpp.shape)
VolMatlab[i,:,:,:]=img_matlab VolMatlab[i,:,:,:]=img_matlab
VolCpp[i,:,:,:]=img_cpp VolCpp[i,:,:,:]=img_cpp
VolOri[i:,:,:,:]=img_ori VolOri[i:,:,:,:]=img_ori
VolCppDiv1[i,:,:,:] = img_cpp
VolCppDiv2[i,:,:,:] = img_divcpp2
VolCppDiv3[i,:,:,:] = img_divcpp3
VolMatlabDiv1[i,:,:,:] = img_divmatlab1
VolMatlabDiv2[i,:,:,:] = img_divmatlab2
VolMatlabDiv3[i,:,:,:] = img_divmatlab3
# VolRand1[i,:,:,:]=img_rand1 # VolRand1[i,:,:,:]=img_rand1
# VolRand2[i,:,:,:]=img_rand2 # VolRand2[i,:,:,:]=img_rand2
# VolCpp10[i,:,:,:]=img_cpp10 # VolCpp10[i,:,:,:]=img_cpp10
# VolCpp30[i,:,:,:]=img_cpp30 # VolCpp30[i,:,:,:]=img_cpp30
VolPeelC[i,:,:,:]=img_peelC # VolPeelC[i,:,:,:]=img_peelC
VolPeelM[i,:,:,:]=img_peelM # VolPeelM[i,:,:,:]=img_peelM
VolCppLoad[i,:,:,:]=img_load # VolCppLoad[i,:,:,:]=img_load
# # Code for video # # Code for video
# cap = cv2.VideoCapture(OriFilePath) # cap = cv2.VideoCapture(OriFilePath)
# i=0 # i=0
...@@ -273,6 +313,27 @@ if __name__ == '__main__': ...@@ -273,6 +313,27 @@ if __name__ == '__main__':
# plt.title("Evolution de la différence de pixel entre le code C++ avec et sans initialisation en pelure d'onion") # plt.title("Evolution de la différence de pixel entre le code C++ avec et sans initialisation en pelure d'onion")
# plt.show() # plt.show()
# # Affichage résultat de la comparaison des pixels dans la zone du masque
# pixCountL1 = np.zeros((3,98))
# pixCountL2 = np.zeros((3,98))
# pixCountL3 = np.zeros((3,98))
# for i in range(98):
# pixCountL1[:,i]=PixCompare(VolCppDiv1[i,:,:,:],VolMatlabDiv1[i,:,:,:],OccMask,0.1)
# pixCountL2[:,i]=PixCompare(VolCppDiv2[i,:,:,:],VolMatlabDiv2[i,:,:,:],OccMediumMask,0.1)
# pixCountL3[:,i]=PixCompare(VolCppDiv3[i,:,:,:],VolMatlabDiv3[i,:,:,:],OccSmallMask,0.1)
#
# plt.plot((pixCountL1[0,:]+pixCountL1[1,:]+pixCountL1[2,:])/3,'black',label='L1 (more detailed)')
# plt.plot((pixCountL2[0,:]+pixCountL2[1,:]+pixCountL2[2,:])/3,'blue',label='L2')
# plt.plot((pixCountL3[0,:]+pixCountL3[1,:]+pixCountL3[2,:])/3,'red',label='L3 (less detailed)')
#
# # plt.axhline(0.05)
# plt.xlabel("number of frame (time)")
# plt.ylabel("Percentage of pixels different in each image on the mask")
# plt.legend()
# plt.title("Evolution de la différence de pixel entre les images Matlab et C++ sur les niveaux de pyramides")
# plt.show()
# ## Evolution du PSNR dans la vidéo # ## Evolution du PSNR dans la vidéo
# PSNR_vol = np.zeros((4,98)) # PSNR_vol = np.zeros((4,98))
# for i in range(98): # for i in range(98):
...@@ -357,4 +418,29 @@ if __name__ == '__main__': ...@@ -357,4 +418,29 @@ if __name__ == '__main__':
# plt.show() # plt.show()
# VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp") # VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp")
visual_compare(VolCpp,VolCppLoad,"Data/onion_debug/peel_compare/visual_comp_cpp_matlab_loading/CompLoadF") # visual_compare(VolCpp,VolCppLoad,"Data/onion_debug/peel_compare/visual_comp_cpp_matlab_loading/CompLoadF")
# Evolution de la différence de pixel au fil des iterations entre Matlab et C++
Cpath = "Data/divergence/CppOutDiv_F32_L"
Mpath = "Data/divergence/full_div/M_FullDiv_F32_L"
values = []
for i in range(1,8):
im1 = io.imread(Cpath+str(3)+"_I"+str(i)+".png")
im2 = io.imread(Mpath+str(3)+"_I_"+str(i+1)+".png")
values.append(np.sum(PixCompare(im1,im2,OccSmallMask,0.1)))
for i in range(1,9):
im1 = io.imread(Cpath+str(2)+"_I"+str(i)+".png")
im2 = io.imread(Mpath+str(2)+"_I_"+str(i+1)+".png")
values.append(np.sum(PixCompare(im1,im2,OccMediumMask,0.1)))
for i in range(1,13):
im1 = io.imread(Cpath+str(1)+"_I"+str(i)+".png")
im2 = io.imread(Mpath+str(1)+"_I_"+str(i+1)+".png")
values.append(np.sum(PixCompare(im1,im2,OccMask,0.1)))
plt.plot(values)
plt.axvline(x=6.5,color='r')
plt.axvline(x=14.5,color='r')
plt.xlabel("Iterations")
plt.ylabel("Pourcentage de pixels différents sur le masque d'occlusion")
plt.title("Evolution de la différence de pixels au fil des iterations entre Matlab et C++")
plt.show()
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from skimage import io
MatlabPath = "Data/matlab_debug/" MatlabPath = "Data/matlab_debug/"
CppPath = "Data/debug/" CppPath = "Data/debug/"
np.set_printoptions(threshold=np.nan)
# Attention cette partie est à remplir à la main # Attention cette partie est à remplir à la main
########Paramètres##################### ########Paramètres#####################
# On choisit ici la frame à observer, attention Matlab est en +1 # On choisit ici la frame à observer, attention Matlab est en +1
...@@ -88,7 +92,51 @@ def evolution(path,MorC,nbFrame,XYZ,idIter): ...@@ -88,7 +92,51 @@ def evolution(path,MorC,nbFrame,XYZ,idIter):
return 0 return 0
def upsample_compare(Mpath,Cpath,nbFrame,XYZ,level,OccMask):
results=[]
for i in range(nbFrame):
temp_matlab = np.genfromtxt(Mpath+"Disp"+XYZ+"_L"+str(level+1)+"_F"+str(i+1)+".csv",delimiter=',')
temp_cpp = np.genfromtxt(Cpath+"Disp"+XYZ+"_L"+str(level)+"_F"+str(i)+".csv",delimiter=';')
end = np.shape(temp_cpp)[1]
diff = temp_matlab-temp_cpp[:,0:end-1]
# print(diff)
plt.imsave("Data/upsample/results/Diff_"+XYZ+"_F"+str(i)+".png",diff,cmap="seismic")
diff[diff!=0]=1
diff_sum = 0
diff_total = 0
for i in range(np.shape(diff)[0]):
for j in range(np.shape(diff)[1]):
if(OccMask[i][j]==255):
diff_total+=1
if(diff[i][j]==1):
diff_sum+=1
# print("diff_sum",diff_sum,"diff_total",diff_total)
results.append((diff_sum*100)/diff_total)
plt.plot(results[3:97])
plt.axhline(np.mean(results[3:97]),color='red')
plt.xlabel("Frames")
plt.ylabel("Pourcentage de différence sur le masque")
plt.title("Evolution de la différence entre les cartes de déplacement établis par les algorithmes d'augmentation \n \
Direction: "+XYZ+" Avg:"+str(np.mean(results[3:97]))+" Ecart-type: "+str(np.std(results[3:97])))
plt.show()
return results
if __name__=="__main__": if __name__=="__main__":
OccMediumPath = "Data/divergence/full_div/M_OccMask_F32_L2_I_1.png"
OccMediumMask = io.imread(OccMediumPath,as_grey=True)
OccMediumMask[OccMediumMask<0.1]=0
OccMediumMask[OccMediumMask>=0.1]=255
# compare(frame,XYZ,MatlabPath,CppPath,iterLevel) # compare(frame,XYZ,MatlabPath,CppPath,iterLevel)
# evolution(CppPath,"Cpp",98,"Y",302) # evolution(CppPath,"Cpp",98,"Y",302)
...@@ -106,3 +154,4 @@ if __name__=="__main__": ...@@ -106,3 +154,4 @@ if __name__=="__main__":
# plt.subplot(2,2,3) # plt.subplot(2,2,3)
# plt.imshow(VolOnion[3,:,:,]) # plt.imshow(VolOnion[3,:,:,])
# plt.show() # plt.show()
upsample_compare("Data/upsample/matlab_upsample/M_upsampleAfter_","Data/upsample/CppOut_",98,"A",1,OccMediumMask)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment