Count dark pixels along a vector in an image

1 visualizzazione (ultimi 30 giorni)
Thomas Lohninger
Thomas Lohninger il 4 Nov 2018
Modificato: Yash Ubale il 12 Nov 2018
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!

Risposte (1)

Yash Ubale
Yash Ubale il 12 Nov 2018
Modificato: Yash Ubale il 12 Nov 2018
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 :
  1. Download the image
  2. Convert the image to grayscale
  3. Complement the image so that the pixels corresponding to the circles are white
  4. Find the connected components (white pixels) in the image
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

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by