How to write object connectivity code?
Mostrar comentarios más antiguos
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 ?
Respuestas (1)
Image Analyst
el 8 de Ag. de 2014
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 comentarios
Image Analyst
el 8 de Ag. de 2014
Not sure how you define "my own code". I see nothing wrong with using regionprops() and that's not your own code. Likewise if you look over my example and adapt it, it will be at least somewhat your own code, depending on how much you adapt it. Are you saying now that you actually don't want any help because if you got it, you would not be able to use it?
Image Analyst
el 9 de Ag. de 2014
You can try to edit the function
>> edit bwconncomp.m
but usually that just shows some of the code in a wrapper and much of the code is hidden in a DLL. If you have to use all open source code, then you'll have to write it in some other language, like C++ and the OpenCV library.
tabw
el 9 de Ag. de 2014
Image Analyst
el 9 de Ag. de 2014
Looks like it. You'll have to change them. New in R2014a (I believe) is that you can use %{ and %} to enclose large blocks:
%{
This line is commented out
So is this line.
%}
Image Analyst
el 10 de Ag. de 2014
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().
Categorías
Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!