how to select neighbouring 5 pixels of an image

I wanted to take one pixel from an image say im(x,y)
then take the neighbouring 5 pixels of position im(x,y)
find the maximum value of the 5 pixels and save it in maxIm(x,y)
please can someone help me write the code - i also want to do it for all the pixels in the image, so that i get maxIm the same size as im
(5 must be 4-neighbourhood pixels, including the center pixel)

 Accepted Answer

imdilate(YourImage, ones(11,11) )
The 11 is determined as "5 pixels in each direction relative to the center pixel".
It is plausible that you might want ones(5,5) instead, in which case the neighbourhood would be
*****
*****
**C**
*****
*****
where C marks the center pixel.
Your question is ambiguous about what the 5 means.

6 Comments

5 must be 4-neighbourhood pixels, including the center pixel
imdilate(YourImage, [0 1 0;1 1 1;0 1 0])
what about maximum of the 5 pixels? actually i wanted to select that 5-pixel block and divide it with the maximum of those 5 pixel value and then save it in maxIm(x,y)
so i think it should be overlapping? is it right? when doing imdilate will it be overlapping?
Dilation is the maximum of all of the pixels in the neighbourhood: that is how it is defined.
If I understand correctly, you take each overlapping 3 x 3 area and take the maximum, and then you want to divide something by that. Is it the entire 3 x 3 area that you want to divide, including the pixels whose maximum you did not take? Is it that you want to divide the 5 pixels by the maximum of the 5 pixels, getting out.. what, a vector of 5 floating point numbers for each original input location ?
No, not a vector, must be a single value
YourMatrix./imdilate(YourMatrix, [0 1 0;1 1 1;0 1 0])

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!