bicubic interpolation - Matlab to C++ -
bicubic interpolation - Matlab to C++ -
i'm trying implement bicubic interpolation;
this follow-up question question:matlab vs c++ vs opencv - imresize imresize, know opencv doesn't cubic interpolation matlab. , need same results matlab. imresize.
so illustration want first pixel of image
int* utilities::matlabimresize(int* channel,int width, int height, double scale) { double test[4][4] = {{channel[0],channel[1], channel[2], channel[3]}, {channel[width],channel[width+1], channel[width+2], channel[width+3]}, {channel[2*width],channel[2*width+1], channel[2*width+2], channel[2*width+3]}, {channel[3*width],channel[3*width+1], channel[3*width+2], channel[3*width+3]}}; double x = bicubicinterpolate(test,0.5,0.5); homecoming null; } double utilities::cubicinterpolate (double p[4], double x) { homecoming p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0]))); } double utilities::bicubicinterpolate (double p[4][4], double x, double y) { double arr[4]; arr[0] = cubicinterpolate(p[0], y); arr[1] = cubicinterpolate(p[1], y); arr[2] = cubicinterpolate(p[2], y); arr[3] = cubicinterpolate(p[3], y); homecoming cubicinterpolate(arr, x); }
i still don't same results i'm guessing kernel isn't same 1 matlab using. how can same results?
**my original 4x4<**br>
155 306 155 306 293 213 293 213 172 325 172 324 291 198 290 198
the results i'm getting matlab:
151.196136474609 155.925476074219 155.555526733398 145.714401245117 151.044921875000 155.254089355469 157.459579467773 154.982849121094 149.490341186523 151.587142944336 150.641662597656 155.392364501953 153.666915893555 156.283508300781 156.848739624023 155.557098388672 147.997482299805 154.688049316406 157.798034667969 152.912796020508
my result pixel 0,0 155.3437500000000
update: using @andrey's advice went imresize code written there:
cubic convolution interpolation digital image % processing," ieee transactions on acoustics, speech, , signal % processing, vol. assp-29, no. 6, dec 1981, p. 1155.
http://www.academia.edu/2266812/cubic_convolution_interpolation_for_digital_image_processing
absx = abs(x); absx2 = absx.^2; absx3 = absx.^3; f = (1.5*absx3 - 2.5*absx2 + 1) .* (absx <= 1) + ... (-0.5*absx3 + 2.5*absx2 - 4*absx + 2) .* ... ((1 < absx) & (absx <= 2));
i not understand how function:
float utilities::cubic(const float& x, const float& scale) { /* % see keys, "cubic convolution interpolation digital image % processing," ieee transactions on acoustics, speech, , signal % processing, vol. assp-29, no. 6, dec 1981, p. 1155. */ float absx = fabs(x*scale); float absx2 = pow(absx, 2); float absx3 = pow(absx, 3); float f = (1.5*absx3 - 2.5*absx2 + 1) * (absx <= 1) + (-0.5*absx3 + 2.5*absx2 - 4*absx + 2) * ((1 < absx) & (absx <= 2)); homecoming f*scale; }
x distance between point interpolated , grid point beingness considered
can handle 4x4 matrix other cubic interpolation have?
c++ matlab opencv image-processing interpolation
Comments
Post a Comment