├── .gitattributes ├── .gitignore ├── README.md ├── TianSGU.sln ├── TianSGU ├── TJBU.cpp ├── TianSGU.vcxproj ├── TianSGU.vcxproj.filters ├── function.h ├── head.h └── main.cpp ├── Tianbad2.png ├── Tianout2.png ├── disp1.png └── view1.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | *.publishproj 132 | 133 | # NuGet Packages 134 | *.nupkg 135 | # The packages folder can be ignored because of Package Restore 136 | **/packages/* 137 | # except build/, which is used as an MSBuild target. 138 | !**/packages/build/ 139 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 140 | #!**/packages/repositories.config 141 | 142 | # Windows Azure Build Output 143 | csx/ 144 | *.build.csdef 145 | 146 | # Windows Store app package directory 147 | AppPackages/ 148 | 149 | # Others 150 | sql/ 151 | *.Cache 152 | ClientBin/ 153 | [Ss]tyle[Cc]op.* 154 | ~$* 155 | *~ 156 | *.dbmdl 157 | *.dbproj.schemaview 158 | *.pfx 159 | *.publishsettings 160 | node_modules/ 161 | 162 | # RIA/Silverlight projects 163 | Generated_Code/ 164 | 165 | # Backup & report files from converting an old project file 166 | # to a newer Visual Studio version. Backup files are not needed, 167 | # because we have git ;-) 168 | _UpgradeReport_Files/ 169 | Backup*/ 170 | UpgradeLog*.XML 171 | UpgradeLog*.htm 172 | 173 | # SQL Server files 174 | *.mdf 175 | *.ldf 176 | 177 | # Business Intelligence projects 178 | *.rdl.data 179 | *.bim.layout 180 | *.bim_*.settings 181 | 182 | # Microsoft Fakes 183 | FakesAssemblies/ 184 | 185 | # ========================= 186 | # Operating System Files 187 | # ========================= 188 | 189 | # OSX 190 | # ========================= 191 | 192 | .DS_Store 193 | .AppleDouble 194 | .LSOverride 195 | 196 | # Icon must end with two \r 197 | Icon 198 | 199 | # Thumbnails 200 | ._* 201 | 202 | # Files that might appear on external disk 203 | .Spotlight-V100 204 | .Trashes 205 | 206 | # Directories potentially created on remote AFP share 207 | .AppleDB 208 | .AppleDesktop 209 | Network Trash Folder 210 | Temporary Items 211 | .apdisk 212 | 213 | # Windows 214 | # ========================= 215 | 216 | # Windows image file caches 217 | Thumbs.db 218 | ehthumbs.db 219 | 220 | # Folder config file 221 | Desktop.ini 222 | 223 | # Recycle Bin used on file shares 224 | $RECYCLE.BIN/ 225 | 226 | # Windows Installer files 227 | *.cab 228 | *.msi 229 | *.msm 230 | *.msp 231 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DepthImageUpsampling 2 | 3 | One new method for depth image upsampling. 4 | 5 | ## 1 Require 6 | 7 | - Visual Studio 2012 or higher 8 | - OpenCV 2.4.8 or higher 9 | 10 | ## 2 Usage 11 | 12 | 1. Open `TianSGU.sln` 13 | 2. Set your own OpenCV for Visual Studio IDE 14 | 3. Build the program and generate `TianSGU.exe` 15 | 4. Invoke `TianSGU.exe` 16 | 17 | ```cmd 18 | D:\Github\DepthImageUpsampling\Debug\> TianSGU.exe view1.png disp1.png 2 Tianout2.png Tianbad2.png 19 | D:\Github\DepthImageUpsampling\Debug\> 20 | Imagescale #:2 21 | The time of Tian method is : 15.974 22 | BPR : 0.515566% 23 | MSE : 10.0913 24 | RMSE : 3.17669 25 | PSNR : 38.0913 26 | ``` 27 | 28 | ## 3 Result 29 | 30 | input images: 31 | 32 | ![color](./view1.png) 33 | 34 | ![depth](./disp1.png) 35 | 36 | output images: 37 | 38 | ![updepth](./Tianout2.png) 39 | 40 | ![badimage](./Tianbad2.png) 41 | -------------------------------------------------------------------------------- /TianSGU.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TianSGU", "TianSGU\TianSGU.vcxproj", "{6DC85E40-48AB-4FD0-91A2-E3485FA676C3}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {6DC85E40-48AB-4FD0-91A2-E3485FA676C3}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {6DC85E40-48AB-4FD0-91A2-E3485FA676C3}.Debug|Win32.Build.0 = Debug|Win32 14 | {6DC85E40-48AB-4FD0-91A2-E3485FA676C3}.Release|Win32.ActiveCfg = Release|Win32 15 | {6DC85E40-48AB-4FD0-91A2-E3485FA676C3}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /TianSGU/TJBU.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | #include "function.h" 3 | 4 | extern Mat F; // the refine mask of downsampling ground truth image 5 | extern Mat VarCF; 6 | extern Mat VarDF; 7 | extern Mat VarF; 8 | extern int height,width; 9 | extern int s_height,s_width; 10 | extern int ScaleRate; 11 | 12 | inline double dist(double x1, double y1, int x2, int y2) 13 | { 14 | return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)); 15 | } 16 | inline double StandardGauss( double x, double sigma) 17 | { 18 | double exponent = exp(-1.0 * (x * x ) / (2 * sigma * sigma)); 19 | return exponent; 20 | } 21 | 22 | Mat& TJBU(Mat& source, Mat &refIm, Mat &dest, int WinWidth) 23 | { 24 | double scale = 1.0*s_width/width; 25 | const double mu = 0.0; 26 | const double sigmad = 0.50; 27 | const double sigmar = 25.5; 28 | const int num_neighbors = WinWidth/2; 29 | 30 | for (int y = 0; y < height; y++) 31 | { 32 | for (int x = 0; x < width; x++) 33 | { 34 | // coordinate maybe fractional 35 | double o_y = y * scale; 36 | double o_x = x * scale; 37 | int r_y = 0, r_ys = 0, r_x = 0, r_xs = 0; 38 | 39 | double varCFval = VarCF.at(o_y,o_x); // Low resolution color image's variance VarCF 40 | double varDFval = VarDF.at(o_y,o_x); // Low resolution depth image's variance VarDF 41 | double afa = VarF.at(o_y,o_x); // Correlation Value CA 42 | 43 | uchar FPix = F.at(o_y, o_x); // Mask F 44 | uchar srcPix = source.at(o_y,o_x); // source Low resolution depth image Dl 45 | uchar refPix = refIm.at(y, x); // refIm High resolution color imag I 46 | 47 | //Joint bilateral upsampling 48 | uchar nsrcPix = 0, nrefPix = 0; 49 | double dis = 0.0, dgauss = 0.0, sgauss = 0.0, rgauss = 0.0, totalgauss = 0.0; 50 | double normalizing_factor = 0.0, total_val = 0.0; 51 | 52 | //for each neighbour for the source 53 | for (int j = -num_neighbors; j <= num_neighbors; j++) 54 | { 55 | //find y coordinates in source 56 | r_y = o_y + j; 57 | r_y = (r_y > 0 ? (r_y < s_height ? r_y :s_height - 1) : 0) ; 58 | r_ys = r_y / scale; 59 | 60 | for (int i = -num_neighbors; i <= num_neighbors; i++) 61 | { 62 | //find x coordinates in source 63 | r_x = o_x + i; 64 | r_x = (r_x > 0 ? (r_x < s_width ? r_x : s_width- 1) : 0); 65 | r_xs = r_x / scale; 66 | 67 | nsrcPix = source.at(r_y, r_x); // Low resolution depth image Dl 68 | nrefPix = refIm.at(r_ys, r_xs); // High resolution color image I 69 | 70 | if (nsrcPix != 0) 71 | { 72 | if (FPix == 255) 73 | { 74 | dis = dist(o_x, o_y, r_x, r_y); 75 | sgauss = StandardGauss(dis, sigmad); // spatial filter 76 | rgauss = StandardGauss(abs(refPix - nrefPix), varCFval); // color filter 77 | dgauss = StandardGauss(abs(srcPix - nsrcPix), varDFval); // depth filter 78 | totalgauss = sgauss * (afa*rgauss + (1 - afa)*dgauss); 79 | total_val += nsrcPix * totalgauss; 80 | normalizing_factor += totalgauss; 81 | } 82 | else 83 | {//Kopf's JBU 84 | dis = dist(o_x, o_y, r_x, r_y); 85 | sgauss = StandardGauss(dis, sigmad); // spatial filter 86 | rgauss = StandardGauss(abs(refPix - nrefPix), sigmar);// range filter 87 | totalgauss = sgauss * rgauss; 88 | total_val += nsrcPix * totalgauss; 89 | normalizing_factor += totalgauss; 90 | } 91 | } 92 | 93 | }//end for i 94 | }//end for j 95 | 96 | dest.at(y, x) = ceil(total_val / normalizing_factor); 97 | 98 | #pragma region Plan_1 99 | if (varDFval >= 0.01) 100 | { 101 | //===============refine depth value============ 102 | const int w = 2; 103 | uchar centPix = dest.at(y, x); 104 | uchar wpix[25] = {0}; 105 | int wdiffpix[25] = {0}; 106 | int indexpix = 0; 107 | 108 | for (int j = -w; j <= w; j++) 109 | { 110 | int r_y = o_y + j; 111 | r_y = (r_y > 0 ? (r_y < s_height ? r_y :s_height - 1) : 0) ; 112 | 113 | for (int i = -w; i <= w; i++) 114 | { 115 | int r_x = o_x + i; 116 | r_x = (r_x > 0 ? (r_x < s_width ? r_x : s_width- 1) : 0); 117 | uchar srcPix = source.at(r_y, r_x); 118 | 119 | if (srcPix != 0) 120 | { 121 | wpix[indexpix] = srcPix; 122 | wdiffpix[indexpix] = abs(srcPix - centPix); 123 | indexpix++; 124 | } 125 | } 126 | } 127 | 128 | int pixid = 0; 129 | int minpix = wdiffpix[0]; 130 | for (int i=0; i wdiffpix[i] ) 133 | { 134 | minpix = wdiffpix[i]; 135 | pixid = i; 136 | } 137 | } 138 | dest.at(y, x) = wpix[pixid]; 139 | } 140 | //=============high resolution color image's edge============= 141 | #pragma endregion 142 | 143 | }//end for x 144 | }//end for y 145 | 146 | return dest; 147 | } -------------------------------------------------------------------------------- /TianSGU/TianSGU.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {6DC85E40-48AB-4FD0-91A2-E3485FA676C3} 15 | Win32Proj 16 | TianSGU 17 | 18 | 19 | 20 | Application 21 | true 22 | v140 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v140 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 55 | true 56 | 57 | 58 | Console 59 | true 60 | %(AdditionalDependencies) 61 | 62 | 63 | 64 | 65 | Level3 66 | 67 | 68 | MaxSpeed 69 | true 70 | true 71 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 72 | true 73 | 74 | 75 | Console 76 | true 77 | true 78 | true 79 | %(AdditionalDependencies) 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /TianSGU/TianSGU.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /TianSGU/function.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUNCTION_H_ 2 | #define _FUNCTION_H_ 3 | 4 | #include "head.h" 5 | 6 | // core function 7 | Mat& TJBU(Mat& source, Mat &refIm, Mat &dest, int WinWidth); 8 | 9 | // Mask F 10 | Mat& ExtractMaskF (Mat &inImage,Mat &TmpF); 11 | 12 | // Variance 13 | Mat& ExtractVariaceF(Mat &inImage,Mat &VarF); 14 | 15 | #endif -------------------------------------------------------------------------------- /TianSGU/head.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEAD_H_ 2 | #define _HEAD_H_ 3 | 4 | #include // input and output method 5 | #include // compatiable for different platform 6 | #include // processing time 7 | #include // the size of different data type 8 | #include // math operator 9 | #include // sort function 10 | 11 | #include "opencv2/core/core.hpp" 12 | #include "opencv2/highgui/highgui.hpp" 13 | #include "opencv2/imgproc/imgproc.hpp" 14 | 15 | using namespace std; 16 | using namespace cv; 17 | 18 | 19 | #endif -------------------------------------------------------------------------------- /TianSGU/main.cpp: -------------------------------------------------------------------------------- 1 | #include "head.h" 2 | #include "function.h" 3 | 4 | Mat F, VarCF, VarDF, VarF; 5 | int height = 0, width = 0; 6 | int s_height = 0, s_width = 0; 7 | int ScaleRate = 0, WinSize = 0; 8 | 9 | void help() { 10 | cout << "Usage: \n" 11 | << "*.exe path_of_color_image path_of_disp_image scale_rate path_of_upsampling_image path_of_badpixel_image\n" 12 | << "Example: \n" 13 | << "./TianSGU.exe view1.png disp1.png 2 Tianout2.png Tianbad2.png" << endl; 14 | } 15 | 16 | int main(int argc,char * argv[]) 17 | { 18 | if (argc != 6) 19 | { 20 | help(); 21 | return -1; 22 | } 23 | 24 | Mat RefImage = imread(argv[1], 0); 25 | Mat SrcImage = imread(argv[2], 0); 26 | ScaleRate = atoi(argv[3]); 27 | 28 | height = SrcImage.rows; 29 | width = SrcImage.cols; 30 | s_height = height/ScaleRate; 31 | s_width = width /ScaleRate; 32 | 33 | Mat TmpCDown = Mat::zeros(s_height, s_width,RefImage.type()); 34 | Mat TmpDDown = Mat::zeros(s_height, s_width,SrcImage.type()); 35 | resize(RefImage,TmpCDown,TmpCDown.size(),0,0,INTER_NEAREST ); 36 | resize(SrcImage,TmpDDown,TmpDDown.size(),0,0,INTER_NEAREST ); 37 | 38 | //------------------------- TJBU---------------------- 39 | double start_time,end_time; 40 | start_time = clock(); 41 | 42 | Mat DepthEdge = Mat::zeros(TmpDDown.size(),TmpDDown.type()); 43 | F = DepthEdge.clone(); 44 | 45 | VarCF = Mat::zeros(s_height, s_width, CV_32FC1); 46 | VarDF = Mat::zeros(s_height, s_width, CV_32FC1); 47 | VarF = Mat::zeros(s_height, s_width, CV_32FC1); 48 | ExtractVariaceF(TmpCDown,VarCF); 49 | ExtractVariaceF(TmpDDown,VarDF); 50 | 51 | #pragma region CA 52 | 53 | const int w = 3; 54 | const int bordval = 2; 55 | const int val = 1; 56 | int top,bottom,left,right; 57 | top = bottom = left = right = val; 58 | 59 | Mat TmpCDownBorder = Mat::zeros(s_height+bordval, s_width+bordval, TmpCDown.type()); 60 | Mat TmpDDownBorder = Mat::zeros(s_height+bordval, s_width+bordval, TmpDDown.type()); 61 | copyMakeBorder(TmpCDown, TmpCDownBorder, top, bottom, left, right, BORDER_REPLICATE); 62 | copyMakeBorder(TmpDDown, TmpDDownBorder, top, bottom, left, right, BORDER_REPLICATE); 63 | 64 | for (int j = 1; j < s_height+1; j++) 65 | { 66 | for (int i = 1; i < s_width+1; i++) 67 | { 68 | double a1 = 0.0, a2 = 0.0; 69 | double sumPix1 = 0.0,sumPix2 = 0.0, sumPix = 0.0; 70 | double meanPix1 = 0.0, meanPix2 = 0.0, meanPix= 0.0; 71 | for (int m = -w/2; m<=w/2; m++) 72 | { 73 | int y = j + m; 74 | y = (y > 0 ? (y < s_height + 2 ? y : s_height + 1 ) : 0); 75 | 76 | for (int n = -w/2; n<=w/2; n++) 77 | { 78 | int x = i + n; 79 | x = (x > 0 ? (x < s_width + 2 ? x : s_width + 1 ) : 0); 80 | a1 = TmpCDownBorder.at(y,x); 81 | a2 = TmpDDownBorder.at(y,x); 82 | sumPix1 += a1; 83 | sumPix2 += a2; 84 | sumPix += (a1 * a2); 85 | }//end for n 86 | }//end for m 87 | 88 | meanPix1 = sumPix1/(w*w);//EX 89 | meanPix2 = sumPix2/(w*w);//EY 90 | meanPix = sumPix/(w*w); //EXY 91 | double CA = meanPix - meanPix1 * meanPix2;//EXY - EXEY 92 | double dx = VarCF.at(j - 1,i - 1); 93 | double dy = VarDF.at(j - 1,i - 1); 94 | CA /= sqrt(dx * dy); //CA = ((EXY - EXEY)/sqrt(DXDY)) 95 | VarF.at(j-1, i-1) = CA; 96 | }//end for i 97 | }//end for j 98 | #pragma endregion 99 | 100 | ExtractMaskF(TmpDDown, DepthEdge); 101 | 102 | threshold(DepthEdge, F, 0, 255, THRESH_OTSU); 103 | 104 | WinSize = ScaleRate * ScaleRate + 1; //window's size for different scals downsampling 105 | Mat SrcUp = Mat::zeros(SrcImage.size(), SrcImage.type()); 106 | 107 | TJBU(TmpDDown, RefImage, SrcUp, WinSize); 108 | 109 | end_time = (clock() - start_time) / CLOCKS_PER_SEC; 110 | cout << "Imagescale #:" << ScaleRate << endl; 111 | cout << "The time of Tian method is : " << end_time << endl; 112 | 113 | imwrite(argv[4],SrcUp); 114 | 115 | #pragma region Criterion BPR MSE RMSE PSNR 116 | 117 | Mat BadImage = Mat::zeros(SrcUp.size(),SrcUp.type()); 118 | double BRP = 0.0,Mse = 0.0 , Rmse = 0.0, Psnr = 0.0; 119 | double blackcnt = 0.0,cnt = 0.0; 120 | int dv = 0; 121 | long sum = 0; 122 | 123 | for (int j = 0; j < height; j++) 124 | { 125 | for (int i = 0; i < width; i++) 126 | { 127 | if (SrcImage.at(j,i) != 0) 128 | { 129 | //MSE RMSE PSNR 130 | dv = abs(SrcImage.at(j,i) - SrcUp.at(j,i)); 131 | dv = pow(dv,2); 132 | sum += dv; 133 | //BPR 134 | if (dv > 1) 135 | { 136 | BadImage.at(j,i) = 0; 137 | cnt++; 138 | } 139 | else 140 | { 141 | BadImage.at(j,i) = 255; 142 | } 143 | } 144 | else 145 | { 146 | BadImage.at(j,i) = 255; 147 | blackcnt++; 148 | } 149 | } 150 | } 151 | 152 | BRP = 1.0 * cnt / (height * width - blackcnt)*100; 153 | Mse = 1.0 * sum/(height*width - blackcnt); 154 | Rmse = sqrt(Mse); 155 | Psnr = 10 * log10(255*255/(Mse)); 156 | 157 | cout << "BPR : " << BRP << "%" << endl; 158 | cout << "MSE : " << Mse << endl; 159 | cout << "RMSE : " << Rmse << endl; 160 | cout << "PSNR : " << Psnr << endl; 161 | cout << endl << endl; 162 | imwrite(argv[5],BadImage); 163 | #pragma endregion 164 | 165 | return EXIT_SUCCESS; 166 | } 167 | 168 | Mat& ExtractMaskF(Mat& inImage,Mat &TmpF) 169 | { 170 | int height = inImage.rows; 171 | int width = inImage.cols; 172 | 173 | Mat grad_x, grad_y; 174 | Mat abs_grad_x, abs_grad_y; 175 | int scale0 = 1; 176 | int delta0 = 0; 177 | int ddepth = CV_16S; 178 | 179 | // Gradient X grad_x 180 | Scharr( inImage, grad_x, ddepth, 1, 0, scale0, delta0, BORDER_DEFAULT ); 181 | convertScaleAbs( grad_x, abs_grad_x ); 182 | 183 | // Gradient Y grad_y 184 | Scharr( inImage, grad_y, ddepth, 0, 1, scale0, delta0, BORDER_DEFAULT ); 185 | convertScaleAbs( grad_y, abs_grad_y ); 186 | 187 | addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, TmpF); 188 | 189 | return TmpF; 190 | } 191 | 192 | Mat& ExtractVariaceF(Mat &inImage,Mat &VarF) 193 | { 194 | //---Lee Mask 3*3 Varance image--- 195 | const int w = 3; 196 | const int bordval = 2; 197 | const int val = 1; 198 | 199 | Mat TmpDownBorder = Mat::zeros(s_height+bordval, s_width+bordval, inImage.type()); 200 | 201 | int top,bottom,left,right; 202 | top = bottom = left = right = val; 203 | 204 | copyMakeBorder(inImage, TmpDownBorder, top, bottom, left, right, BORDER_REPLICATE); 205 | 206 | for (int j = 1; j < s_height+1; j++) 207 | { 208 | for (int i = 1; i < s_width+1; i++) 209 | { 210 | double sumPix = 0.0,sumPix2 = 0.0; 211 | double meanPix = 0.0, meanPix2 = 0.0, variancePix = 0.0; 212 | for (int m = -w/2; m<=w/2; m++) 213 | { 214 | int y = j + m; 215 | y = (y > 0 ? (y < s_height + 2 ? y : s_height + 1 ) : 0); // y coordinate 216 | 217 | for (int n = -w/2; n<=w/2; n++) 218 | { 219 | int x = i + n; 220 | x = (x > 0 ? (x < s_width + 2 ? x : s_width + 1 ) : 0); // x coordinate 221 | uchar a = TmpDownBorder.at(y,x); 222 | sumPix += a; 223 | sumPix2 += (a*a); 224 | }//end for n 225 | }//end for m 226 | 227 | meanPix = sumPix/(w*w); 228 | meanPix2 = sumPix2/(w*w); 229 | variancePix = meanPix2 - meanPix*meanPix; 230 | VarF.at(j-1, i-1) = variancePix; 231 | }//end for i 232 | }//end for j 233 | return VarF; 234 | } -------------------------------------------------------------------------------- /Tianbad2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Digital2Slave/DepthImageUpsampling/697ae0949cdb53d24f1a3c7534ded89ee2e220ea/Tianbad2.png -------------------------------------------------------------------------------- /Tianout2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Digital2Slave/DepthImageUpsampling/697ae0949cdb53d24f1a3c7534ded89ee2e220ea/Tianout2.png -------------------------------------------------------------------------------- /disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Digital2Slave/DepthImageUpsampling/697ae0949cdb53d24f1a3c7534ded89ee2e220ea/disp1.png -------------------------------------------------------------------------------- /view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Digital2Slave/DepthImageUpsampling/697ae0949cdb53d24f1a3c7534ded89ee2e220ea/view1.png --------------------------------------------------------------------------------