【问题标题】:Resizing a the dimensions of a pixel pgm image in C在 C 中调整像素 pgm 图像的尺寸
【发布时间】:2020-07-16 14:06:08
【问题描述】:

我想要做的是调整常规 pgm 图像的大小,将 3--100X100 的因子变为 33X33,我使用指针数组来存储原始图像和调整大小的图像,原始图像将是 10000 长并且调整大小的图像将是 1089 长,我正在尝试获取宽度维度中的每 3 个元素并跳过两个宽度行(因为高度也需要减少),当我写它时,我不断得到一个奇怪的模糊图像一个 pgm 输出,我知道可能会有一点差异,因为我们正在舍入高度和宽度,这只是代码的一部分。

enter code here
int k,l,m;
image =(unsigned char*) malloc((width*height) * sizeof(unsigned char));
 int thumbHeight=round(height/3);
 int thumbWidth =round(width/3);

resizedImage =(unsigned char*) malloc(((resizedWidth*resizedHeight)) * sizeof(unsigned char));

 for(l=0;l<resizedHeight;l++){

    for(k=0;k<resizedWidth;k++){
      *resizedImage= *image;
    
     image++;
     image++;

  }
 //skipping two lines
 for (m=0;m<width*2;m++){
    image++;
    
 }
 }

【问题讨论】:

    标签: c image pgm


    【解决方案1】:

    也许:

    unsigned char *resize(const unsigned char *source, unsigned char *dest, size_t origx, size_t origy, size_t destx)
    {
        double ratio = (double)destx / origx;
        double stepx = (double)origx / destx;
        double stepy = (double)origy / (origy * ratio);
    
        for(size_t y = 0;  y < origy * ratio; y++)
        {
            for(size_t x = 0;  x < destx; x++)
            {
                dest[y * destx + x] = source[(ssize_t)((y * stepy) * origx + x * stepx)];
            }
        }
        return dest;
    }
    

    但我没有运行它,所以它可能是错误的。

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 2014-04-23
      • 2015-07-18
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      相关资源
      最近更新 更多