Commit 600223a6 authored by sarthou's avatar sarthou
Browse files

Comparaison of files right after peel init, and trying to feed C++ with Matlab...

Comparaison of files right after peel init, and trying to feed C++ with Matlab data, not working for now
parent 85998662
......@@ -35,7 +35,11 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa
for(int iteration = 0; iteration < nbIterations && residual > residualThreshold; iteration++){
iProfiler->BeforeInpaintingIteration(curLevel, iteration);
if(curLevel == downsamplingLevels-1 && iteration == 0)
OnionPeelInitialisation(&downsampledDataSource, iProfiler);
{
//OnionPeelInitialisation(&downsampledDataSource, iProfiler);
LoadingInitialisation(&downsampledDataSource,iProfiler);
}
else{
iSearcher->Search(&detailedOcclusionDataSource, false);
residual = iReconstructor->Reconstruct(&detailedOcclusionDataSource, false);
......@@ -110,5 +114,27 @@ void InpaintingConverger::OnionPeelInitialisation(InpaintingDataSource * const i
// }
iProfiler->AfterInitialisation();
}
void InpaintingConverger::LoadingInitialisation(InpaintingDataSource * const iDataSource,InpaintingProfiler * const iProfiler){
iProfiler->BeforeInitialisation();
InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO();
openCVIO.LoadRGBMatrixFromVideo("Data/onion_debug/peel_compare/umbrella_after_peel.avi",\
iDataSource->GetRed(), iDataSource->GetGreen(), iDataSource->GetBlue());
openCVIO.LoadOcclusionMatrixFromImage("Data/onion_debug/Occ/OccF0.png",iDataSource->GetOcc());
for(int nbFrame=0;nbFrame<iDataSource->GetDim()->GetSizeZ();nbFrame++)
{
openCVIO.LoadMatrixFromCSV("Data/onion_debug/peel_compare/end_peel_disp/M_EndPeel_DispX_"\
+std::to_string(nbFrame)+".csv",iDataSource->GetDispX(),1);
openCVIO.LoadMatrixFromCSV("Data/onion_debug/peel_compare/end_peel_disp/M_EndPeel_DispY_"\
+std::to_string(nbFrame)+".csv",iDataSource->GetDispY(),1);
openCVIO.LoadMatrixFromCSV("Data/onion_debug/peel_compare/end_peel_disp/M_EndPeel_DispZ_"\
+std::to_string(nbFrame)+".csv",iDataSource->GetDispZ(),1);
}
iProfiler->AfterInitialisation();
}
......@@ -54,6 +54,7 @@ public:
private:
void OnionPeelInitialisation(InpaintingDataSource * const iDataSource, InpaintingProfiler * const iProfiler);
void LoadingInitialisation(InpaintingDataSource * const iDataSource, InpaintingProfiler * const iProfiler);
};
......
......@@ -56,7 +56,7 @@ int main(){
// Output the new images.
for(int i = 0; i < baseIPS.GetDim()->GetSizeZ(); ++i)
openCVIO.GeneralIOForRGB(baseIPS.GetRed(), baseIPS.GetGreen(), baseIPS.GetBlue(), i,
InpaintingIO::IH_DBG_SAVE, "Data/onion_debug/CppOut_WithoutSmallInit_F" + std::to_string(i));
InpaintingIO::IH_DBG_SAVE, "Data/onion_debug/CppOut_WithMatlabInput_F" + std::to_string(i));
profiler.AfterInpainting();
......
......@@ -11,7 +11,7 @@ function[] = write_image_volume(imgVol,fileName)
for ii=1:size(imgVol,3)
frameNumber = number_leading_zeros(ii,3);
imwrite(uint8(squeeze(imgVol(:,:,ii,:))),strcat(fileName,'_frame_',frameNumber,'.png'));
imwrite(uint8(squeeze(imgVol(:,:,ii,:))),strcat(fileName,'_frame_',int2str(ii-1),'.png'));
end
......
......@@ -184,6 +184,7 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
occVolIter = occVol;
debug_iter =0;
%fill in, in an onion peel fashion
while(sum(occVolIter(:)) > 0)
......@@ -220,24 +221,35 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
occVolPatchMatch,...
occVolDilate);
% cd matlab_debug
%determine the pixels to reconstruct at this layer
occVolBorder = abs(occVolIter - occVolErode);
%if the occVol == 2, then we cannot use the colour
%info, but we do not inpaint it either
occVolBorder(occVolErode == 1) = 2;
% cd matlab_debug/peel
%
% [~,w,l,maxFrame] = size(shiftVol);
%
% occVolIterCopy = occVolIter*125;
% occVolDilateCopy = occVolDilate*125;
% occVolErodeCopy = occVolErode*125;
% occVolPatchMatchCopy = occVolPatchMatch*125;
% occVolBorderCopy = occVolBorder*125;
%
% write_image_volume(occVolIterCopy,strcat('Iter_',int2str(debug_iter)));
% write_image_volume(occVolDilateCopy,strcat('Dilate_',int2str(debug_iter)));
% write_image_volume(occVolErodeCopy,strcat('Erode_',int2str(debug_iter)));
% write_image_volume(occVolPatchMatchCopy,strcat('PM_',int2str(debug_iter)));
% write_image_volume(occVolBorderCopy,strcat('Border_',int2str(debug_iter)));
%
% for nbframe=1:maxFrame
% csvwrite(strcat('M_Init_DispX_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
% csvwrite(strcat('M_Init_DispY_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat('M_Init_DispZ_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_Init_DispX_',int2str(debug_iter)),strcat(int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_Init_DispY_',int2str(debug_iter)),strcat(int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat(strcat('M_Init_DispZ_',int2str(debug_iter)),strcat(int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% end
%
% cd ..
%determine the pixels to reconstruct at this layer
occVolBorder = abs(occVolIter - occVolErode);
%if the occVol == 2, then we cannot use the colour
%info, but we do not inpaint it either
occVolBorder(occVolErode == 1) = 2;
% cd ../..
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%carry out the reconstruction
......@@ -270,7 +282,23 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
%now go to the next onion peel layer
occVolIter = occVolErode;
debug_iter = debug_iter +1;
end
% end of initialisation branch
%write_image_volume(imgVol,'matlab_debug/peel/M_EndPeel_F');
cd matlab_debug/peel/end_peel_disp/
[~,w,l,maxFrame] = size(shiftVol);
for nbframe=1:maxFrame
csvwrite(strcat('M_EndPeel_DispX_',int2str(nbframe-1),'.csv'),reshape(shiftVol(1,:,:,nbframe),[w,l]));
csvwrite(strcat('M_EndPeel_DispY_',int2str(nbframe-1),'.csv'),reshape(shiftVol(2,:,:,nbframe),[w,l]));
csvwrite(strcat('M_EndPeel_DispZ_',int2str(nbframe-1),'.csv'),reshape(shiftVol(3,:,:,nbframe),[w,l]));
end
cd ../../..
end
pp=pp+1;
%we have finished the initialisation : make sure that both
......
......@@ -152,6 +152,7 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
% end
%
% cd ..
% Carry out the reconstruction
if (exist('featurePyramid','var'))
[imgVol,gradX,gradY,normGradX,normGradY] = ...
......@@ -183,6 +184,7 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
occVolIter = occVol;
debug_iter =0;
%fill in, in an onion peel fashion
while(sum(occVolIter(:)) > 0)
......@@ -218,19 +220,6 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
firstGuess,...
occVolPatchMatch,...
occVolDilate);
%
% cd matlab_debug
%
% [~,w,l,maxFrame] = size(shiftVol);
%
% for nbframe=1:maxFrame
% csvwrite(strcat('M_Init_DispX_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
% csvwrite(strcat('M_Init_DispY_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
% csvwrite(strcat('M_Init_DispZ_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
% end
%
% cd ..
%determine the pixels to reconstruct at this layer
occVolBorder = abs(occVolIter - occVolErode);
......@@ -238,6 +227,20 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
%info, but we do not inpaint it either
occVolBorder(occVolErode == 1) = 2;
cd matlab_debug
[~,w,l,maxFrame] = size(shiftVol);
write_image_volume(O
for nbframe=1:maxFrame
csvwrite(strcat('M_Init_DispX_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(1,:,:,nbframe),[w,l]));
csvwrite(strcat('M_Init_DispY_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(2,:,:,nbframe),[w,l]));
csvwrite(strcat('M_Init_DispZ_',strcat(int2str(nbframe),'.csv')),reshape(shiftVol(3,:,:,nbframe),[w,l]));
end
cd ..
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%carry out the reconstruction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -269,6 +272,7 @@ function[imgOut, shiftVolOut] = inpaint_video(varargin)
%now go to the next onion peel layer
occVolIter = occVolErode;
debug_iter = debug_iter +1;
end
end
pp=pp+1;
......
......@@ -16,6 +16,9 @@ Rand1Path = "Data/random_compare/OneRandImgF"
Rand2Path = "Data/random_compare/ThreeRandImgF"
Cpp10 = "Data/onion_debug/CppOutF"
Cpp30 = "Data/onion_debug/CppOut30F"
PeelMatlab = "Data/onion_debug/peel_compare/M_EndPeel_F_frame_"
PeelCpp = "Data/onion_debug/peel_compare/Cpp_EndPeel_F"
OccSmallPath = "Data/onion_debug/Occ/OccF0.png"
# print(OccMask)
threshold_nbPixDiff = 0.1
......@@ -146,7 +149,7 @@ def MSSIM(VolX,VolY,C1,C2,WinNb):
return 0
def visual_compare(Vol1,Vol2,OutputPath):
VolOutput = np.zeros((98,68,264,3))
VolOutput = np.zeros(np.shape(Vol1))
for i in range(98):
VolOutput[i,:,:,0] = np.absolute(Vol1[i,:,:,0] - Vol2[i,:,:,0])
......@@ -158,10 +161,14 @@ def visual_compare(Vol1,Vol2,OutputPath):
return VolOutput
if __name__ == '__main__':
OccMask = io.imread(OccPath)
OccSmallMask = io.imread(OccSmallPath,as_grey=True)
OccSmallMask[OccSmallMask<0.1]=0
OccSmallMask[OccSmallMask>=0.1]=255
VolMatlab = np.zeros((98,68,264,3))
VolCpp = np.zeros((98,68,264,3))
VolOri = np.zeros((98,68,264,3))
......@@ -169,6 +176,8 @@ if __name__ == '__main__':
VolRand2 = np.zeros((98,68,264,3))
VolCpp10 = np.zeros((98,68,264,3))
VolCpp30 = np.zeros((98,68,264,3))
VolPeelM = np.zeros((98,17,66,3))
VolPeelC = np.zeros((98,17,66,3))
# Chargement des images dans un volume
for i in range(98):
if(i<9):
......@@ -179,21 +188,24 @@ if __name__ == '__main__':
img_cpp = io.imread(CppPath+str(i)+".png")
img_matlab = io.imread(MatlabPath+str(i)+".png")
img_ori = io.imread(OriFilePath+str(i)+".png")
img_rand1 = io.imread(Rand1Path+str(i)+".png")
img_rand2 = io.imread(Rand2Path+str(i)+".png")
img_cpp10 = io.imread(Cpp10+str(i)+".png")
img_cpp30 = io.imread(Cpp30+str(i)+".png")
# img_rand1 = io.imread(Rand1Path+str(i)+".png")
# img_rand2 = io.imread(Rand2Path+str(i)+".png")
# img_cpp10 = io.imread(Cpp10+str(i)+".png")
# img_cpp30 = io.imread(Cpp30+str(i)+".png")
img_peelM = io.imread(PeelMatlab+str(i)+".png")
img_peelC = io.imread(PeelCpp+str(i)+".png")
# print(img_cpp.shape)
VolMatlab[i,:,:,:]=img_matlab
VolCpp[i,:,:,:]=img_cpp
VolOri[i:,:,:,:]=img_ori
VolRand1[i,:,:,:]=img_rand1
VolRand2[i,:,:,:]=img_rand2
VolCpp10[i,:,:,:]=img_cpp10
VolCpp30[i,:,:,:]=img_cpp30
# VolRand1[i,:,:,:]=img_rand1
# VolRand2[i,:,:,:]=img_rand2
# VolCpp10[i,:,:,:]=img_cpp10
# VolCpp30[i,:,:,:]=img_cpp30
VolPeelC[i,:,:,:]=img_peelC
VolPeelM[i,:,:,:]=img_peelM
# # Code for video
# cap = cv2.VideoCapture(OriFilePath)
......@@ -226,19 +238,20 @@ if __name__ == '__main__':
# plt.imshow(imZ)
# plt.show()
## Affichage résultat de la comparaison des pixels dans la zone du masque
# # Affichage résultat de la comparaison des pixels dans la zone du masque
# pixCountRGB = np.zeros((3,98))
# for i in range(98):
# pixCountRGB[:,i]=PixCompare(VolRand1[i,:,:,:],VolRand2[i,:,:,:],OccMask,0.1)
# pixCountRGB[:,i]=PixCompare(VolPeelM[i,:,:,:],VolPeelC[i,:,:,:],OccSmallMask,0.1)
#
# plt.plot(pixCountRGB[0,:],'r', label='Red pixel ratio')
# plt.plot(pixCountRGB[1,:],'g',label='Green pixel ratio')
# plt.plot(pixCountRGB[2,:],'b',label='Blue pixel ratio')
# plt.plot((pixCountRGB[0,:]+pixCountRGB[1,:]+pixCountRGB[2,:])/3,'black',label='Mean pixel ratio')
# 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 le code C++ avec rand() appelée une fois ou 3 fois")
# plt.title("Evolution de la différence de pixel entre le code C++ et Matlab à la fin de l'initialisation en pelure d'onion")
# plt.show()
# ## Evolution du PSNR dans la vidéo
......@@ -255,20 +268,20 @@ if __name__ == '__main__':
# plt.legend()
# plt.show()
## PSNR entre Cpp avec 10,20 et 30 iterations (reference avec Matlab)
PSNR_vol = np.zeros((3,98))
for i in range(98):
[_,_,_,PSNR_vol[0,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp10[i,:,:,:],OccMask)
[_,_,_,PSNR_vol[1,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp[i,:,:,:],OccMask)
[_,_,_,PSNR_vol[2,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp30[i,:,:,:],OccMask)
plt.plot(PSNR_vol[0,:],'r', label='Cpp with 10 search iterations')
plt.plot(PSNR_vol[1,:],'g',label='Cpp with 20 search iterations')
plt.plot(PSNR_vol[2,:],'b',label='Cpp with 30 search iterations')
plt.ylabel("PSNR on the mask during time")
plt.xlabel("number of frame (time)")
plt.legend()
plt.title("Comparaison of mean PSNR over RGB during time for differents search iterations in the C++ algorithm")
plt.show()
# ## PSNR entre Cpp avec 10,20 et 30 iterations (reference avec Matlab)
# PSNR_vol = np.zeros((3,98))
# for i in range(98):
# [_,_,_,PSNR_vol[0,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp10[i,:,:,:],OccMask)
# [_,_,_,PSNR_vol[1,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp[i,:,:,:],OccMask)
# [_,_,_,PSNR_vol[2,i]] = PSNR(VolMatlab[i,:,:,:],VolCpp30[i,:,:,:],OccMask)
# plt.plot(PSNR_vol[0,:],'r', label='Cpp with 10 search iterations')
# plt.plot(PSNR_vol[1,:],'g',label='Cpp with 20 search iterations')
# plt.plot(PSNR_vol[2,:],'b',label='Cpp with 30 search iterations')
# plt.ylabel("PSNR on the mask during time")
# plt.xlabel("number of frame (time)")
# plt.legend()
# plt.title("Comparaison of mean PSNR over RGB during time for differents search iterations in the C++ algorithm")
# plt.show()
# ## Evolution du SSIM dans la vidéo en comparaison CPP 10/20/30 search iter
# SSIM_cpp10 = np.zeros((3,98))
......@@ -312,3 +325,4 @@ if __name__ == '__main__':
# plt.show()
# VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp")
visual_compare(VolPeelM,VolPeelC,"Data/onion_debug/peel_compare/CompF")
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