How to find signature of the object for the given binary image?
조회 수: 13 (최근 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
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
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
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
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!