c - C 中的 Lanczos 插值

标签 c image resampling lanczos

我需要在c代码中实现以下公式: https://en.wikipedia.org/wiki/Lanczos_resampling 因此我使用多维插值方法:

Multidimensional interpolation

其中 L(x-i) 或 L(y-i) 是:

Lanczos Kernel

我正在使用 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 文件:

http://pastebin.com/wdUHVh6U

谢谢!

最佳答案

看看您的代码中没有进行任何类型的插值

插值运算是这样的:

[输入像素] => [Lanczos插值] => [输出插值像素]

                        |
                        |
                        V
        a sum operation in the neighbourhood 
            of the corresponding location
               in the input image

您的问题如下:

  1. 不理解Lanczos 插值技术。事实上,您似乎不知道什么是插值
  2. 您的代码没有输入像素输出像素
  3. 您的代码中没有求和。 (您只需将 Lanczos 系数时间 s_ij 分配给 img 像素。同样,s_ij 实际上是输入 code> 公式中的像素值,但您已将图像中像素总数的固定值分配给 s_ij。)
  4. 您不必要地使用了 floor(*) 函数。

我给你的建议是:

  1. 理解什么是算法插值。
  2. 根据您的目的编写算法/伪代码
  3. 确保您在第 1 步和第 2 步中正确
  4. 然后只尝试编写代码

关于c - C 中的 Lanczos 插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198553/

相关文章:

java - 在 JFrame 中显示 .png 图像?

r - Caret包中的数据分区和过拟合

将方程转换为 cnf,以便使用 sat 求解器

c - 如何在 C 中使用 gets() 打印多个字符串(带空格)?

c++ - 这行代码是什么意思*((int*)(0))=1;?

python - 使用 Python 将 PDF 转换为图像

c - Intel Xeon Phi 上的快速人口统计

css - 无法让 bg img 在 CSS 中做我想做的事

python-3.x - python中的resample或asfreq pandas时间序列数据帧错误为 'Duplicate Index'

audio - 如何在 Rust 中将 16 位 PCM 音频的采样率从 24000 Hz 更改为 48000 Hz?