MATLAB Answers


How can I make a Loop (!) over the image using a 5×5 pixel window

Asked by Nadeen Bahnam on 14 Nov 2019 at 9:00
Latest activity Commented on by Nadeen Bahnam on 20 Nov 2019 at 11:15
Loop (!) over the image using a 5×5 pixel window. For each such window, compute the average pixel value and store the result in a new image. Treat borders in some controlled way and make sure the result has the same size in pixels as the original image. You will need at least two nested for-loops, to scan rows and columns in your image.


Show 1 older comment
There is no need of loops, is it must be use?
Is there some other way to solve this if loops are not be used ?
nlfilt(), blockproc(), conv2()

Sign in to comment.

1 Answer

Answer by Mahesh Taparia on 20 Nov 2019 at 10:17
 Accepted Answer

Hi Nadeen,
It seems you want to do average filtering of an image with the kernal size of 5x5. It can be done using imfilter command. Consider the code below:
window_size = 5;
filter_type=fspecial('average', window_size);
filtered_image = imfilter(I,filter_type, 'replicate'); %%% I = image
For more details refer to the documentation page of imfilter using the link given below:

  1 Comment

Sign in to comment.