Mean of neighbor pixel
10 views (last 30 days)
Show older comments
Hi guys,
I try to calculate the average intensity value of the neighbors of a pixel(either 8 or not). I am confused with the way matlab uses matrices(i-th,j-th position of a pixel is at j-th,i-th position of the matrix) and I have difficulties find the neighbors.
Thanks
0 Comments
Accepted Answer
More Answers (1)
Adam
on 4 Oct 2016
If you are finding all 8 neighbours then it doesn't make a difference which is x,y and rows, columns, but your confusion and that comes from the fact that a matrix is indexed as (row,column), whereas an image is (x,y) more usually where x is horizontal and is therefore represented by columns of the image.
The neighbours of a pixel are simply
neighbours = yourMatrix( yLoc-1:yLoc+1, xLoc-1:xLoc+1 )
for a pixel at ( xLoc, yLoc ) in a matrix called yourMatrix.
This will also include the point itself, but that is easy to get rid of and you didn't state what you want to do with the neighbourhood so it may or may not be better to keep the central point for it to retain its 2d structure.
2 Comments
Efstathios Kontolatis
on 4 Oct 2016
Edited: Efstathios Kontolatis
on 4 Oct 2016
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!