Commit 3e8561a5 authored by sarthou's avatar sarthou
Browse files

Modifying time seed for C++, and starting to clean Python code, with new files

parent 8d3a590d
......@@ -5,6 +5,7 @@
#include <iostream>
#include <fstream>
#include <chrono>
#include <time.h>
#include "ISRandom.h"
ISRandom::ISRandom(int const searchIterations, InpaintingEvaluator * const iEvaluator)
......@@ -14,7 +15,8 @@ ISRandom::~ISRandom(){}
void ISRandom::Search(InpaintingDataSource * const iDataProvider, bool const hasInvalidPixels)
{
srand(0);
//srand(0);
srand(time(NULL));
std::chrono::steady_clock::time_point sectionClock;
// iDataProvider->GetOcc()->GetFrame(0)->Mprint();
......@@ -280,7 +282,7 @@ void ISRandom::InitialiseDisplacementField(InpaintingDataSource * const iDataPro
}
/*Problème noté:
- Valeur du statut renvoyé dans les cas occlus/pas occlus => Ok
- Valeur du statut renvoyé dans les cas occlus/pas occlus => Ok
- HalfPatchSize à 3 au lieu de 2 (ceil) => Corrigé
- Inverse bool in Search (bof)
*/
......@@ -52,7 +52,7 @@ int main(){
openCVIO.LoadOcclusionMatrixFromImage(occFileName, occMatrix);
IDSConcrete baseIPS = IDSConcrete(dim, redMatrix, greenMatrix, blueMatrix, occMatrix);
/*
int level = 0;
IDSDDownsampling downsampledDataSource = IDSDDownsampling(&baseIPS, 3, 2);
downsampledDataSource.SetCurLevel(level);
......@@ -121,7 +121,7 @@ int main(){
}
std::cout << "End of search/reconstruct test" << std::endl;
*/
// Execute the work
inpainter.Inpaint(&baseIPS, &profiler);
......@@ -134,7 +134,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/upsample_ant/final/CppOut_F" + std::to_string(i));
InpaintingIO::IH_DBG_SAVE, "Data/seed/C_seed/C_Seed_Time2_F" + std::to_string(i));
profiler.AfterInpainting();
......
......@@ -34,16 +34,13 @@ M_SR_Path = "Data/search_reconstruct/SR_matlab/M_SR_Post_Im_L3_frame_"
# print(OccMask)
threshold_nbPixDiff = 0.1
list_result = []
list_max = []
# test_cpp = io.imread(CppPath+str(0)+".png")
# test_matlab = io.imread(MatlabPath+"01"+".png")
# print(test_cpp.shape)
# print(test_matlab.shape)
#plt.imshow(test_cpp)
#plt.imshow(test_matlab)
#plt.show()
def rgb2gray(rgb):
"""Convert an rgb (int 0-255) image (loaded in a numpy array of size [n,m,3]) into
a greyscale image (with Matlab parameters to insure similarity)
@params:
rgb : numpy array of size [n,m,3]
@output numpy array of size [n,m] (grayscale image)
"""
r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2]
gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
......@@ -51,6 +48,16 @@ def rgb2gray(rgb):
return gray
def PixCompare(im1,im2,occMask,threshold):
""" Compare the percentage of pixels different by a threshold value between two images,
on the mask specified
@params:
im1,im2 : numpy array of size [n,m,3] (has to be of the same dimension)
occMask: numpy array of size [n,m] (binary, with int 0/255)
threshold: float, expressing the limit for which two pixels are considered different.
@output numpy array of size 3, with the percentage of difference per color canal (RGB)
"""
#Calculs des différences de canaux
n,m=im1.shape[0],im1.shape[1]
assert(im2.shape[0]==occMask.shape[0]==n and im2.shape[1]==occMask.shape[1]==m)
......@@ -77,6 +84,19 @@ def PixCompare(im1,im2,occMask,threshold):
return [Rcount/MaskCount,Gcount/MaskCount,Bcount/MaskCount]
def FullPixCompare(Vol1Path,Vol2Path,sizeVol,OccMaskPath,threshold):
""" Take two paths towards volumes of images in order to compare them image
by image with pixComp method and plot the resulting graph.
@params:
Vol1Path,Vol2Path : string containing path to volumes, ending with the format of namefiles
sizeVol: size of Volume (numbers of images,their size, number of color channel),
numpy array of size 4
occMaskPath: string containing path to the mask (greyscale image)
threshold: float, expressing the limit for which two pixels are considered different.
@output: numpy array of size [3,nbFrame]. Each colonn contains the three
values of RGB diff for the corresponding frames
"""
Vol1 = np.zeros((sizeVol[0],sizeVol[1],sizeVol[2],sizeVol[3]))
Vol2 = np.zeros(np.shape(Vol1))
VolOutput = np.zeros(np.shape(Vol1))
......@@ -95,11 +115,15 @@ def FullPixCompare(Vol1Path,Vol2Path,sizeVol,OccMaskPath,threshold):
return pixCount
def PSNR(im1,im2,occMask):
""" Compute the peak signal-to-noise ratio between two images, on the mask.
@params:
im1,im2 : numpy array of size [n,m,3] (has to be of the same dimension)
occMask: numpy array of size [n,m] (binary, with int 0/255)
@output: numpy array of size 4. Each colonn contains the three
values of RGB diff for the corresponding frames, the last one is the mean
"""
n,m=im1.shape[0],im1.shape[1]
assert(im2.shape[0]==occMask.shape[0]==n and im2.shape[1]==occMask.shape[1]==m)
......@@ -120,20 +144,109 @@ def PSNR(im1,im2,occMask):
return [R_PSNR,G_PSNR,B_PSNR,Mean_PSNR]
def SSIM(imX,imY,C1,C2):
meanX = np.mean(np.mean(imX,axis=1),axis=0)
meanY = np.mean(np.mean(imY,axis=1),axis=0)
def FullPSNR(Vol1Path,Vol2Path,sizeVol,OccMaskPath,title):
""" Take two paths towards volumes of images in order to compare them image
by image with PSNR and plot the resulting graph.
@params:
Vol1Path,Vol2Path : string containing path to volumes, ending with the format of namefiles
sizeVol: size of Volume (numbers of images,their size, number of color channel),
numpy array of size 4
occMaskPath: string containing path to the mask (greyscale image)
title: string containing title of graph plot.
@output: numpy array of size (4,98). Each line is RGB and mean PSNR over frames.
"""
Vol1 = np.zeros((sizeVol[0],sizeVol[1],sizeVol[2],sizeVol[3]))
Vol2 = np.zeros(np.shape(Vol1))
PSNR_vol = np.zeros((4,sizeVol[0]))
for i in range(sizeVol[0]):
Vol1[i,:,:,:] = io.imread(Vol1Path+str(i)+".png")
Vol2[i,:,:,:] = io.imread(Vol2Path+str(i)+".png")
OccMask = io.imread(OccMaskPath,as_grey=True)
OccMask[OccMask<0.1]=0
OccMask[OccMask>=0.1]=255
## Evolution du PSNR dans la vidéo
for i in range(sizeVol[0]):
PSNR_vol[:,i]=PSNR(Vol1[i,:,:,:],Vol2[i,:,:,:],OccMask)
plt.plot(PSNR_vol[0,:],'r', label='Red pixel PSNR')
plt.plot(PSNR_vol[1,:],'g',label='Green pixel PSNR')
plt.plot(PSNR_vol[2,:],'b',label='Blue pixel PSNR')
plt.plot(PSNR_vol[3,:],'black',label='Mean pixel PSNR')
plt.ylabel("PSNR on the mask during time")
plt.xlabel("number of frame (time)")
plt.legend()
plt.title(title)
plt.show()
return PSNR_vol
def SSIM(im1,im2,C1,C2):
""" Compute the structural similarity (similarity metric of comparison) between two RGB images.
@params:
im1,im2 : numpy array of size [n,m,3] (has to be of the same dimension)
C1,C2: float, parameters for SSIM computation
@output: numpy array of size 4. Each colonn contains the three
values of RGB diff for the corresponding frames, the last one is the mean
"""
mean1 = np.mean(np.mean(im1,axis=1),axis=0) #Size 3 (RGB mean over X and Y axis)
mean2 = np.mean(np.mean(im2,axis=1),axis=0)
std1 = np.std(np.std(im1,axis=1),axis=0)
std2 = np.std(np.std(im2,axis=1),axis=0)
std1_2 = [np.sum((im1[:,:,0]-mean1[0])*(im2[:,:,0]-mean2[0]))/(np.size(im1[:,:,0]-1)),\
np.sum((im1[:,:,1]-mean1[1])*(im2[:,:,1]-mean2[1]))/(np.size(im1[:,:,0]-1)),\
np.sum((im1[:,:,2]-mean1[2])*(im2[:,:,2]-mean2[2]))/(np.size(im1[:,:,0]-1))]
stdX = np.std(np.std(imX,axis=1),axis=0)
stdY = np.std(np.std(imY,axis=1),axis=0)
std1_2 = np.array(std1_2)
result = (2*mean1*mean2+C1)*(2*std1_2 + C2)/((mean1**2 + mean2**2 + C1)*(std1**2 + std2**2 + C2))
stdXY = [np.sum((imX[:,:,0]-meanX[0])*(imY[:,:,0]-meanY[0]))/(np.size(imX[:,:,0]-1)),\
np.sum((imX[:,:,1]-meanX[1])*(imY[:,:,1]-meanY[1]))/(np.size(imX[:,:,0]-1)),\
np.sum((imX[:,:,2]-meanX[2])*(imY[:,:,2]-meanY[2]))/(np.size(imX[:,:,0]-1))]
return [result[0],result[1],result[2],np.mean(result)]
stdXY = np.array(stdXY)
def FullSSIM(Vol1Path,Vol2Path,sizeVol,C1,C2,title):
""" Take two paths towards volumes of images in order to compare them image
by image with SSIM and plot the resulting graph.
@params:
Vol1Path,Vol2Path : string containing path to volumes, ending with the format of namefiles
sizeVol: size of Volume (numbers of images,their size, number of color channel),
C1,C2: float, parameters for SSIM computation
title: string containing title of graph plot.
@output: numpy array of size (4,98). Each line is RGB and mean PSNR over frames.
"""
Vol1 = np.zeros((sizeVol[0],sizeVol[1],sizeVol[2],sizeVol[3]))
Vol2 = np.zeros(np.shape(Vol1))
SSIM_vol = np.zeros((4,sizeVol[0]))
for i in range(sizeVol[0]):
Vol1[i,:,:,:] = io.imread(Vol1Path+str(i)+".png")
Vol2[i,:,:,:] = io.imread(Vol2Path+str(i)+".png")
## Evolution du PSNR dans la vidéo
for i in range(sizeVol[0]):
SSIM_vol[:,i]=SSIM(Vol1[i,:,:,:],Vol2[i,:,:,:],C1,C2)
plt.plot(SSIM_vol[0,:],'r', label='Red pixel SSIM')
plt.plot(SSIM_vol[1,:],'g',label='Green pixel SSIM')
plt.plot(SSIM_vol[2,:],'b',label='Blue pixel SSIM')
plt.plot(SSIM_vol[3,:],'black',label='Mean pixel SSIM')
plt.ylabel("SSIM during time")
plt.xlabel("number of frame (time)")
plt.legend()
plt.title(title)
plt.show()
return SSIM_vol
return (2*meanX*meanY+C1)*(2*stdXY + C2)/((meanX**2 + meanY**2 + C1)*(stdX**2 + stdY**2 + C2))
def MSSIM(VolX,VolY,C1,C2,WinNb):
assert(np.shape(VolX)==np.shape(VolY))
......@@ -187,6 +300,17 @@ def MSSIM(VolX,VolY,C1,C2,WinNb):
return 0
def visual_compare(Vol1Path,Vol2Path,sizeVol,OutputPath):
""" Take two paths towards volumes of images in order to compare them image
by image by substracting color channel and output results in gray.
@params:
Vol1Path,Vol2Path : string containing path to volumes, ending with the format of namefiles
sizeVol: size of Volume (numbers of images,their size, number of color channel),
numpy array of size 4
OutputPath: string containing path to output images (With the name format)
@output: numpy array of sizeVol containing gray frames of images differences.
The function also output the volume to the specified output path"""
Vol1 = np.zeros((sizeVol[0],sizeVol[1],sizeVol[2],sizeVol[3]))
Vol2 = np.zeros(np.shape(Vol1))
......@@ -218,78 +342,8 @@ if __name__ == '__main__':
OccMediumMask[OccMediumMask<0.1]=0
OccMediumMask[OccMediumMask>=0.1]=255
VolMatlab = np.zeros((98,68,264,3))
VolCpp = np.zeros((98,68,264,3))
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))
# VolPeelM = np.zeros((98,17,66,3))
# VolPeelC = np.zeros((98,17,66,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))
VolSRM = np.zeros((98,17,66,3))
VolSRC = np.zeros((98,17,66,3))
# Chargement des images dans un volume
for i in range(98):
if(i<9):
temp_str= "0"+str(i+1)
else:
temp_str= str(i+1)
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_peelM = io.imread(PeelMatlab+str(i)+".png")
# img_peelC = io.imread(PeelCpp+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)
VolMatlab[i,:,:,:]=img_matlab
VolCpp[i,:,:,:]=img_cpp
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
# VolRand2[i,:,:,:]=img_rand2
# VolCpp10[i,:,:,:]=img_cpp10
# VolCpp30[i,:,:,:]=img_cpp30
# VolPeelC[i,:,:,:]=img_peelC
# VolPeelM[i,:,:,:]=img_peelM
# VolCppLoad[i,:,:,:]=img_load
# # Code for video
# # Code for transforming video into .png frames
# cap = cv2.VideoCapture(OriFilePath)
# i=0
# while(True):
......@@ -303,56 +357,10 @@ if __name__ == '__main__':
# cap.release()
# cv2.destroyAllWindows()
# #Code de test pour savoir si les images ont bien chargé en uint8
# imX = VolMatlab[97,:,:,:].astype(np.uint8)
# imY = io.imread(MatlabPath+"98"+".png")
# imZ = VolOri[97,:,:,:].astype(np.uint8)
#MSSIM(VolMatlab,VolOri,0.01,0.03,(3,4))
# print(SSIM(imX,imY,0.01,0.03))
# print(test[11,23])
# print(strange[11,23])
# plt.subplot(1,2,1)
# plt.imshow(test)
# plt.subplot(1,2,2)
# plt.imshow(imZ)
# plt.show()
# # 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(VolCpp[i,:,:,:],VolCppLoad[i,:,:,:],OccMask,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 et sans initialisation en pelure d'onion")
# plt.show()
# # Affichage résultat de la comparaison des pixels dans la zone du masque
# pixCountCpp = np.zeros((3,98))
# pixCountLoad = np.zeros((3,98))
# for i in range(98):
# pixCountCpp[:,i]=PixCompare(VolCpp[i,:,:,:],VolMatlab[i,:,:,:],OccMask,0.1)
# pixCountLoad[:,i]=PixCompare(VolCppLoad[i,:,:,:],VolMatlab[i,:,:,:],OccMask,0.1)
#
# plt.plot((pixCountCpp[0,:]+pixCountCpp[1,:]+pixCountCpp[2,:])/3,'black',label='Cpp with peel init')
# plt.plot((pixCountLoad[0,:]+pixCountLoad[1,:]+pixCountLoad[2,:])/3,'blue',label='Cpp with matlab data loading')
# # 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 et sans initialisation en pelure d'onion")
# plt.show()
# # Affichage résultat de la comparaison des pixels dans la zone du masque
# # pour l'évolution de la divergence au fil de l'algorithme
# pixCountL1 = np.zeros((3,98))
# pixCountL2 = np.zeros((3,98))
# pixCountL3 = np.zeros((3,98))
......@@ -372,21 +380,6 @@ if __name__ == '__main__':
# 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
# PSNR_vol = np.zeros((4,98))
# for i in range(98):
# PSNR_vol[:,i]=PSNR(VolRand1[i,:,:,:],VolRand2[i,:,:,:],OccMask)
#
# plt.plot(PSNR_vol[0,:],'r', label='Red pixel PSNR')
# plt.plot(PSNR_vol[1,:],'g',label='Green pixel PSNR')
# plt.plot(PSNR_vol[2,:],'b',label='Blue pixel PSNR')
# plt.plot(PSNR_vol[3,:],'black',label='Mean pixel PSNR')
# plt.ylabel("PSNR on the mask during time")
# plt.xlabel("number of frame (time)")
# 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):
......@@ -456,10 +449,8 @@ if __name__ == '__main__':
# plt.legend()
# plt.show()
# VolOutComp = visual_compare(VolRand1,VolRand2,"Data/random_compare/RComp")
# 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++
"""Mesure de la divergence sur une frame"""
# # Evolution de la différence de pixel au fil des iterations entre Matlab et C++ sur une frame
# Cpath = "Data/divergence/CppOutDiv_F32_L"
# Mpath = "Data/divergence/full_div/M_FullDiv_F32_L"
# values = []
......@@ -485,7 +476,7 @@ if __name__ == '__main__':
# plt.show()
############## Working on Search/reconstruct
"""Working on Search/reconstruct"""
# # visual_compare(Cpp_SR_Path,M_SR_Path,[98,17,66,3],"Data/search_reconstruct/SR_result/SR_OutComp_L3_F")
#
# pixCountSR = FullPixCompare(Cpp_SR_Path,M_SR_Path,[98,17,66,3],OccSmallPath,0.1)
......@@ -531,19 +522,19 @@ if __name__ == '__main__':
# visual_compare("Data/reconstruct_ant/result_L1_I14/CppOut_F","Data/reconstruct_ant/L1_I14/M_RA_Post_Im_L1_I14_frame_",[98,68,264,3],"Data/reconstruct_ant/visu_comp_L1_I14_F")
# # Result: Weird noise
# plot pix compare between matlab and C++ reconstruction with L1_I14 injection
pixCountSR = FullPixCompare("Data/reconstruct_ant/result_L1_I14/CppOut_F",\
"Data/reconstruct_ant/L1_I14/M_RA_Post_Im_L1_I14_frame_",[98,68,264,3],OccPath,0.1)
plt.plot((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3,'black')
plt.axhline(np.mean((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3),color='red')
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 une itération Recherche/Reconstruction avec injection sur le niveau L1-I14 \n \
Avg:"+str(np.mean((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3))+\
" Ecart-type: "+str(np.std((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3)))
plt.show()
# Result: 3% de différence en moyenne, le problème ne doit pas venir de là.
# # plot pix compare between matlab and C++ reconstruction with L1_I14 injection
# pixCountSR = FullPixCompare("Data/reconstruct_ant/result_L1_I14/CppOut_F",\
# "Data/reconstruct_ant/L1_I14/M_RA_Post_Im_L1_I14_frame_",[98,68,264,3],OccPath,0.1)
#
# plt.plot((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3,'black')
# plt.axhline(np.mean((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3),color='red')
#
# 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 une itération Recherche/Reconstruction avec injection sur le niveau L1-I14 \n \
# Avg:"+str(np.mean((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3))+\
# " Ecart-type: "+str(np.std((pixCountSR[0,:]+pixCountSR[1,:]+pixCountSR[2,:])/3)))
# plt.show()
# # Result: 3% de différence en moyenne, le problème ne doit pas venir de la reconstruction.
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage import measure
import cv2
import compare
import scipy.signal
np.set_printoptions(threshold=np.nan)
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"
M_Ori_Path = "Data/seed/M_Ori/M_Seed_Ori_F"
C_Ori_Path = "Data/seed/C_Ori/C_Seed_Ori_F"
M_Seed_Path = "Data/seed/M_Seed/M_Seed_Perso_F"
C_Seed_Path = "Data/seed/C_seed/C_Seed_Time_F"
C_Seed2_Path = "Data/seed/C_seed/C_Seed_Time2_F"
# Loading masks if needed
OccMask = io.imread(OccPath)
OccSmallMask = io.imread(OccSmallPath,as_grey=True)
OccSmallMask[OccSmallMask<0.1]=0
OccSmallMask[OccSmallMask>=0.1]=255
OccMediumMask = io.imread(OccMediumPath,as_grey=True)
OccMediumMask[OccMediumMask<0.1]=0
OccMediumMask[OccMediumMask>=0.1]=255
########################################################
#####################"Pixel comparison##################
########################################################
"""
# For bases, PixCompare comparaison between Matlab (origin) and C++ (origin)
VolSeed_Ori = compare.FullPixCompare(M_Ori_Path,C_Ori_Path,\
[98,68,264,3],OccPath,0.1)
# Notes:
# Comparison between normal Matlab and personal seed
VolSeed_M_RNG = compare.FullPixCompare(M_Ori_Path,M_Seed_Path,\
[98,68,264,3],OccPath,0.1)
# Result:
# Comparison between normal Matlab and C++ unfixed seed (with time.h)
VolSeed_M_time = compare.FullPixCompare(M_Ori_Path,C_Seed_Path,\
[98,68,264,3],OccPath,0.1)
# Result:
# Comparison between C++ (origin) and C++ with time seed
VolSeed_C_time = compare.FullPixCompare(C_Ori_Path,C_Seed_Path,\
[98,68,264,3],OccPath,0.1)
# Result:
# Comparison between two iterations of C++ with time seed, just to see the impact
VolSeed_C_timecompare = compare.FullPixCompare(C_Seed_Path,C_Seed2_Path,\
[98,68,264,3],OccPath,0.1)
# Result: 9%, Acceptable
plt.plot((VolSeed_Ori[0,:]+VolSeed_Ori[1,:]+VolSeed_Ori[2,:])/3,'r',\
label='Matlab origin vs C++ origin')
plt.axhline(np.mean((VolSeed_Ori[0,:]+VolSeed_Ori[1,:]+VolSeed_Ori[2,:])/3),color='red')
plt.plot((VolSeed_M_RNG[0,:]+VolSeed_M_RNG[1,:]+VolSeed_M_RNG[2,:])/3,'g',\
label='Matlab origin vs Matlab manual RNG')
plt.axhline(np.mean((VolSeed_M_RNG[0,:]+VolSeed_M_RNG[1,:]+VolSeed_M_RNG[2,:])/3),color='g')
plt.plot((VolSeed_M_time[0,:]+VolSeed_M_time[1,:]+VolSeed_M_time[2,:])/3,'b',\
label='Matlab origin vs C++ time seed')
plt.axhline(np.mean((VolSeed_M_time[0,:]+VolSeed_M_time[1,:]+VolSeed_M_time[2,:])/3),color='b')
plt.plot((VolSeed_C_time[0,:]+VolSeed_C_time[1,:]+VolSeed_C_time[2,:])/3,'black', \
label='C++ origin vs C++ time seed')
plt.axhline(np.mean((VolSeed_C_time[0,:]+VolSeed_C_time[1,:]+VolSeed_C_time[2,:])/3),color='black')
plt.plot((VolSeed_C_timecompare[0,:]+VolSeed_C_timecompare[1,:]+VolSeed_C_timecompare[2,:])/3,'yellow', \
label='C++ time seed vs C++ time seed')
plt.axhline(np.mean((VolSeed_C_timecompare[0,:]+VolSeed_C_timecompare[1,:]+VolSeed_C_timecompare[2,:])/3),color='yellow')
plt.xlabel("number of frame (time)")
plt.ylabel("Percentage of pixels different in each image on the mask")
plt.legend()
plt.title("Plot of mean PixCompare for differents algorithms with different RNG")
plt.show()
# Conclusion: There is but little difference between C++ origin and Matlab
# with perso RNG, which means that Random distribution is indeed a big issue.
# We can see the impact of perso RNG on the green curve (around 10%) and the impact
# of time seed on C++ in the black curve (8%). So random isnt probably the
# only issue here, but it is a start
"""
########################################################
############################PSNR########################
########################################################
"""
# For bases, PSNR comparaison between Matlab (origin) and C++ (origin)
VolSeed_Ori = compare.FullPSNR(M_Ori_Path,C_Ori_Path,\
[98,68,264,3],OccPath,"PSNR entre Matlab et C++ (origine)")
# Notes:
# Comparaison between normal Matlab and personal seed
VolSeed_M_RNG = compare.FullPSNR(M_Ori_Path,M_Seed_Path,\
[98,68,264,3],OccPath, "PSNR entre Matlab avec et sans RNG personnelle")
# Result:
# Comparaison between normal Matlab and C++ unfixed seed (with time.h)
VolSeed_M_time = compare.FullPSNR(M_Ori_Path,C_Seed_Path,\
[98,68,264,3],OccPath,"PSNR entre Matlab (origine) et C++ avec une seed temporelle")
# Result:
# Comparaison between C++ (origin) and C++ with time seed
VolSeed_C_time = compare.FullPSNR(C_Ori_Path,C_Seed_Path,\
[98,68,264,3],OccPath,"PSNR entre C++ (origine) et C++ avec une seed temporelle")
# Result:
# Plot all 4 mean PSNR together for comparison.
plt.plot(VolSeed_Ori[3,:],'r', label='Matlab origin vs C++ origin')
plt.plot(VolSeed_M_RNG[3,:],'g',label='Matlab origin vs Matlab manual RNG')
plt.plot(VolSeed_M_time[3,:],'b',label='Matlab origin vs C++ time seed')
plt.plot(VolSeed_C_time[3,:],'black',label='C++ origin vs C++ time seed')
plt.ylabel("PSNR on the mask during time")
plt.xlabel("number of frame (time)")
plt.legend()
plt.title("Plot of mean PSNR for differents algorithms with different RNG")
plt.show()
# Result: PSNR not fit for comparison
"""
########################################################
#########################SSIM###########################
########################################################
"""
# For bases, SSIM comparaison between Matlab (origin) and C++ (origin)
VolSeed_Ori = compare.FullSSIM(M_Ori_Path,C_Ori_Path,\
[98,68,264,3],0.01,0.03,"SSIM entre Matlab et C++ (origine)")
# Notes:
# Comparaison between normal Matlab and personal seed
VolSeed_M_RNG = compare.FullSSIM(M_Ori_Path,M_Seed_Path,\
[98,68,264,3],0.01,0.03, "SSIM entre Matlab avec et sans RNG personnelle")
# Result: