How to find signature of the object for the given binary image?

4 次查看(过去 30 天)
My binary images are like this.
______________________________________________________________________________
So far I have written some lines of code to find signature but getting error. Code and Error are shown below
______________________________________________________________________________
image = imread('C:\Users\Explorer\Desktop\aa_contour.jpg');
GRAY1 = rgb2gray(image);
threshold1 = graythresh(GRAY1);
BW1 = im2bw(GRAY1, threshold1);
stats = regionprops(BW1, 'Centroid')
c = stats.Centroid
boundary = bwboundaries(BW1);
x = boundary(:,1);
y = boundary(:,2);
distances = sqrt((x - c(1)).^2 + (y - c(2)).^2)
______________________________________________________________________________
Error
-------------------------------------------------------------------------------
stats = 2x1 struct array with fields:
Centroid
c = 173.5 1
Index exceeds matrix dimensions. Error in signature (line 17) y = boundary(:,2);
-------------------------------------------------------------------------------
Please correct the code.
  1 个评论
Ljubica Kovacevic
Ljubica Kovacevic 2017-7-28
编辑:Ljubica Kovacevic 2017-7-28
stats=regionprops(BW,'Centroid');
boundary=bwboundaries(BW);
for k=1 : length(stats)
c=stats(k).Centroid;
bound=boundary(k);
x=bound{1,1}(:,1);
y=bound{1,1}(:,2);
distances=sqrt((y-c(1)).^2+(x-c(2)).^2);
t=1:1:length(distances);
figure(k),
plot(t,distances);
end

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2014-2-11
There you basically said that there were 3 boundaries. I see two, an inner one and an outer one. I don't know what the third one is. You can probably either fill the image with imfill() and hopefully just get one, or else you can just use boundary{1} which hopefully is the outer one.
  5 个评论
Explorer
Explorer 2014-2-11
Are you asking about sizes?
>> size(boundary(1))
ans =
1 1
>> size(boundary(2))
ans =
1 1
>> size(boundary(3))
ans =
1 1
Image Analyst
Image Analyst 2014-2-11
No, that doesn't make any sense. You need to read the FAQ about cell arrays http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F Please read this. You could do this:
boundary1 = boundary{1};
size(boundary1)
boundary2 = boundary{2};
size(boundary2)
boundary3 = boundary{3};
size(boundary3)

请先登录,再进行评论。

更多回答(1 个)

David Young
David Young 2014-2-11
It would help you to look at the documentation for bwboundaries - especially look at the examples.
Your problem is that bwboundaries returns a cell array, so you need to extract the individual boundary coordinate matrices, like this:
boundary = bwboundaries(BW1);
boundary1 = boundary{1};
boundary2 = boundary{2};
Either boundary1 or boundary2 will refer to the outside of your shape, and the other will refer to the hole inside it. To work out which is which you could look at which array has the larger size, or you could use the other results of bwboundaries. Or maybe it doesn't matter which you use if you can assume the line in the image is of constant width and is thin compared to the size of the object it surrounds.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by