- Download the image
- Convert the image to grayscale
- Complement the image so that the pixels corresponding to the circles are white
- Find the connected components (white pixels) in the image
Count dark pixels along a vector in an image
1 次查看(过去 30 天)
显示 更早的评论
Hi there,
I am trying to count the rings in a picture like this: https://i.imgur.com/1Rf5lLm.png
This should represent the rings of a tree so in the final product the rings will not be as perfect circles as those are.
My ideas was to start at the center (I have a method to give me the center of the rings) and go along a vector and counting the number of times the image changes from black to white. Repeating that for many angles and taking a median it should give me a close aproximation of the number of rings.
I just don't know how to implement that - is there a method in matlab to define a vector in an image and loop over it's values?
Or do you have a better idea how to achieve my goal?
Thanks in advance for your help!
0 个评论
回答(1 个)
Yash Ubale
2018-11-12
编辑:Yash Ubale
2018-11-12
Hello,
I have a better solution as shown below which you can try.
>> I = imread('https://i.imgur.com/1Rf5lLm.png');
>> [L,n] = bwlabel(imcomplement(rgb2gray(I)));
Explanation of the above code :
If you find connected components without complementing the image it will show that there is only one connected component.
Here 'n' will show the number of rings in the image and 'L' is the visualization of the connected components.
For the image that you attached I get 'n' as 7 and 'L' as shown below.
The problem with your solution is that, you may miss some circles since a vector from the center may not intersect all of them.
For more details on connected components please visit the link mentioned below.
Label connected components in 2-D binary image - https://www.mathworks.com/help/images/ref/bwlabel.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!