find 8 neighbours in image

17 ビュー (過去 30 日間)
Sajid Rahim
Sajid Rahim 2017 年 9 月 21 日
回答済み: Mehadi Hasan 2021 年 10 月 22 日
hi dears..... plz help me
how i find the 8 neighbours around the white pixels...
  3 件のコメント
RASHMI CHINNAPPA
RASHMI CHINNAPPA 2020 年 7 月 4 日
how to find the 8 neighbours around a single white region
Image Analyst
Image Analyst 2020 年 7 月 4 日
Use imdilate() then and it with the original
neighbors = imdilate(bw, true(3)) & ~bw;

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

回答 (2 件)

KSSV
KSSV 2017 年 9 月 21 日
Read about knnsearch
I = imread('2.png') ;
I = rgb2gray(I) ;
[y,x] = find(I) ;
% 8 nearest neighbors
[ny,nx] = size(I) ;
[X,Y] = meshgrid(1:nx,1:ny) ;
% global indices
idx = knnsearch([X(:) Y(:)],[x,y],'k',8) ;
% sub indices
[i,j] = ind2sub(size(I),idx) ;
  2 件のコメント
Sajid Rahim
Sajid Rahim 2017 年 10 月 16 日
編集済み: Walter Roberson 2017 年 10 月 17 日
clear all;
[filename
pathname]=uigetfile('*.jpg;*.png;*.tif;*.tiff;*.gif;*.bmp;');
inputimage=imread([pathname filename]);
I=inputimage;
% I = imread('5.png') ;
I = rgb2gray(I) ;
[y,x] = find(I) ;
figure
imshow(I)
hold on
plot(x,y,'.b')
% x
% y
% z=(y+x)/2
% plot(z,'.r')
a=x(1)
b=y(1)
plot(x(1),y(1),'*y')
plot(x(end),y(end),'*y')
% neighbors(1) = (a,b-1);
neighbors(1) = I(a,b-1);
plot(a,b-1,'*r')
neighbors(2) = I(a,b+1);
plot(a,b+1,'*r')
neighbors(3) = I(a,b+2);
plot(a,b+2,'*r')
neighbors(4) = I(a+1,b);
plot(a+1,b,'*r')
neighbors(5) = I(a+1,b+1);
plot(a+1,b+1,'*r')
neighbors(6) = I(a+2,b+2);
plot(a+2,b+2,'*r')
neighbors(7) = I(a+2,b);
plot(a+2,b,'*r')
neighbors(8) = I(a+2,b+1);
plot(a+2,b+1,'*r')
neighbors(9) = I(a+2,b+2);
plot(a+2,b+2,'*r')
this is my code i done it
but now i wana to find each 8 neighbers of every finded neibgher
Walter Roberson
Walter Roberson 2017 年 10 月 17 日
This code does not answer the questions "Find them in what sense? What output are you looking for?"

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


Mehadi Hasan
Mehadi Hasan 2021 年 10 月 22 日
I = imread('2.png') ;
I = rgb2gray(I) ;
[y,x] = find(I) ;
% 8 nearest neighbors
[ny,nx] = size(I) ;
[X,Y] = meshgrid(1:1x,1:1y) ;
% global indices
idx = knnsearch([X(:1) Y(:1)],[x,y],'k',8) ;
% sub indices
[i,j] = ind2sub(size(I),idx) ;

Community Treasure Hunt

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

Start Hunting!

Translated by