number of disks in a grey scale Image

1 view (last 30 days)
I am trying to find the number of black disks in this Image. I have tried "regionprops" but the problem is first I need to convert the Image to a binary one (without significant loss in resolution or accuracy) and then use this function. In addition, "regionprops" cannot distinguish "touching disks" quite well. I am using R2014a version.
Any help or comment would be greatly appreciated. Bests, Ramin

Accepted Answer

Image Analyst
Image Analyst on 9 Apr 2014
For an image like this, where all the blobs are very close to the same size, you simply threshold to find the entire mass and then divide by the area of a single blob. For all intents and purposes this will give you a very accurate count. There are other methods such as bwulterode() or Marker Controlled Watershed Segmentation but I think they may not be as accurate and are more complicated.
  8 Comments
ramin bba
ramin bba on 11 Apr 2014
Just took a look at the file. It is awesome! thanks a lot.
I will try to use my image as the input. Hope it works.
regards, Ramin
ramin bba
ramin bba on 12 Apr 2014
Edited: ramin bba on 13 Apr 2014
The code is great! thanks. A couple of questions (if you prefer, I can ask them at the page where I downloaded the file):
1- Is there a way to to come up with a good approximate for the threshold value? right now I do it by comparing (with my eyes) the actual image and the binary one! I added a loop in case I know the surface fraction but this might not be the case. here is how I did it:
while abs(1-sum(sum(binaryImage))/1200^2-VF)>0.01
if 1-sum(sum(binaryImage))/1200^2>VF
thresholdValue=thresholdValue-1;
binaryImage = originalImage > thresholdValue;
else
thresholdValue=thresholdValue+1;
binaryImage = originalImage > thresholdValue;
end
i=i+1
end
2- Right now, the center of the disks are not saved. In my own code, I used a for loop to save them. I wrote this code for a very simple 3D image wherein every 2D cross section (i.e. Image(:,:,i)) is like coins.png in your code. I aslos assumed that I know the number of the disks. Is there any other method to implement this in your code?
function [Centroid_f] = Centroid_finder(Image,n_of_F)
% the inputs to this function are:
% Image=a 3D binary matrix
% n_of_F= number of the fibers/disks/ cylinders in the matrix
%output is the centroids of the fibers within the matrix
Size3=size(Image);
Size=Size3(3);
Centroid_f=zeros(n_of_F,2,Size);
for k=1:Size
C=Image(:,:,k);
cc = bwconncomp(C);
s = regionprops(cc, 'PixelIdxList', 'Centroid');
% pause
for i=1:n_of_F
Centroid_f(i,:,k)=s(i).Centroid;
end
end
end
3- How can I change the code so that the input could be a 3D greyscale image? I THINK THIS IS VERY DIFFICULT! I was thinking about choosing n sections of the 3D matrix to construct n 2D images in grey scale. Then, use your code for each section. Even in this case, I might have to run this code for at least 100 times! is it a good idea to put the whole code in a "for" loop (since I will know how many sections/2D images I have) and then run it? i.e. :
for i=1:n
...
Image2D(i)=imread(['section'num2str(i),'.png']);
...
end
4- How can I keep track of the movements of the centers? i.e. let's say I move the disks in one image and create another image. Now, how can I connect the corresponding disks?
regards,

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!