The reason why this is happening is because your average image after you use filter2
is a double type image. You're not the first person (and probably not the last person...) to experience this mixup with imshow
. In fact, almost all of the problems that I have solved with regards to imshow
here on StackOverflow is because of this small mixup with imshow
.
You have to be cognizant of the type of image you are trying to display with imshow
before you decide to use the function. Images of type double
are expected to have its intensities / colour channels to be in the range between [0,1]
. Anything below 0
is set to black while anything beyond 1
is set to white, which is why you are getting a completely white image.
You need to convert back to uint8
to properly display the image. As such, try doing this before you show your image:
down1 = uint8(down1);
imshow(down1);
When I do this, this is what I get when I show the downsampled image.

Minor comment
FWIW, when it comes to image filtering, I would personally use imfilter
instead. imfilter
is designed for image filtering where filter2
is for more generic 2D signals. One thing that is good about imfilter
is that it will output an image of the same type where filter2
will default to double
. I would stay away from filter2
unless you're forced to use it on images.
As such, replace your filter2
syntax with:
avgimg = imfilter(img, avgfilter);
If you do this instead, you don't need to cast your image back to uint8
. You will be able to visualize the results properly with imshow
.