フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by