How to label shape

3 ビュー (過去 30 日間)
amirul
amirul 2014 年 4 月 10 日
コメント済み: amirul 2014 年 4 月 11 日
if true
% code
endS = imread('test.jpg');
S = im2bw(S);
S2 = ~S;
imshow(S2);
S3 = bwlabel(S2);
imagesc(S3);
S4 = regionprops(S3,'MinorAxisLength','MajorAxisLength','Area','Perimeter','centroid');
for cnt = 1:length(S4)
score1(cnt) = abs(1-(S4(cnt).MajorAxisLength-S4(cnt).MinorAxisLength)...
/max([S4(cnt).MajorAxisLength,S4(cnt).MinorAxisLength]));
score2(cnt) = abs(1 - abs(pi*((mean([S4(cnt).MajorAxisLength,...
S4(cnt).MinorAxisLength]))/2)^2-S4(cnt).Area)/S4(cnt).Area);
score3(cnt) = abs(1 - abs(pi*(max([S4(cnt).MajorAxisLength,...
S4(cnt).MinorAxisLength]))-S4(cnt).Perimeter)/S4(cnt).Perimeter);
end
score = mean([score1;score2;score3]);
imshow(S2)
for cnt = 1:length(S4)
text(S4(cnt).Centroid(1),S4(cnt).Centroid(2),num2str(score(cnt)),'color','red');
end
how to label the output result, if the score is higher than 0.92, then the object will have label circle. i try using if-else statement, but couldnt get it work.can someone help me.thank you
  1 件のコメント
Image Analyst
Image Analyst 2014 年 4 月 11 日
You forgot to attach test.jpg. Do that and we can run your code. Also explain what "the object will have label circle" means. Do you mean you want to plot a circle in the overlay surrounding the object, or perhaps a small circle right at the centroid. And what is being computer in that long formula for score1, scroe2, and score3? Why are there no comments whatsoever in this code? ANd why is it not properly indented so that we can read it? Did you know you can type control-a and then control-i in MATLAB to fix your indenting. Then paste into the editor window here and highlight it. THEN (not before) is when you click the {}Code button. Please fix. http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2014 年 4 月 11 日
% Label regions.
labeledImage = bwlabel(binaryImage);
% Measure regions.
measurements = regionprops(labeledImage, 'area', 'perimeter');
% Convert structure fields into arrays.
allAreas = [measurements.Area];
appPerimeters = [measurements.Perimeter];
% Compute circularity. 1 = perfect circle. Higher numbers = more tortuous borders.
circularities = appPerimeters.^2 ./ (4*pi*allAreas);
% Find indexes of regions that are fairly circular.
indexesOfCircular = find(circularities < 4);
labeledImage = bwlabel(binaryImage);
% Measure regions.
measurements = regionprops(labeledImage, 'area', 'perimeter');
% Extract only the circular images from the labeled image and then binarize.
circleObjects = ismember(labeledImage , indexesOfCircular) > 0
% Can relabel and measure only circular blobs if you want.
Look into the code for a fully commented image segmentation tutorial.
  1 件のコメント
amirul
amirul 2014 年 4 月 11 日
S = imread('test.jpg');
S = rgb2gray ( S);
bw = edge ( S, 'sobel');
bw = bwareaopen(bw,30);
se = strel('disk',2);
bw = imclose(bw,se);
bw = imfill(bw,'holes');
imshow(S2);
S3 = bwlabel(bw);
S4 = regionprops(S3,'MinorAxisLength','MajorAxisLength','Area','Perimeter','centroid');
for cnt = 1:length(S4)
score1(cnt) = abs(1-(S4(cnt).MajorAxisLength-S4(cnt).MinorAxisLength)/max([S4(cnt).MajorAxisLength,S4(cnt).MinorAxisLength]));
% for score 1, it basically test the roundness of the object
score2(cnt) = abs(1 - abs(pi*((mean([S4(cnt).MajorAxisLength,S4(cnt).MinorAxisLength]))/2)^2-S4(cnt).Area)/S4(cnt).Area);
% for score 2 , it will test the ratio of area and the roundness
score3(cnt) = abs(1 - abs(pi*(max([S4(cnt).MajorAxisLength,S4(cnt).MinorAxisLength]))-S4(cnt).Perimeter)/S4(cnt).Perimeter);
% for score 3, it will test and give ratio of roundness and perimeter
end
score = mean([score1;score2;score3]);
% then all the 3 score will be mean to find the score.
%This score will be used to find the presence of circle object in image.
% Circle object will have certain value of score ( in this case 0.97)
imshow(S2)
for cnt = 1:length(S4)
text(S4(cnt).Centroid(1),S4(cnt).Centroid(2),num2str(score(cnt)),'color','red');
end
% so ryte now im replacing the above code with below code , but it doesnt work, it should have
% label with name circle on it, but it doesnt work, it can run, but the
% there is no output
%for cnt = 1:length(S4)
% if score > 0.95
%text(S4(cnt).Centroid(1),S4(cnt).Centroid(2),num2str( 'Circle' ),'color','red');
%else
%text(S4(cnt).Centroid(1),S4(cnt).Centroid(2),num2str( 'Not Circle'),'color','red');
%end
% end
if true
% code
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by