Reputation: 21
I have an image like this. And I want to find the location of notes. What is the best way to find them ? (They are not circle and they are so small so circlefinder can't find them !)
Upvotes: 1
Views: 149
Reputation: 13945
Here is a bit of code to get you going...that's not perfect but it was a lof of fun haha.
What I did is to erode the image with a disk structuring element until what was left in the image was shapes the looked the most like circles. Then I eroded again but this time with a line structuring element oriented at an angle close to that of the notes; I figured it's about 15 degrees.
After that, call regionprops
to get the centroids, and then plot them.
Code:
clear
clc
BW = im2bw(imread('Notes.png'));
BW = imclearborder(BW);
%//Erode the image with a disk structuring element to obtain circleish
%// shapes.
se = strel('disk',2);
erodedBW = imerode(BW,se);
Here erodedBW
looks like this:
%// Erode again with a line oriented at 15 degrees (to ~ match orientation of major axis of notes...very approximate haha)
se2 = strel('line',5,15);
erodedBW2 = imerode(erodedBW,se2);
erodedBW2
looks like this:
Then find centroids and plot them
S = regionprops(erodedBW2,'Centroid');
figure;
imshow(BW)
hold on
for k = 1:numel(S)
scatter(S(k).Centroid(:,1), S(k).Centroid(:,2),60,'filled')
end
Output:
Empty notes are not detected but that's manageable using other morphological operations I guess.
Hope that helps!
Upvotes: 6