image-processing - 以下用于图像调整大小的 c++ 双三次插值代码有什么问题

我正在尝试使用双三次插值对图像进行上采样,我需要与 opencv 的 cvResize() 函数匹配的准确值,但以下代码的结果与 cvResize() 的结果不匹配,你能帮我看看吗修复错误。
图片 *Image::resize_using_Bicubic(int w, int h) {
float dx,dy;
float x,y;
float tx, ty;
float i,j,m,n;
Image *result=new Image(w, h); tx = (float)this->m_width/(float)w; ty = (float)this->m_height/(float)h; for(i=0; i< w; i++) { for(j=0; j< h; j++) { x = i*tx; y = j*ty; dx = float(i-x)-(int)(i-x); dy = float(j-y)-(int)(j-y); float temp=0.0; for(m=-1;m<=2;m++) { for(n=-1;n<=2;n++) { int HIndex,WIndex; HIndex=(y+n); WIndex=(x+m); if (HIndex<0) { HIndex=0; } else if(HIndex>this->getHeight()) { HIndex=this->getHeight()-1; } if (WIndex<0) { WIndex=0; } else if(WIndex>this->getWidth()) { WIndex=this->getWidth()-1; } temp+=this->getPixel(HIndex,WIndex)*R(m-dx)*R(dy-n); } } result->setPixel(j, i, temp); } } return result;
}

最佳答案

你没有说结果有多么不同。如果它们非常接近,例如在每个 RGB channel 中相差 1 或 2,这可以简单地通过舍入差异来解释。

双三次插值的算法不止一种。 Don Mitchell 和 Arun Netravali 进行了分析,并提出了一个公式来描述其中的一些:http://www.mentallandscape.com/Papers_siggraph88.pdf

编辑:还有一件事,应该将各个滤波器系数相加并用于最后除以最终值,以对值进行归一化。我不知道你为什么有 m-dx一个和dy-n对于另一个,它们不应该是同一个符号吗?

r=R(m-dx)*R(dy-n);
r_sum+=r;
temp+=this->getPixel(HIndex,WIndex)*r;
. . .
result->setPixel(j, i, temp/r_sum);

https://stackoverflow.com/questions/7110716/

相关文章:

iphone - 如何改善iPhone应用程序的边缘检测?

visual-studio-2010 - 如何在VS2010 Windows 7中安装tbb_ded

exception - openNI干扰cvCreateCameraCapture()

docker - 与 WORKDIR 相关的映射卷

docker - chown : changing ownership of '/var/lib/m

opencv - 段错误 OpenCV/Facedetect.c/CentOS 6 64Bit

vb.net - 如何从VB.net轻松调用IronPython函数?

python - 'import cv' 之后的 `Fatal Python error: PyTh

opencv - Eclipse中的OpenCV编译错误

image-processing - 有关cvPerspectiveTransform的OpenCV