sliding window
Mostrar comentarios más antiguos
How to apply a 3x3 sliding window for an image while the pixel in the center of the window should have the mean value of the window.
Respuestas (3)
Ben Mitch
el 22 de Mayo de 2011
I think you're after filter2(). Try
mn = filter2(ones(3), im);
5 comentarios
Gova ReDDy
el 22 de Mayo de 2011
Jan
el 23 de Mayo de 2011
Read "doc filter2". I assume you need a further normalization: "filter2(ones(3)/9, im)".
Ben Mitch
el 25 de Mayo de 2011
assuming your image comes from a file (if not, the process is much the same)...
im = imread('my_image.png');
im = double(im);
im = mean(im, 3); % convert to greyscale, if is RGB
b = ones(3)/9;
im = filter2(b, im);
imshow(im);
if you need to work in RGB rather than greyscale, you could use something like...
for d = 1:3
im(:, :, d) = filter2(b, im(:, :, d));
end
Gova ReDDy
el 11 de Jun. de 2011
Image Analyst
el 12 de Jun. de 2011
But that's exactly what Ben, Jan, and Sean de's code does! Did you look up the help for filter2()? It is basically conv2() (which is highly optimized) with the 'same' option. (I always use conv2 rather than filter2.) Write a test with a small image to convince yourself.
Jan
el 11 de Jun. de 2011
1 voto
What is "the next 3x3 position"? Will the resulting picture have a width and size reduced by 3? If so, this can achieve the calculation efficiently: FEX: BlockMean
2 comentarios
Gova ReDDy
el 12 de Jun. de 2011
Image Analyst
el 12 de Jun. de 2011
Patan, how many times do we have to say it. CONV2 AND IMFILTER WILL DO WHAT YOU'RE ASKING!!!!
Sean de Wolski
el 25 de Mayo de 2011
Imean_window = conv2(double(I),ones(3)/9,'valid');
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!