Commit b7b038ba authored by sarthou's avatar sarthou
Browse files

Implementing the new interpolation similar to matlab, working partially, but...

Implementing the new interpolation similar to matlab, working partially, but there is a size problem
parent b5ed9c1f
......@@ -85,6 +85,62 @@ void IDSDDownsampling::UpsampleShiftMatrices(){
}while(nextVolIt.Next(downsamplingRate, downsamplingRate) && sourceVolIt.Next());
}
void IDSDDownsampling::MatlabUpsampleShiftMatrix(){
/*This method is for interpolate the displacements fields, with an algorithm
more similar than what is done in the Matlab example, to compare efficiency */
PaddedMatrixDim * fromDim = idsLevels[curLevel]->GetDim();
int* fromXDispData = idsLevels[curLevel]->GetDispX()->GetData();
int* fromYDispData = idsLevels[curLevel]->GetDispY()->GetData();
int* fromZDispData = idsLevels[curLevel]->GetDispZ()->GetData();
float* fromADispData = idsLevels[curLevel]->GetDispA()->GetData();
PaddedMatrixDim * toDim = idsLevels[curLevel - 1]->GetDim();
int* toXDispData = idsLevels[curLevel - 1]->GetDispX()->GetData();
int* toYDispData = idsLevels[curLevel - 1]->GetDispY()->GetData();
int* toZDispData = idsLevels[curLevel - 1]->GetDispZ()->GetData();
float* toADispData = idsLevels[curLevel - 1]->GetDispA()->GetData();
PaddedMatrix<int> * GridX = new PaddedMatrix<int>(toDim);
PaddedMatrix<int> * GridY = new PaddedMatrix<int>(toDim);
PaddedMatrix<int> * GridZ = new PaddedMatrix<int>(toDim);
// Creating Meshgrid
for(int i = 0; i < toDim->GetSizeX(); i++){
for(int j = 0; j < toDim->GetSizeY(); j++){
for(int k = 0; k < toDim->GetSizeZ(); k++){
int temp_x = std::max(std::min((int)roundf(i/2),fromDim->GetSizeX()-1),0);
int temp_y = std::max(std::min((int)roundf(j/2),fromDim->GetSizeY()-1),0);
int temp_z = std::max(std::min(k,fromDim->GetSizeZ()-1),0);
GridX->Set(i,j,k,temp_x);
GridY->Set(i,j,k,temp_y);
GridZ->Set(i,j,k,temp_z);
}
}
}
// GridX->Mprint();
PaddedMatrixIt nextVolIt = PaddedMatrixIt(toDim);
do {
toXDispData[nextVolIt.GetPosition()] = downsamplingRate * \
fromXDispData[fromDim->DeterminePosition(GridX->GetData()[nextVolIt.GetPosition()],\
GridY->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()])];
// On garde les mêmes valeurs car il n'y a pas de downsampling sur Z
toZDispData[nextVolIt.GetPosition()] =\
fromZDispData[fromDim->DeterminePosition(GridX->GetData()[nextVolIt.GetPosition()],\
GridY->GetData()[nextVolIt.GetPosition()],GridZ->GetData()[nextVolIt.GetPosition()])];
toADispData[nextVolIt.GetPosition()] =\
fromADispData[fromDim->DeterminePosition(GridX->GetData()[nextVolIt.GetPosition()],\
GridY->GetData()[nextVolIt.GetPosition()],GridZ->GetData()[nextVolIt.GetPosition()])];
} while(nextVolIt.Next());
}
PaddedMatrixDim * const IDSDDownsampling::GetDim(){
return idsLevels[curLevel]->GetDim();
}
......@@ -181,6 +237,7 @@ void IDSDDownsampling::DownsampleCasellesDescriptors(int const targetLevel){
}while(sourceIt.Next(leap, leap) && targetIt.Next());
}
/*
PaddedMatrixDim gaussianKernelDim = PaddedMatrixDim(downsamplingRate + 1, downsamplingRate + 1, 1);
......@@ -224,4 +281,4 @@ void IDSDDownsampling::DownsampleCasellesDescriptors(int const targetLevel){
dwnSmpGrn[targetLevelIt.GetPosition()] = grnVal;
dwnSmpOcc[targetLevelIt.GetPosition()] = occVal;
}while(targetLevelIt.Next() && sourceLevelIt.Next(downsamplingRate, downsamplingRate));
*/
\ No newline at end of file
*/
......@@ -8,6 +8,8 @@
#include "../../../standardTools/ImageManipulator.h"
#include "../IDSDecorator.h"
#include "../IDSConcrete.h"
#include <cfloat>
#include <algorithm>
class IDSDDownsampling : public IDSDecorator {
private:
......@@ -24,6 +26,7 @@ public:
void SetCurLevel(int const curLevel);
void UpsampleShiftMatrices();
void MatlabUpsampleShiftMatrix();
PaddedMatrixDim * const GetDim() override;
PaddedMatrix<float> * const GetRed() override;
......@@ -40,6 +43,8 @@ public:
private:
void DownsampleColorsAndOcclusion(int const targetLevel);
void DownsampleCasellesDescriptors(int const targetLevel);
//void Meshgrid(PaddedMatrixDim * dim,PaddedMatrix<int> * X,PaddedMatrix<int> * Y,PaddedMatrix<int> * Z);
};
......
......@@ -77,22 +77,26 @@ int main(){
+std::to_string(nbFrame)+".csv",frame_a,1);
downsampledDataSource.GetDispA()->SetFrame(frame_a,nbFrame);
}
downsampledDataSource.GetDispX()->GetFrame(70)->Mprint();
downsampledDataSource.UpsampleShiftMatrices();
downsampledDataSource.MatlabUpsampleShiftMatrix();
downsampledDataSource.SetCurLevel(1);
downsampledDataSource.GetDispX()->GetFrame(70)->Mprint();
/*
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.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/test_methodCpp/CppOut_DispX_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispY_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/test_methodCpp/CppOut_DispY_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispZ_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/test_methodCpp/CppOut_DispZ_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/CppOut_DispA_L1_F"+std::to_string(nbFrame));
downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/upsample/test_methodCpp/CppOut_DispA_L1_F"+std::to_string(nbFrame));
}
*/
std::cout << "End of upsample test"<< std::endl;
// Execute the work
inpainter.Inpaint(&baseIPS, &profiler);
......
......@@ -92,7 +92,7 @@ def evolution(path,MorC,nbFrame,XYZ,idIter):
return 0
def upsample_compare(Mpath,Cpath,nbFrame,XYZ,level,OccMask):
def upsample_compare(Mpath,Cpath,nbFrame,XYZ,level,OccMask, outPath):
results=[]
for i in range(nbFrame):
......@@ -103,7 +103,7 @@ def upsample_compare(Mpath,Cpath,nbFrame,XYZ,level,OccMask):
diff = temp_matlab-temp_cpp[:,0:end-1]
# print(diff)
plt.imsave("Data/upsample/results/Diff_"+XYZ+"_F"+str(i)+".png",diff,cmap="seismic")
plt.imsave(outPath+XYZ+"_F"+str(i)+".png",diff,cmap="seismic")
diff[diff!=0]=1
diff_sum = 0
......@@ -154,4 +154,10 @@ if __name__=="__main__":
# plt.subplot(2,2,3)
# plt.imshow(VolOnion[3,:,:,])
# plt.show()
upsample_compare("Data/upsample/matlab_upsample/M_upsampleAfter_","Data/upsample/CppOut_",98,"A",1,OccMediumMask)
# upsample_compare("Data/upsample/matlab_upsample/M_upsampleAfter_",\
# "Data/upsample/test_methodCpp/CppOut_",98,"Z",1,OccMediumMask,"Data/upsample/results/DiffNewFunc_")
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')
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