Reducing intensity in an image using a function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
PenguinForce
el 12 de Oct. de 2016
Comentada: Image Analyst
el 12 de Oct. de 2016
So I'm trying to use mean filtering to process an image. The idea of mean filtering is simply to replace each pixel value in an image with the mean (average) value of its neighbors, including itself.
0 comentarios
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 12 de Oct. de 2016
Try conv2:
windowSize = 3;
kernel = ones(windowSize)/windowSize^2;
filteredImage = conv2(double(grayImage), kernel, 'same');
imshow(filteredImage, []);
This will give an output image where each pixel is the mean of a sliding 3-by-3 window.
2 comentarios
Walter Roberson
el 12 de Oct. de 2016
conv2 will not give the answer the user wants at the edges, as it will zero pad, but still divide by the windowSize^2. The user wants the edges to only be divided by the number of pixels that are in-bounds.
You can run a correction afterwards -- multiply the edge values by windowSize^2 and then divide by the number of valid neighbours, which would be 6 everywhere except the corners and would be 4 there.
Image Analyst
el 12 de Oct. de 2016
Yes, there are boundary/edge effects with filters and there are different ways of handling them. imfilter() is like conv2() but offers more boundary handling options. Unfortunately none of them see to be the "shrinking window" effect like Walter mentioned. For a 3x3 filter (nearest 8 neighbors), only the outermost perimeter layer of edge pixels is affected. So if the outer 1-pixel-wide boundaries are important to you, and you want that "shrinking window" option, you'll have to do like Walter explained. It is possible to do it with nlfilter() or blockproc() but those won't be nearly as fast as conv2() or imfilter() which are highly optimized, so to just fix up one pixel, I wouldn't bother with those.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!