How do we choose circles and rectangles?

4 ビュー (過去 30 日間)
bugrahan ilgaz
bugrahan ilgaz 2020 年 6 月 26 日
コメント済み: Image Analyst 2020 年 6 月 27 日
How do we choose circles and rectangles?
I want to determine the rectangles and circles in the picture with different colors and write numbers on them. For example, I want to see how many circles and how many rectangles there are. Can you please help with the code?

採用された回答

Image Analyst
Image Analyst 2020 年 6 月 26 日
Just call imbinarize() and bwferet().
  7 件のコメント
bugrahan ilgaz
bugrahan ilgaz 2020 年 6 月 27 日
I take this final , but how do I show biggest number ?
Image Analyst
Image Analyst 2020 年 6 月 27 日
To count them, simply count them:
numberOfCircles = 0;
numberOfRectangles = 0;
for k = 1 : length(props)
% For each blob.
x = props(k).Centroid(1);
y = props(k).Centroid(2);
blobAspectRatio = props(k).MajorAxisLength / props(k).MinorAxisLength;
fprintf('For blob #%d, the aspect ratio is %f.\n', blobAspectRatio);
if blobAspectRatio > 1.5
text(x, y, 'Rectangle', 'Color', 'r', 'FontSize', 15, 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
numberOfRectangles = numberOfRectangles + 1;
else
text(x, y, 'Circle', 'Color', 'b', 'FontSize', 15, 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
numberOfCircles = numberOfCircles + 1;
end
end
Exactly what do you mean by "how do I show biggest number"? First of all there are lots of numbers in the program. What collection of numbers are you comparing when you say "biggest"? Do you mean which count is higher, circles or rectangles? Do you mean which blob has the largest area? I have no idea - you need to be precise, not ambiguous. Secondly exactly what does "how do I show" mean??? Do you mean you want a popup message box telling the user? Do you want something printed to the command window? Do you want text overlaid on the image? Do you want it in the title above the image? Again I have no idea. Please be specific.
For your new image, I didn't see any that were missing. Where is the missing one? You say "this" one is missing but you didn't point to the one that "this" refers to. Can you point a red arrow to it? Is it a lot smaller than the rest? Because you can see where I filter away blobs less than 400 pixels -- that is well commented in the code. Was it a very tiny rectangle (smaller than 400 pixels) because that would not be counted. You can set a smaller number than 400 if you want but you don't want to get much smaller than the known smallest size of your objects or else you'll be counting noise. Also note that with this new image, the camera has shifted so that the black sliver in the lower left is no longer in this image like it was in your original image.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by