我试图实现双三次插值;
这是我的问题的后续问题:MATLAB vs C++ vs OpenCV - imresize 左右imresize,所以我知道openCV不像matlab那样进行三次插值。 我需要得到像matlab一样的结果。为了imresize。
所以举个例子我想得到我图像的第一个像素
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);
return NULL;
}
double Utilities::cubicInterpolate (double p[4], double x)
{
return 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);
return cubicInterpolate(arr, x);
}
我仍然没有得到相同的结果,因此我猜测我的内核与matlab使用的内核不同。我怎样才能得到相同的结果?
**我原来的4x4< ** br>
155 306 155 306
293 213 293 213
172 325 172 324
291 198 290 198
结果我来自 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
我的结果是155.3437500000000
更新
使用@ andrey的建议我进入了imresize代码
这就是那里写的:
数字图像%处理的立方卷积插值," IEEE 声学,语音和信号处理的交易,处理,卷。 ASSP-29,第6号,1981年12月,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));
我不明白这个功能如何:
float Utilities::Cubic(const float& x, const float& scale)
{
/*
% See Keys, "Cubic Convolution Interpolation for Digital Image
% Processing," IEEE Transactions on Acoustics, Speech, and Signal
% Processing, Vol. ASSP-29, No. 6, December 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));
return f*scale;
}
x是要插值的点与网格点之间的距离 考虑
可以处理4X4矩阵,就像我有的其他三次插值一样?