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

5 views (last 30 days)
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 Comment
Ljubica Kovacevic
Ljubica Kovacevic on 28 Jul 2017
Edited: Ljubica Kovacevic on 28 Jul 2017
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

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 11 Feb 2014
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 Comments
Explorer
Explorer on 11 Feb 2014
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 on 11 Feb 2014
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)

Sign in to comment.

More Answers (1)

David Young
David Young on 11 Feb 2014
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.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!