smoothing image with moving average filter
Afficher commentaires plus anciens
Hello i have a question. how can i smoothing this image with moving average filter 5*5 for only green Thank you so much.

Réponses (1)
Rushil
le 21 Fév 2025
Hi
From what I understood, the task at hand is to compute a moving average over each 5x5 window, in order to smoothen the image. This can be accomplished using the conv2 function, using a filter of size 5x5 with all values being
. You can find the supporting documentation of conv2 at the link below:
Below is some implementation that may help:
img = imread("file_name.jpeg");
% isolate the green channel
green = img(:, :, 2);
filter = ones(5, 5) / 25;
% here we use convolution for faster implementation
% the result is a moving mean in a 5x5 window
paddedGreenChannel = padarray(green, [2, 2], 'replicate');
% padding to avoid wrong mean calculation for edges
smoothedGreenChannel = conv2(double(paddedGreenChannel), filter, 'valid');
smoothedGreenChannel = uint8(smoothedGreenChannel);
% replace the green channel with the update one
smoothedImg = img;
smoothedImg(:, :, 2) = smoothedGreenChannel;
% to plot and compare both the images
figure;
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(smoothedImg);
title('Smoothed Image');
Hope it's helpful
Catégories
En savoir plus sur Smoothing and Denoising dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!