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 CenterFile Exchange에서 Image 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