Calculate average size of circles in jpg

4 visualizzazioni (ultimi 30 giorni)
Ivan Volodin
Ivan Volodin il 21 Ott 2018
Commentato: YT il 22 Ott 2018

Hello!

I have pretty standart task to calculate average size of circles on variety of jpg files. So the whole application would have structure like this:

for-loop (from first image to the last)
turn rgb image to binary one;
calculate average raw of bubbles;
end-loop

I have done common structure but starting stumbling on the step where I suppose to calculate size (see image). There is standard function regionprops() to find objects properties, but actually I do not understand what this function returns and even more I cannot execute example "Estimate Center and Radii of Circular Objects and Plot Circles" on this page: https://www.mathworks.com/help/images/image-processing-on-a-gpu.html because as far as I understand

   regionprops('table',bw,'Centroid',...
      'MajorAxisLength','MinorAxisLength')

need a scalar as an input, which I concluded from this error I am getting during execution:

Expected input number 1, L, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was char.

My image is

which is binary one, I have plenty of files like that which differ from each other by average size of black bubble and my question is how to calculate average size of bubbles..?

Is there a simple way to calculate size of every bubble on my picture..?

Thank you in advance!

  6 Commenti
Bruno Luong
Bruno Luong il 21 Ott 2018
Get also 'MaxIntensity'
Ivan Volodin
Ivan Volodin il 21 Ott 2018
Modificato: Ivan Volodin il 21 Ott 2018
In the same line, in the same command or somehow separately ? How to do that? Like this
z = regionprops('table',I,'ConvexArea',...,
'MaxIntensity')
or how?

Accedi per commentare.

Risposte (1)

YT
YT il 21 Ott 2018
"Is there a simple way to calculate size of every bubble on my picture..?"
Using the image you provided, I came up with the following solution (NOTE: this requires Image Processing Toolbox):
%read & resize the image to detect smaller circles later
factor = 2;
A = imresize(im2bw(imread('s.png')),factor);
%display image
imshow(A)
%radii of possible circles (this is why resized the image because you cannot use floats)
r = [1 30];
%find circles
[centersDark, radiiDark] = imfindcircles(A,r,'ObjectPolarity','dark');
%display circles
viscircles(centersDark, radiiDark,'Color','b');
So now you got the radii of the circles you detected in the image but you resized the image remember, so you have to take that factor in consideration so (atleast thats how I was thinking; this is the first time doing this myself):
radiiDark = radiiDark / factor;
Now you got the 'real' radius of every circle it found in pixels. I don't really know what you meant to calculate the "size" of every bubble, but I think this answers the main issue. You can do things like calculating the circumference or area now.
  2 Commenti
Ivan Volodin
Ivan Volodin il 22 Ott 2018
Thanks, but the problem is that I have plenty of pictures like this (around 100) and I do not know the actual average size (by size I mean diameter) of bubbles, whereas according to you suggestion I am supposed to know it.. The solution will not work out in my case
YT
YT il 22 Ott 2018
Well I didnt know the size of the bubbles either and I just tried a range of radii until I found a reasonable visual result. If all your pictures have the same size (w-by-h) and have roughly the same diameter of circles, this will work just fine. Even though I'm not very experienced in the field of image processing, this method seems to me the "simplest way" to do so. There are some functions on file exchange, but they also require a range of radii (like this one). Good luck.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by