- conv2: https://www.mathworks.com/help/releases/r2024b/matlab/ref/conv2.html
- conv: https://www.mathworks.com/help/ releases/r2024b matlab/ref/convn.html
how to find the local mean value for an image?
6 次查看(过去 30 天)
显示 更早的评论
I have an image and I want to calculate the average pixel value of that image, i.e. the value at each pixel is the average value of neighbourhood pixels' intensities in 3*3 window of the image. Therefore, for every pixel, we have to take the mean of its neighbourhood pixels' intensities.
Does anyone know how to do this in matlab?
0 个评论
回答(1 个)
Abhishek
2025-3-11
Hi Ghada,
As per my understanding, you are looking for help with blurring an image by calculating the average value of each pixel using a 3-by-3 kernel. This process involves applying a simple averaging filter to smooth the image. Below is how it can be achieved:
I = imread('cameraman.tif'); % Read the image
I2 = im2double(I); % Convert image to double
kernel = ones(3)/9; % Define a 3x3 averaging kernel
I3 = conv2(I2, kernel, "same"); % Apply convolution
imshow(I3); % Display the image
The above code works for grayscale images. For an RGB image, replace “conv2” with “convn” to handle multiple color channels.
To learn more about the “conv2” and “conv” functions, refer to the MATLAB documentation links below:
I hope this answers your question.
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!