Shrink Image

Hi I am not able to shrink the image.
Here's the code.
Kindly help me to shrink it.

1
2
3
4
5
6
7
8
9
10
11
12
  for( row=0; row<numRow / 2; row++)
  {
            
     for(col =0; col<numCol / 2; col++)
     {
	if(array[row][col] % 2 != 0)
	{
	    shrinkArray[row][col] = array[row][col];
	}
				 
     }
  }
What do you mean by "to shrink the image"?
My Image is 260*200 and I want to change it in 130*100
how about change it directly...
1. There are image manipulation programs. Do you have to use C++?

2. If you would shrink down to 1x1, what would be the color of that one and only pixel?

3. Your code looks more a (lossy) crop than a shrink.

4. What is in an element of your arrays?
Yes I have to use C++.
Pixels are the elements of array.
I am not able to shrink.
Would u please tell me the suitable code or algorithm to shrink the image.
Pixels are in the array I want to store the half of them in shrinkArray by dropping one pixel after two.
You can interpolate the pixels, which is a fancy word that means "take the average of Rs over a block, the average of Gs over the block, and the average of Bs over a block"

That is, if you had 9 pixels, and wanted to convert those to 1 pixel, you would just average the color components. This gives you a 3 to 1 reduction in size.

that is a decent method.

But it isnt what you asked :)

Your problem is:
if(array[row][col] % 2 != 0)

I think you wanted

if(row%2 == 0 && col%2==0)
{
keep the pixel
}

and the loops shouldn't divide by 2.

basically you need to loop over ALL the pixels, and only keep half of them. So the loops go over everything, and the keep logic tosses out every other one in both dimensions... right?


also have no idea what you have here, but a typical image is at least 3 bytes / pixel. If this is greyscale, or you have wrappers that I don't understand, it may be fine.... if it is colors and that loop is over bytes, it is wrong.

Last edited on
You want a "2->1 shrink". Four pixels (a 2*2 square) in old image is converted to single pixel in the new image.

If you do look at pixel {x,y} in the new image, what are the indices of those four pixels of the old image? Can you figure that out?
Topic archived. No new replies allowed.