0

What i am trying to do i resize the a regular pgm image,by a factor of 3--100X100 becomes 33X33,i am using pointer array to store the original image and the resized image, the original image will be 10000 long and the resized image will be 1089 long, I am trying to do get the every 3rd element in the width dimension and skipping two width rows(as height also needs to be reduced),I keep getting a weird blurry image when I write it in a pgm output,i get there might be a little difference as we are rounding height and width,this is just a bit of the code.

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++;
    
 }
 }
Dan Mašek
  • 17,852
  • 6
  • 57
  • 85

1 Answers1

0

maybe:

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;
}

But I did not run this so it may be buggy.

0___________
  • 60,014
  • 4
  • 34
  • 74