get the x,y coordinate of the boundaries of the entities in the attached image. I have written the code to do so but still not able to get the co-ordinate because not able to get the continuous curve.
4 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171541/image.jpeg)
blood = imread('boundaries.jpg');
[x,y]=size(blood);
b=double(blood);
N =sqrt(100) * randn(x,y);
I=b+N;
for i=1:x
for j=1:y
if (I(i,j)>255)
I(i,j)=255;
end
if (I(i,j)<0)
I(i,j)=0;
end
end
end
z0=max(max(I));
z1=min(min(I));
T=(z0+z1)/2;
TT=0;
S0=0; n0=0;
S1=0; n1=0;
allow=0.5;
d=abs(T-TT);
count=0;
while(d>=allow)
count=count+1;
for i=1:x
for j=1:y
if (I(i,j)>=T)
S0=S0+I(i,j);
n0=n0+1;
end
if (I(i,j)<T)
S1=S1+I(i,j);
n1=n1+1;
end
end
end
T0=S0/n0;
T1=S1/n1;
TT=(T0+T1)/2;
d=abs(T-TT);
T=TT;
end
Seg=zeros(x,y);
for i=1:x
for j=1:y
if(I(i,j)>=T)
Seg(i,j)=1;
end
end
end
SI=1-Seg;
se1=strel('square',3);
SI1=imerode(SI,se1);
BW=SI-SI1;
I=uint8(I);
figure(1);
imshow(BW);title('New algorithm')
1 Comment
Image Analyst
on 8 Apr 2018
That code is not good. Like I said below, use bwboundaries. Simple extract the green channel, threshold, and call bwboundaries. If you want the boundaries as an image instead of an N-by-2 list of (x,y) coordinates, then call bwperim(). But don't do it the way you did.
Answers (1)
Image Analyst
on 25 Mar 2018
Simply use bwboundaries(). See this code snippet from my Image Processing Tutorial in my File Exchange:
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries.
subplot(3, 3, 6);
imshow(originalImage);
title('Outlines, from bwboundaries()', 'FontSize', captionFontSize);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!