I performed an image downsampling with averaging operation(The image is divided into 2 by 2 blocks,then it is downsampled by 4 times.New pixel values od downsampled image is replaced with the mean of each block) as follows.

img = imread('cameraman.gif');
avgfilter = fspecial('average', [2 2]);
avgimg = filter2(avgfilter, img);
down1 = avgimg(1:2:end,1:2:end);

I used a graysacle image as input.

enter image description here

but I'm getting a complete white image as output on downsampling.
I tried with jpg image also. Why this happened?
Please help.


When you open an image using imread, you get the image as a uint8 matrix with grayscale (or color) values of 0-255. However, filtering is no possible for this type. Therefore, filter2 converts your image to double.
The function imshow accepts both uint8 and double type. When the input is uint8 it also assumes color values of 0-255. But, when the input is double, it assumes the values are normalised to the range of 0-1. Therefore you should tell imshow that although your input is of type double it has color values of 0-255 by using

imshow(down1,[0 255]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.