我需要在c代码中实现以下公式: https://en.wikipedia.org/wiki/Lanczos_resampling 因此,我使用多维插值方法:
其中L(x-i)或L(y-i)是:
我使用ppm图像格式通过一个小脚本获取rgb值。 这是我现在的实际lanczos方法:
double _L(int param) {
/*
LANCZOS KERNEL
*/
int a = 2; // factor "a" from formula
if(param == 0) {
return 1;
}
if(abs(param) > 0 && abs(param) < a) {
return (a*sin(PI*param) * sin((PI*param)/a))/(PI*PI*param*param)
}
return 0;
}
void lanczos_interpolation(PPMImage *img) {
if(img) {
int start_i, start_j, limit_i, limit_j;
int a = 2; // factor "a" from formula
samples_ij = img->x*img->y; // "sij" from formula
for(x = 0;x < img->x;x++) {
for(y = 0;y = < img->y;y++) {
start_i = floor(x)-a+1:
limit_i = floor(x)+a;
for(i = start_i;i <= limit_i;i++) {
start_j = floor(y)-a+1:
limit_j = floor(y)+a;
for(i = start_i;i <= limit_i;i++) {
img->data[x+(W*y)].red = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].green = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].blue = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
}
}
}
}
}
}
这部分代码让我很困惑:
img->data[x+(W*y)].red = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].green = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
img->data[x+(W*y)].blue = (int)(samples_ij * _L(x-i) * _L(y-j)) // "_L" represents "L(x-i)" from formula
有人可以帮助我在c中使用这个lanczos插值吗? 这是我完整的C档案:
谢谢!
答案 0 :(得分:2)
在代码中看到没有进行任何插值。
插值操作如下:
[input pixels
] =&gt; [Lanczos interpolation
] =&gt; [output interpolated pixels
]
|
|
V
a sum operation in the neighbourhood
of the corresponding location
in the input image
您的问题如下:
Lanczos interpolation technique
。事实上,您似乎并不知道插值是什么。input pixels
和output pixels
。summation
。 (您只是将Lanczos系列时间s_ij
指定为img
像素。再次s_ij
&#39} s实际上是公式中的input
像素值,但您已为图片中的像素总数分配固定值s_ij
。)floor(*)
个功能。我的建议是: