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

조회 수: 13 (최근 30일)
Explorer
Explorer 2014년 2월 11일
편집: Ljubica Kovacevic 2017년 7월 28일
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에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by