main.cpp 9.31 KB
Newer Older
sarthou's avatar
sarthou committed
1
#include <iostream>
2
#include <typeinfo>
sarthou's avatar
sarthou committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "algorithm/inpainting/searchers/ISFull.h"
#include "algorithm/inpainting/searchers/ISProfiler.h"
#include "algorithm/inpainting/reconstructors/IRProfiler.h"
#include "algorithm/inpainting/reconstructors/IRBestPatch.h"

#include "algorithm/inpaintingTools/InpaintingOpenCVIO.h"
#include "algorithm/inpaintingTools/InpaintingProfiler.h"
#include "algorithm/inpainting/dataSources/IDSConcrete.h"
#include "algorithm/inpainting/InpaintingConverger.h"


int main(){
    InpaintingOpenCVIO openCVIO = InpaintingOpenCVIO();
    InpaintingProfiler profiler = InpaintingProfiler();

    const std::string videoFileName = "resources/beach_umbrella.avi";
    const std::string occFileName = "resources/beach_umbrella_occlusion.png";

21
22
23
24
    // const std::string videoFileName = "Data/resources/Oreo/Oreo.avi";
    // const std::string occFileName = "Data/resources/Oreo/OreoHD-Occlusion.png";


sarthou's avatar
sarthou committed
25
26
    profiler.BeforeInpainting();

27

sarthou's avatar
sarthou committed
28
29
    // Select and parameterize the algorithms
    InpaintingEvaluator evaluationAlgo = InpaintingEvaluator(50, 5, 5, 5);
30
    ISRandom searchAlgo = ISRandom(20, &evaluationAlgo); //initiated at 20, but 10 in Matlab code
sarthou's avatar
sarthou committed
31
32
    // ISFull searchAlgo = ISFull(&evaluationAlgo);
    IRWeightedAverage reconstructAlgo = IRWeightedAverage(0.75f, 5, 5, 5);
33
    //IRBestPatch reconstructAlgo = IRBestPatch(5, 5, 5);
sarthou's avatar
sarthou committed
34
35
36
37
38
39
40
41
42
43
44

    // To profile
    ISProfiler searchProfiler = ISProfiler(&profiler, &searchAlgo);
    IRProfiler reconstructProfiler = IRProfiler(&profiler, &reconstructAlgo);
    // Final algo
    InpaintingConverger inpainter = InpaintingConverger(3, 2, 20, 0.1f/255.0f, &searchProfiler, &reconstructProfiler, &evaluationAlgo);

    // Load the data source // TODO Move this to another class.
    int sizeX, sizeY, sizeZ;

    openCVIO.GetVideoDimensions(videoFileName, sizeX, sizeY, sizeZ);
45

sarthou's avatar
sarthou committed
46
47
48
49
50
51
52
53
54
    PaddedMatrixDim * const dim = new PaddedMatrixDim(sizeX, sizeY, sizeZ, 2, 2, 2);
    PaddedMatrix<float> * const redMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const greenMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const blueMatrix = new PaddedMatrix<float>(dim);
    PaddedMatrix<float> * const occMatrix = new PaddedMatrix<float>(dim);
    openCVIO.LoadRGBMatrixFromVideo(videoFileName, redMatrix, greenMatrix, blueMatrix);
    openCVIO.LoadOcclusionMatrixFromImage(occFileName, occMatrix);
    IDSConcrete baseIPS = IDSConcrete(dim, redMatrix, greenMatrix, blueMatrix, occMatrix);

sarthou's avatar
sarthou committed
55
    /*
56
    // Work for testing upsampe algorithm
57
58
59
60
61
62
63
64
65
    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++)
    {
66
      openCVIO.LoadMatrixFromCSV("Data/upsample_ant/UA_matlab/M_UA_Ante_DispX_F"\
67
68
69
      +std::to_string(nbFrame)+".csv",frame_x,1);
      downsampledDataSource.GetDispX()->SetFrame(frame_x,nbFrame);

70
      openCVIO.LoadMatrixFromCSV("Data/upsample_ant/UA_matlab/M_UA_Ante_DispY_F"\
71
72
73
      +std::to_string(nbFrame)+".csv",frame_y,1);
      downsampledDataSource.GetDispY()->SetFrame(frame_y,nbFrame);

74
      openCVIO.LoadMatrixFromCSV("Data/upsample_ant/UA_matlab/M_UA_Ante_DispZ_F"\
75
76
77
      +std::to_string(nbFrame)+".csv",frame_z,1);
      downsampledDataSource.GetDispZ()->SetFrame(frame_z,nbFrame);

78
      openCVIO.LoadMatrixFromCSV("Data/upsample_ant/UA_matlab/M_UA_Ante_DispA_F"\
79
80
81
      +std::to_string(nbFrame)+".csv",frame_a,1);
      downsampledDataSource.GetDispA()->SetFrame(frame_a,nbFrame);
    }
82
    //downsampledDataSource.GetDispX()->GetFrame(70)->Mprint();
83

84
    downsampledDataSource.MatlabUpsampleShiftMatrix();
85
    // downsampledDataSource.UpsampleShiftMatrices();
86
87
    downsampledDataSource.SetCurLevel(1);

88
89
    //downsampledDataSource.GetDispX()->GetFrame(70)->Mprint();

90
91
    for(int nbFrame=0;nbFrame < downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
    {
92
93
94
95
      downsampledDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/Cpp_UA_DispX_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/Cpp_UA_DispY_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/Cpp_UA_DispZ_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/upsample_ant/Cpp_UA_DispA_F"+std::to_string(nbFrame));
96
    }
97
    std::cout << "End of upsample test"<< std::endl;
sarthou's avatar
sarthou committed
98
    */
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    /*
    int level = 2;
    IDSDDownsampling downsampledDataSource = IDSDDownsampling(&baseIPS, 3, 2);
    downsampledDataSource.SetCurLevel(level);

    openCVIO.LoadRGBMatrixFromVideo("Data/search_reconstruct/SR_matlab/M_SR_Ante_L3.avi",\
    downsampledDataSource.GetRed(), downsampledDataSource.GetGreen(), downsampledDataSource.GetBlue());

    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());
    PaddedMatrix<float> * const frame_gx = new PaddedMatrix<float>(downsampledDataSource.GetDim());
    PaddedMatrix<float> * const frame_gy = new PaddedMatrix<float>(downsampledDataSource.GetDim());

    for(int nbFrame=0;nbFrame<downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
    {
      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_DispX_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_x,1);
      downsampledDataSource.GetDispX()->SetFrame(frame_x,nbFrame);

      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_DispY_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_y,1);
      downsampledDataSource.GetDispY()->SetFrame(frame_y,nbFrame);

      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_DispZ_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_z,1);
      downsampledDataSource.GetDispZ()->SetFrame(frame_z,nbFrame);

      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_DispA_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_a,1);
      downsampledDataSource.GetDispA()->SetFrame(frame_a,nbFrame);

      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_GradX_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_gx,1);
      downsampledDataSource.GetGradX()->SetFrame(frame_gx,nbFrame);

      openCVIO.LoadMatrixFromCSV("Data/search_reconstruct/SR_matlab/M_SR_Ante_GradY_L"\
      +std::to_string(level+1)+"_F_"+std::to_string(nbFrame)+".csv",frame_gy,1);
      downsampledDataSource.GetGradY()->SetFrame(frame_gy,nbFrame);
    }

    searchAlgo.Search(&downsampledDataSource, false);
    reconstructAlgo.Reconstruct(&downsampledDataSource, false);

    for(int nbFrame=0;nbFrame < downsampledDataSource.GetDim()->GetSizeZ();nbFrame++)
    {
      openCVIO.GeneralIOForRGB(downsampledDataSource.GetRed(), downsampledDataSource.GetGreen(),\
       downsampledDataSource.GetBlue(),nbFrame,InpaintingIO::IH_DBG_SAVE,\
       "Data/search_reconstruct/CppOut_SR_L"+std::to_string(level+1)+"_F"+ std::to_string(nbFrame));

      downsampledDataSource.GetDispX()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_DispX_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispY()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_DispY_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispZ()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_DispZ_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));
      downsampledDataSource.GetDispA()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_DispA_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));
      downsampledDataSource.GetGradX()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_GradX_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));
      downsampledDataSource.GetGradY()->GetFrame(nbFrame)->MprintToCSV("Data/search_reconstruct/CppOut_SR_GradY_L"+std::to_string(level+1)+"_F"+std::to_string(nbFrame));

    }

    std::cout << "End of search/reconstruct test" << std::endl;
    */
sarthou's avatar
sarthou committed
162
163
164
165
166
167
168
169
170
171
172
    // Execute the work
    inpainter.Inpaint(&baseIPS, &profiler);

    // Get better quality, less blurry, final images
    IDSDDetailedOcclusion detOcc = IDSDDetailedOcclusion(&baseIPS, 5, 5, 5);
    IRBestPatch bestPatch = IRBestPatch(5, 5, 5);
    bestPatch.Reconstruct(&detOcc, false);

    // Output the new images.
    for(int i = 0; i < baseIPS.GetDim()->GetSizeZ(); ++i)
        openCVIO.GeneralIOForRGB(baseIPS.GetRed(), baseIPS.GetGreen(), baseIPS.GetBlue(), i,
sarthou's avatar
sarthou committed
173
                                 InpaintingIO::IH_DBG_SAVE, "Data/upsample_ant/final/CppOut_F" + std::to_string(i));
174

sarthou's avatar
sarthou committed
175
176
177
178

    profiler.AfterInpainting();
    return 0;
}