フィルターのクリア

How to find four neighbours of a pixel in an indexed image?

3 ビュー (過去 30 日間)
Anwesha Sharma
Anwesha Sharma 2021 年 7 月 29 日
コメント済み: Anwesha Sharma 2021 年 8 月 2 日
I have an indexed image with 7 indices. I have to find how many neighbors of each pixel with index=7 are pixels with index = 6.
I wrote the code below, however, I am not getting a correct histogram.
[A,map] = imread('FCLS_crop_20190627_1.tif');
for i=1:numel(A)
if A(i)==7
[ix,ixn] = ixneighbors(A,i);
fprintf('index[%d]',ix);
fprintf('\n');
neigh = A(ixn);
fprintf('%d\t',neigh);
numberOfNonZeros = nnz(neigh==6);
NumofOnes(i) = numberOfNonZeros;
end
end
hist(NumofOnes);
xlabel('Number of Neighbors')
ylabel('Frequency')
  3 件のコメント
Rik
Rik 2021 年 7 月 29 日
Or a loop with calls to circshift so you can test equality for the entire array at once?
Anwesha Sharma
Anwesha Sharma 2021 年 8 月 2 日
Thanks.

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

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by