フィルターのクリア

Mean of neighbor pixel

4 ビュー (過去 30 日間)
Efstathios Kontolatis
Efstathios Kontolatis 2016 年 10 月 4 日
編集済み: Matt J 2021 年 3 月 25 日
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

採用された回答

Matt J
Matt J 2016 年 10 月 4 日
編集済み: Matt J 2016 年 10 月 4 日
Just use convolution,
k=[1 1 1; 1 0 1; 1 1 1]/8;
averageIntensities = conv2(double(yourImage),k,'same');
  3 件のコメント
Arghya Pathak
Arghya Pathak 2021 年 3 月 25 日
"same" stands for what?
Matt J
Matt J 2021 年 3 月 25 日
編集済み: Matt J 2021 年 3 月 25 日

サインインしてコメントする。

その他の回答 (1 件)

Adam
Adam 2016 年 10 月 4 日
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 件のコメント
Efstathios Kontolatis
Efstathios Kontolatis 2016 年 10 月 4 日
編集済み: Efstathios Kontolatis 2016 年 10 月 4 日
I want to find the average intensity of the neighbors without using the central point. Also, I don't think that this solution will give me the neighbors on the borders of the image. I used this code
for i=1:height
for j=1:width
neighbours(i,j).ar=img(j-1:j+1, i-1:i+1);
end
end
and I take the following message 'Subscript indices must either be real positive integers or logicals'. Img is a uint16 image. As you can see I want to save the neighbors of each pixel.
Adam
Adam 2016 年 10 月 4 日
編集済み: Adam 2016 年 10 月 4 日
Yes, you have to deal with the borders differently, but that is not difficult.
If you don't want the middle point then just throw it away and collapse the neighbours to a 1d array since you will just be taking the mean anyway - e.g.
neighbours(5) = [];

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by