在图像中查找笔记 [英] Finding notes in an image
问题描述
我有这样的图像。我想找到笔记的位置。找到它们的最佳方法是什么? (它们不是圆圈,它们太小,所以circlefinder找不到它们!)
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 !)
推荐答案
这里有一些代码可以帮到你......这不是很完美,但它只是一个有趣的哈哈。
Here is a bit of code to get you going...that's not perfect but it was a lof of fun haha.
我所做的是用磁盘结构元素侵蚀图像,直到图像中剩下的内容为止形状看起来最像圆圈。然后我再次受到侵蚀,但这次是一个线条结构元素,其角度接近音符的角度;我认为它大约是15度。
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.
之后,调用 regionprops
来获取质心,然后绘制它们。
After that, call regionprops
to get the centroids, and then plot them.
代码:
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);
此处 erodedBW
如下所示:
%// 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
看起来像这样:
然后找到质心并绘制它们
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
输出:
没有检测到空白笔记,但我认为可以使用其他形态学操作进行管理。
Empty notes are not detected but that's manageable using other morphological operations I guess.
希望有帮助!
这篇关于在图像中查找笔记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!