How to achieve 4 neighbouring connectivity in matlab ?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
see the code for detail
this code is not working as it is intended to do so why ?
mat = imread('nf.jpg')
gray = mat(1:200,1:200,2) % gray scale image extracted
max(gray(:))
ans=
253
% need to check N4 connectivity through pixel value p to q
p = 200
q = 100
V = [100 200 300 250 50]
cc = bwconncomp(gray,4)
for i=1:cc.NumObjects
pix = cc.PixelIdxList{i}
if any(ismember(pix(:), p)) && any(ismember(pix(:), q)) && any(ismember(V(:), p)) && any(ismember(V(:), q))
display('found N4 connectivity')
end
Risposte (1)
Image Analyst
il 20 Mar 2016
What is "N4 connectivity"? bwconncomp() is supposed to work on a binary image. You're passing it a gray level image and I don't recall what it does if you pass it the wrong kind of image like that. Why are you passing it a gray scale image???
If you simply want to see if pixel1 is in the same blob as pixel2 you can simply label the blob
labeledImage = bwlabel(binaryImage);
if labeledImage(row1, column1) == labeledImage(row2, column2)
% They are in the same blob, and can be connected by an unbroken path.
else
% They are NOT in the same blob, and cannot be connected by an unbroken path.
end
2 Commenti
Image Analyst
il 20 Mar 2016
I think he's just picked his own unnecessarily complicated notation. I haven't seen anyone make it that complicated before and use notation and wording like he did.
Basically it's like I said, you can determine if two pixels are 4 or 8-connected by calling bwlabel and seeing if the labeled image values are the same for each point. It's as simple as that. And I gave you code for it already.
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!