我需要在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 文件:
谢谢!
最佳答案
看看您的代码中没有进行任何类型的插值。
插值运算是这样的:
[输入像素
] => [Lanczos插值
] => [输出插值像素
]
|
|
V
a sum operation in the neighbourhood
of the corresponding location
in the input image
您的问题如下:
- 您不理解
Lanczos 插值技术
。事实上,您似乎不知道什么是插值。 - 您的代码没有
输入像素
和输出像素
。 - 您的代码中没有
求和
。 (您只需将 Lanczos 系数时间s_ij
分配给img
像素。同样,s_ij
实际上是输入
code> 公式中的像素值,但您已将图像中像素总数的固定值分配给s_ij
。) - 您不必要地使用了
floor(*)
函数。
我给你的建议是:
- 理解什么是算法插值。
- 根据您的目的编写算法/伪代码。
- 确保您在第 1 步和第 2 步中正确。
- 然后只尝试编写代码。
关于c - C 中的 Lanczos 插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198553/