
smoothing image with moving average filter
2 ビュー (過去 30 日間)
古いコメントを表示
Hello i have a question. how can i smoothing this image with moving average filter 5*5 for only green Thank you so much.

0 件のコメント
回答 (1 件)
Rushil
2025 年 2 月 21 日
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!