Commit 85998662 authored by sarthou's avatar sarthou
Browse files

Removing compilation files, testing for search iterations, multiples debugs...

 Removing compilation files, testing for search iterations, multiples debugs and modifying (without consequences) the borders of occ mask during search and reconstruct
parent ac1f4876
......@@ -45,7 +45,7 @@ void InpaintingConverger::Inpaint(InpaintingDataSource * const iDataSource, Inpa
// std::cout << "DimDisp = (" << detailedOcclusionDataSource.GetDispX()->GetDimension()->GetSizeX()\
// <<":"<< detailedOcclusionDataSource.GetDispX()->GetDimension()->GetSizeY()<< ":" << \
// detailedOcclusionDataSource.GetDispX()->GetDimension()->GetSizeZ()<<")"<< std::endl;
std::cout << "No" << (downsamplingLevels-curLevel)*100+iteration <<std::endl;
//std::cout << "No" << (downsamplingLevels-curLevel)*100+iteration <<std::endl;
//detailedOcclusionDataSource.GetDispX()->GetFrame(nbFrame)->Mprint();
/*
......@@ -73,8 +73,9 @@ void InpaintingConverger::OnionPeelInitialisation(InpaintingDataSource * const i
IDSDDetailedOcclusionPeeling(iDataSource, iEvaluator->GetPatchDim().GetSizeX(),\
iEvaluator->GetPatchDim().GetSizeY(), iEvaluator->GetPatchDim().GetSizeZ());
InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO();
// Slowly peel back the layers!
//std::cout << "Appel to Onion Peel" <<std::endl;
int peelNo = 0;
do{
// peelingDataSource.GetOcc()->GetFrame(0)->Mprint();
......@@ -88,19 +89,25 @@ void InpaintingConverger::OnionPeelInitialisation(InpaintingDataSource * const i
// peelingDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/debug/debug_init/InitBeforeDispZ_"+std::to_string(nbFrame)+"_" + std::to_string(peelNo));
// }
iSearcher->Search(&peelingDataSource, true);
iReconstructor->Reconstruct(&peelingDataSource, true);
//
// for(int nbFrame=0;nbFrame<peelingDataSource.GetDispX()->GetDimension()->GetSizeZ();nbFrame++ )
// {
// peelingDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/debug/debug_init/InitAfterDispX_"+std::to_string(nbFrame)+"_" + std::to_string(peelNo));
// peelingDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/debug/debug_init/InitAfterDispY_"+std::to_string(nbFrame)+"_" + std::to_string(peelNo));
// peelingDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/debug/debug_init/InitAfterDispZ_"+std::to_string(nbFrame)+"_" + std::to_string(peelNo));
// peelingDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/onion_debug/InitAfterDispX_"+std::to_string(peelNo)+"_F" + std::to_string(nbFrame));
// peelingDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/onion_debug/InitAfterDispY_"+std::to_string(peelNo)+"_F" + std::to_string(nbFrame));
// peelingDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/onion_debug/InitAfterDispZ_"+std::to_string(peelNo)+"_F" + std::to_string(nbFrame));
// }
//
// for(int i = 0; i < peelingDataSource.GetDim()->GetSizeZ(); ++i)
// openCVIO.GeneralIOForRGB(peelingDataSource.GetRed(), peelingDataSource.GetGreen(), peelingDataSource.GetBlue(), i,
// InpaintingIO::IH_DBG_SAVE, "Data/onion_debug/Onion_"+std::to_string(peelNo)+"_F" + std::to_string(i));
iProfiler->AfterInitialisationPeel(peelNo++);
}while(peelingDataSource.Peel());
// for(int i = 0; i < peelingDataSource.GetDim()->GetSizeZ(); ++i){
// peelingDataSource.GetOcc()->GetFrame(i)->MprintToCSV("Data/onion_debug/OccF"+std::to_string(i));
// }
iProfiler->AfterInitialisation();
......
......@@ -29,7 +29,7 @@ float IRBestPatch::Reconstruct(InpaintingDataSource * const iDataProvider, bool
PaddedMatrixIt matIt = PaddedMatrixIt(iDataProvider->GetDim());
PaddedMatrixKernelIt kernelIt = PaddedMatrixKernelIt(iDataProvider->GetDim(), &patchDim);
do{
if(occMatData[matIt.GetPosition()] < DOCC_BORDER || occMatData[matIt.GetPosition()] > DOCC_BORDER_ALT)
if(occMatData[matIt.GetPosition()] <= DOCC_NEAROCC || occMatData[matIt.GetPosition()] >= DOCC_CORE)
continue;
bool correctInfo = false;
......@@ -41,7 +41,7 @@ float IRBestPatch::Reconstruct(InpaintingDataSource * const iDataProvider, bool
kernelIt.Start(matIt.GetPosition());
do{
if(occMatData[kernelIt.GetPosition()] != DOCC_BUFFER &&
(!hasInvalidPixels || occMatData[kernelIt.GetPosition()] < DOCC_BORDER))
(!hasInvalidPixels || occMatData[kernelIt.GetPosition()] <= DOCC_NEAROCC))
{
if(dispAData[kernelIt.GetPosition()] < minWeight){
minWeight = dispAData[kernelIt.GetPosition()];
......
......@@ -17,8 +17,14 @@ void ISRandom::Search(InpaintingDataSource * const iDataProvider, bool const has
srand(0);
std::chrono::steady_clock::time_point sectionClock;
// iDataProvider->GetOcc()->GetFrame(0)->Mprint();
sectionClock = std::chrono::steady_clock::now();
//iDataProvider->GetDispX()->GetFrame(29)->MprintToCSV("Data/onion_debug/DispX_"+std::to_string(searchCall)+"_before");
InitialiseDisplacementField(iDataProvider, hasInvalidPixels);
//iDataProvider->GetDispX()->GetFrame(29)->MprintToCSV("Data/onion_debug/DispX_"+std::to_string(searchCall)+"_after");
std::cout << " Initialisation time : " << ((std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - sectionClock).count()) * pow(10,-9)) << std::endl;
double propTime = 0, randTime = 0;
......@@ -39,6 +45,8 @@ void ISRandom::Search(InpaintingDataSource * const iDataProvider, bool const has
std::cout << " Propagation count : " << propCount << std::endl;
std::cout << " Rand search time : " << randTime << std::endl;
std::cout << " Rand search count : " << randCount << std::endl;
searchCall+=1;
}
bool ISRandom::CheckForBetterDisplacement(InpaintingDataSource * const iDataProvider, PaddedMatrixDim *dim, bool const hasInvalidPixels,
......@@ -244,9 +252,13 @@ void ISRandom::InitialiseDisplacementField(InpaintingDataSource * const iDataPro
int* dispYData = iDataProvider->GetDispY()->GetData();
int* dispZData = iDataProvider->GetDispZ()->GetData();
float* dispAData = iDataProvider->GetDispA()->GetData();
float* detailOccData = iDataProvider->GetOcc()->GetData();
PaddedMatrixIt volIt = PaddedMatrixIt(levelDim);
do{
// if(detailOccData[volIt.GetPosition()] < DOCC_BORDER)
// continue;
int xDispT = dispXData[volIt.GetPosition()];
int yDispT = dispYData[volIt.GetPosition()];
int zDispT = dispZData[volIt.GetPosition()];
......
......@@ -21,6 +21,7 @@ private:
// TODO Hardcoded so we know what to remove later...
int patchHalfSize = 2; // Works for X, Y and Z since they're all the same...
int searchCall = 0;
InpaintingEvaluator * const iEvaluator;
......
......@@ -21,9 +21,10 @@ int main(){
// Select and parameterize the algorithms
InpaintingEvaluator evaluationAlgo = InpaintingEvaluator(50, 5, 5, 5);
ISRandom searchAlgo = ISRandom(10, &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);
IRWeightedAverage reconstructAlgo = IRWeightedAverage(0.75f, 5, 5, 5);
//IRBestPatch reconstructAlgo = IRBestPatch(5, 5, 5);
// To profile
ISProfiler searchProfiler = ISProfiler(&profiler, &searchAlgo);
......@@ -55,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/random_compare/ThreeRandImgF" + std::to_string(i));
InpaintingIO::IH_DBG_SAVE, "Data/onion_debug/CppOut_WithoutSmallInit_F" + std::to_string(i));
profiler.AfterInpainting();
......
......@@ -14,7 +14,8 @@ OccPath = "Data/resources/beach_umbrella_occlusion.png"
OriFilePath = "Data/resources/beach_umbrella_f"
Rand1Path = "Data/random_compare/OneRandImgF"
Rand2Path = "Data/random_compare/ThreeRandImgF"
Cpp10 = "Data/onion_debug/CppOutF"
Cpp30 = "Data/onion_debug/CppOut30F"
# print(OccMask)
threshold_nbPixDiff = 0.1
......@@ -166,6 +167,8 @@ if __name__ == '__main__':
VolOri = np.zeros((98,68,264,3))
VolRand1 = np.zeros((98,68,264,3))
VolRand2 = np.zeros((98,68,264,3))
VolCpp10 = np.zeros((98,68,264,3))
VolCpp30 = np.zeros((98,68,264,3))
# Chargement des images dans un volume
for i in range(98):
if(i<9):
......@@ -174,10 +177,12 @@ if __name__ == '__main__':
temp_str= str(i+1)
img_cpp = io.imread(CppPath+str(i)+".png")
img_matlab = io.imread(MatlabPath+temp_str+".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")
# print(img_cpp.shape)
......@@ -186,6 +191,9 @@ if __name__ == '__main__':
VolOri[i:,:,:,:]=img_ori
VolRand1[i,:,:,:]=img_rand1
VolRand2[i,:,:,:]=img_rand2
VolCpp10[i,:,:,:]=img_cpp10
VolCpp30[i,:,:,:]=img_cpp30
# # Code for video
# cap = cv2.VideoCapture(OriFilePath)
......@@ -247,6 +255,44 @@ 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()
# ## Evolution du SSIM dans la vidéo en comparaison CPP 10/20/30 search iter
# SSIM_cpp10 = np.zeros((3,98))
# SSIM_cpp =np.zeros((3,98))
# SSIM_cpp30 = np.zeros((3,98))
# for i in range(98):
# SSIM_cpp10[:,i]=SSIM(VolCpp10[i,:,:,:],VolOri[i,:,:,:],0.01,0.03)
# SSIM_cpp[:,i]=SSIM(VolCpp[i,:,:,:],VolOri[i,:,:,:],0.01,0.03)
# SSIM_cpp30[:,i]=SSIM(VolCpp30[i,:,:,:],VolOri[i,:,:,:],0.01,0.03)
#
#
# plt.plot((SSIM_cpp10[0,:]+SSIM_cpp10[1,:]+SSIM_cpp10[2,:])/3,'r', label='SSIM Cpp 10 iter')
# plt.plot((SSIM_cpp[0,:]+SSIM_cpp[1,:]+SSIM_cpp[2,:])/3,'g', label='SSIM Cpp 20 iter')
# plt.plot((SSIM_cpp30[0,:]+SSIM_cpp30[1,:]+SSIM_cpp30[2,:])/3,'b', label='SSIM Cpp 30 iter')
#
#
#
# plt.ylabel("SSIM of picture during time")
# plt.xlabel("number of frame (time)")
# plt.legend()
# plt.title("Comparaison of mean MSSIM over RGB during time for differents search iterations in the C++ algorithm")
# plt.show()
# ## Evolution du SSIM dans la vidéo en comparaison MATLAB/CPP
# SSIM_matlab = np.zeros((3,98))
# SSIM_cpp =np.zeros((3,98))
......@@ -265,4 +311,4 @@ if __name__ == '__main__':
# plt.legend()
# plt.show()
VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp")
# VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp")
......@@ -92,17 +92,17 @@ if __name__=="__main__":
# compare(frame,XYZ,MatlabPath,CppPath,iterLevel)
# evolution(CppPath,"Cpp",98,"Y",302)
# Quick Load
VolOnion = np.zeros((3,17,67))
VolOnion[0,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(0)+".csv",delimiter=";")
VolOnion[1,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(1)+".csv",delimiter=";")
VolOnion[2,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(2)+".csv",delimiter=";")
plt.figure()
plt.subplot(2,2,1)
plt.imshow(VolOnion[0,:,:,])
plt.subplot(2,2,2)
plt.imshow(VolOnion[1,:,:,])
plt.subplot(2,2,3)
plt.imshow(VolOnion[2,:,:,])
plt.show()
# ###Quick Load of occlusion
# VolOnion = np.zeros((4,17,67))
# VolOnion[0,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(0)+".csv",delimiter=";")
# VolOnion[1,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(1)+".csv",delimiter=";")
# VolOnion[2,:,:]=np.genfromtxt("Data/onion_debug/OccF0_"+str(2)+".csv",delimiter=";")
# VolOnion[3,:,:]=np.genfromtxt("Data/onion_debug/OccF0_last.csv",delimiter=";")
# plt.figure()
# plt.subplot(2,2,1)
# plt.imshow(VolOnion[1,:,:,])
# plt.subplot(2,2,2)
# plt.imshow(VolOnion[2,:,:,])
# plt.subplot(2,2,3)
# plt.imshow(VolOnion[3,:,:,])
# plt.show()
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from PIL import Image
"""Ce fichier sert à afficher les matrices de déplacement en parallèle des
images reconstruites et du masque pendant l'initialisation en pelure d'onion du code C++"""
frame = 32
direction = "X"
nbPeel = 3
#Loading
Disp = []
Im = []
Occ = []
path = "Data/onion_debug/Disp/"
#### Convert occ mask to png
#
# for i in range(98):
# temp = np.genfromtxt("Data/onion_debug/OccF"+str(i)+".csv",delimiter=';')
# end = np.shape(temp)[1]
# plt.imsave("Data/onion_debug/OccF"+str(i)+".png",temp[:,0:end-1])
##### Reconstruction en init
# for i in range(nbPeel):
# #Loading Disp
# onion_path = path + "round"+str(i)+"/"
# temp = np.genfromtxt(onion_path+"InitAfterDisp"+direction+"_"+str(i)+"_F"+str(frame)+".csv",delimiter=';')
# end = np.shape(temp)[1]
# Disp.append(temp[:,0:end-1])
#
# # Loading reconstructed image
# img = io.imread(onion_path+"Onion_"+str(i)+"_F"+str(frame)+".png")
# Im.append(img)
#
# # Loading occlusion mask
# temp2 = np.genfromtxt("Data/onion_debug/OccF0_"+str(i)+".csv",delimiter=';')
# end = np.shape(temp2)[1]
# Occ.append(temp2[:,0:end-1])
#
#
# for i in range(nbPeel):
# plt.subplot(nbPeel,3,3*i+1)
# plt.imshow(Occ[i],vmin=0, vmax=3)
# plt.ylabel("Peel n°"+str(i))
# plt.xlabel("Occlusion mask")
# plt.subplot(nbPeel,3,3*i+2)
# plt.imshow(Disp[i])
# plt.xlabel("Displacement over "+direction)
# plt.subplot(nbPeel,3,3*i+3)
# plt.imshow(Im[i])
# plt.xlabel("Frame n° "+str(frame))
#
# plt.suptitle("Evolution of reconstruction during onion peel initialisation",horizontalalignment='center',fontsize='20')
# plt.show()
#### Convert Disp matrix from search call to png
# for i in range(39):
# temp = np.genfromtxt("Data/onion_debug/DispX_"+str(i)+"_before.csv",delimiter=';')
# end = np.shape(temp)[1]
# plt.imsave("Data/onion_debug/DX_"+str(i)+"_before.png",temp[:,0:end-1])
#
# temp = np.genfromtxt("Data/onion_debug/DispX_"+str(i)+"_after.csv",delimiter=';')
# end = np.shape(temp)[1]
# plt.imsave("Data/onion_debug/DX_"+str(i)+"_after.png",temp[:,0:end-1])
# temp = np.genfromtxt("Data/onion_debug/Occ/OccF0_2.csv",delimiter=';')
# end = np.shape(temp)[1]
# temp = temp[:,0:end-1]
# temp = io.imread("Data/resources/beach_umbrella_occlusion.png")
temp = io.imread("Data/onion_debug/Occ/OccF0.png")
# print(np.shape(temp))
p_temp = np.zeros((17,66,3))
p_temp[:,:,0],p_temp[:,:,1],p_temp[:,:,2] = temp[:,:,0], temp[:,:,1], temp[:,:,2]
p1 = Image.fromarray(np.uint8(p_temp))
# for i in range(98):
# p2 = Image.open("Data/onion_debug/Onion_2_F"+str(i)+".png")
# p3 = Image.blend(p1,p2,.8)
# p3.save("Data/onion_debug/mask_compare/FullMaskLastPeel"+str(i)+".png")
for i in range(98):
p1 = Image.open("Data/Out_matlab_random/beach_umbrellainpainted_frame_0"+str(i)+".png")
p2 = Image.open("Data/onion_debug/CppOutF"+str(i)+".png")
p3 = Image.blend(p1,p2,.8)
p3.save("Data/onion_debug/WTF_"+str(i)+".png")
Markdown is supported
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