So I have this image:
There are 36 objects in total and roughly 10 different ones.
Is there a method to calculate how many different objects there are?

 채택된 답변

Akira Agata
Akira Agata 2018년 7월 25일
편집: Akira Agata 2018년 7월 25일

2 개 추천

How about the following way?
% Load the image
BW = imread('bARgija.png');
% Remove small area (< 10 pixel)
BW2 = bwareaopen(BW,10);
% Obtain area and bounding box for each area
s = regionprops('table',BW2,{'Area','BoundingBox'});
% Set allowable area torelance (e.g 5 pixel)
tolPixel = 5;
% Assume same object has same area (with 5 pixel torelance)
r = tolPixel/max(s.Area);
[~,~,group] = uniquetol(s.Area,r);
% Show the result
color = jet(max(group));
figure
imshow(BW)
hold on
for kk = 1:height(s)
rectangle(...
'Position', s.BoundingBox(kk,:),...
'EdgeColor', color(group(kk),:),...
'LineWidth', 2);
end
The number of different objects can be obtained by max(group).
>> max(group)
ans =
12

댓글 수: 4

Image Analyst
Image Analyst 2018년 7월 25일
편집: Image Analyst 2018년 7월 25일
Very nice - clever. I was going to use some kind of machine learning method to figure out how many area clusters there are. I didn't know about uniquetol(). It looks like a nice function - perfect for using here.
I also learned about height() and width() from your code. However, I'm disappointed that the Mathworks chose to create a built-in functions with those names, instead of tableheight() and tablewidth() because I've often used variables with those names (height and width). I guess I'll have to change now.
João  Oliveira
João Oliveira 2018년 7월 27일
Thank you for the answer. Really apreciated.
Paolo Piazza
Paolo Piazza 2020년 3월 24일
This is really interesting, I'd have another question: is it possible to calculate how simillar/dissimilar the objects are in an image? for instance, if all objects were saws (or more less have the same shape).
Image Analyst
Image Analyst 2020년 3월 24일
편집: Image Analyst 2020년 3월 24일
What I'd probably do is to align the objects, like with imregister() or imrotate() or something, then compute the Dice Sorensen Coefficient. It's been talked about here before so look it up. Also run my attached demo on it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2018년 7월 18일

편집:

2020년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by