首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C中的Lanczos插值

C中的Lanczos插值
EN

Stack Overflow用户
提问于 2015-12-10 09:50:51
回答 1查看 3.3K关注 0票数 1

我需要在c代码中实现以下公式:resampling,因此我使用多维插值方法:

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

我使用ppm图像格式,通过一个小脚本获得rgb值。这是我现在实际的lanczos方法:

代码语言:javascript
复制
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
                    }
                }
            }
        }
    }   
}

代码的这一部分让我很困惑:

代码语言:javascript
复制
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

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-12-11 18:40:30

请看,您是,没有在代码中进行任何形式的插值

插值操作如下:

input pixels => Lanczos interpolation => output interpolated pixels

代码语言:javascript
复制
                        |
                        |
                        V
        a sum operation in the neighbourhood 
            of the corresponding location
               in the input image

你的问题如下:

  1. 你没有理解 Lanczos interpolation technique。事实上,你似乎不知道什么是插值
  2. 您的代码没有input pixelsoutput pixels
  3. 代码中没有summation。(您只是将Lanczos高效时间s_ij分配给img像素。同样,s_ij的像素值实际上是公式中的input像素值,但是将图像中像素总数的固定值分配给s_ij
  4. 您不必要地使用了floor(*)函数。

我对你的建议是:

  1. 以算法的方式理解什么是插值。
  2. 为您的目的编写算法/伪代码
  3. 确保您在步骤1和步骤2中是正确的
  4. 然后只尝试编写代码
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34198553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档