# Image getting completely white on downsampling

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);
imshow(down1);


I used a graysacle image as input.

but I'm getting a complete white image as output on downsampling.
I tried with jpg image also. Why this happened?
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]);