3

I am trying to convert following MATLAB code into c++ code by Opencv library

Matlab Code:

scale_x = 0.99951;
scale_y = 0.99951;
RsrcImg= imref2d(size(im1));
T=[scale_x 0 0;0 scale_y 0;0 0 1];
tformEstimate = affine2d(T);
destImg =imwarp(im1,tformEstimate,'Interp','cubic','OutputView',RsrcImg);

C++ Code:

double scale_x = 0.99951;
double scale_y = 0.99951;
Mat tformEstimate=Mat::zeros(2,3,CV_64FC1);
tformEstimate.at<double>(0,0)=scale_x;
tformEstimate.at<double>(1,1)=scale_y;
warpAffine(im1,destImg,tformEstimate,im1.size(),INTER_CUBIC);

but I get completely different PSNR values! is there any way to make both codes work with the same result?

INPUT:

im1=[19656,20452,21048,21020,20564;
20740,21332,21964,20932,20220;
21688,21832,20236,21520,21948;
19780,20572,21056,20748,20088;
20560,21188,20608,22136,20736]

Matlab output:

[19656.4613056001,20452.8984647534,21048.6416903208,21019.5009522438,0;
20741.1425789163,21333.2772155087,21963.2997618553,20930.5373907996,0; 
21687.3205560205,21830.7204384573,20235.1172001277,21521.5360776160,0;
19779.1003189859,20572.0033036149,21056.4880106032,20747.6616956745,0;
0,0,0,0,0]

C++ output:

[19656.00000  20452.00000  21048.00000  21020.00000  20564.00000  
20740.00000  21332.00000  21964.00000  20932.00000  20220.00000  
21688.00000  21832.00000  20236.00000  21520.00000  21948.00000  
19780.00000  20572.00000  21056.00000  20748.00000  20088.00000  
20560.00000  21188.00000  20608.00000  22136.00000  20736.00000] 

I have seen MATLAB vs C++ vs OpenCV - imresize without success.

Thank you for your help.

mr.ao
  • 71
  • 6
  • find out what kind of interpolation is used in matlabs imwarp – Micka Dec 15 '17 at 19:18
  • do both results look similar? Is the result size equal? – Micka Dec 15 '17 at 19:19
  • @Micka cubic interpolation is used in matlab, the result size is equal,and first rows look similar, but last rows not – mr.ao Dec 15 '17 at 19:43
  • @Micka , I improve my post – mr.ao Dec 15 '17 at 20:28
  • why are matlabs last row and column zero? – Micka Dec 15 '17 at 21:11
  • looks like different border interpolation? – Micka Dec 15 '17 at 21:14
  • `Matlab: 'FillValues' — Value used for output pixels outside image boundaries numeric scalar or array Value used for output pixels outside the input image boundaries, specified as the comma-separated pair consisting of 'FillValues' and a numeric array. Fill values are used for output pixels when the corresponding inverse transformed location in the input image is completely outside the input image boundaries. If the input image is 2-D, FillValues must be a scalar.` – mr.ao Dec 15 '17 at 21:40
  • Opencv: `borderMode – pixel extrapolation method (see borderInterpolate()); when borderMode=BORDER_TRANSPARENT , it means that the pixels in the destination image corresponding to the “outliers” in the source image are not modified by the function. borderValue – value used in case of a constant border; by default, it is 0.` – mr.ao Dec 15 '17 at 21:42

0 Answers0