How to write object connectivity code?
2 ビュー (過去 30 日間)
古いコメントを表示
Actually I am writing a code for detecting a line and its size.But I encountered some problems.
Can=im2bw(imread('Ims.png'));
[X Y]= size(Can);
result=[];
region=[];
for j= 1:Y;
i=1; % initialize the while loop
while i<299
if (i~= 1)
if (find(CellOutline(j,i)==0)) % check pixel itself is black
if (CellOutline(i-1,j) ==0)&& (CellOutline(i+1,j)==0) %check left pixel and right pixel of pixel(i) s black
region(i+1,j)=CellOutline(i+1,j); % write pixel(i+1,j) value into region
end
end
elseif (CellOutline(i,j)==0)&&(CellOutline(i+1,j)==0) %When i=1, check the forward point and point itself.
region(i,j)=CellOutline(i,j); %write the value into region.
region(i+1,j)=CellOutline(i+1,j); %\/
else
end
i=i+1;
end
end
I know lots of flaws in this code. Can this code even detect a continuous black line on binary image ?
0 件のコメント
回答 (1 件)
Image Analyst
2014 年 8 月 8 日
Not sure what that code does. To detect a black line in a gray scale image, do
blackLine = (grayImage == 0);
This actually detects all pure black pixels. You might have to filter it to find line-like region shapes. See my Image Segmentation Tutorial.
If that doesn't work for you then attach your Ims.png image so we can try your code or other code of our own.
8 件のコメント
Image Analyst
2014 年 8 月 10 日
No I don't. I'd guess that they know in advance how many slices there are.
To calculate region volumes in 3D call bwconncomp() followed by regionprops().
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!