How do you average each pixel in an image with a 9x9 square?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eric Yang
el 18 de Oct. de 2020
Respondida: Image Analyst
el 18 de Oct. de 2020
I tried to provide a diagram for my situation. Essentialy I have a 1280 X 1024 pixel image that needs to be processed through an equation that specifically requires each individual pixel to be put through a function in a 9x9 square, ignoring the edge cases where a 9x9 square cannot be formed. I've created a nested for loop that goes through each individual pixel in the image, but don't know how to select a 9x9 matrix to work with. Based on the diagram below, the target pixel iterates from the black, to purple, to blue, then to pink box.
As the function processes each individual pixel, I do not want it to modify the original image, rather store it in a new image. For context, this is for producing a laser speckle contrast image.
I tried following the documentation from https://www.mathworks.com/matlabcentral/answers/272994-calculate-average-around-pixel ,but I don't see how I can apply it for successive pixels.
I've also tried using mat2tiles, but that doesn't meet the criteria for the problem i'm trying to solve since it creates a tile, rather than average the next pixel in the image.
3 comentarios
Rik
el 18 de Oct. de 2020
I would suggest calculating all terms individually. When I'm back at a computer I can write an example for you.
Respuesta aceptada
Rik
el 18 de Oct. de 2020
Editada: Rik
el 18 de Oct. de 2020
If you want the average (or something like a gaussian blur): use conv2, as described in the answer you linked. Read the documentation for that function to see how to keep only the results from the places where you have a full surrounding field.
0 comentarios
Más respuestas (1)
Image Analyst
el 18 de Oct. de 2020
Try conv2() or imfilter():
kernel = ones(9)/81; % Define filter window to take the mean in a 9x9 square.
blurredImage = imfilter(grayImage, kernel); % blurredImage is the same class as grayImage.
% or
blurredImage = conv2(double(grayImage), kernel, 'same'); % blurredImage is a double.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!