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

 Akzeptierte Antwort

Image Analyst
Image Analyst am 9 Apr. 2014

0 Stimmen

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 Kommentare

tnx,
That method definitely works. However, I do need to find the center of each of the disks because this image actually shows the cross sectional view of "fibers" (which is like a disk) within a composite and I need to investigate the distribution of the fibers in the third dimension(into the plane). In other words, I have several pictures (like this) which are taken from a 3D structure in different cross sections. To investigate the distribution, I want to simplify the problem by replacing each fiber with its center line (I am assuming that all the fibers have approximately the same radius and that the radius remains constant in the third dimension). Once I have the centers (corresponding to each fiber), I can fit a Spline to them to find the center line.
I wanted to use this code for "Filtering, adjusting (the contrast), and binarizing" the image and then using the "regionprops" command but I cannot get it to work this time:
background = medfilt2( Image, [20, 20] );
Image = double(Image) - double(background);
[~, Image] = transform(Image, 1-VF); %VF=Volume Fraction
Image = Image/255; %1=fiber
-------------------------------
function [iThreshold, BinaryImage] = transform(filepath, VF)
% Transform the grey images to binary images
% Input: filepath - a path of the grey *.tif SEM image OR
% a matrix with 0-255 grey level
% VF - volume fraction of the composite
% Output: iThreshold - threshold used to convert the image
% BinaryImage - the binary image
if ischar(filepath)
Img = imread(filepath);
else
Img = 255-filepath;
end
Img = medfilt2(Img);
[row col] = size(Img);
TotalNopixel = row*col;
ThresholdPixelNo = ceil(TotalNopixel*VF);
ranking = sort(Img(:),'descend');
iThreshold = ranking(ThresholdPixelNo);
BinaryImage = zeros(row,col);
for i=1:row
for j=1:col
if Img(i,j)>=iThreshold
BinaryImage(i,j) = 0;
else
BinaryImage(i,j) = 255;
end
end
end
% BinaryImage = uint8(BinaryImage);
% BinaryImage = double(BinaryImage);
% BinaryImage = abs(BinaryImage-255);
-----------------------------------------------
Thanks again,
Sincerely Yours'
Ramin
Image Analyst
Image Analyst am 10 Apr. 2014
Then use bwulterode() like I previously suggested.
ramin bba
ramin bba am 10 Apr. 2014
Tnx, but what exactly does that show? 'cause some of the points are definitely not the centers! even if you run the example in MATLAB documentation, you will see this! I can eliminate the points that are not the centers by setting a constraint (i.e. min distance between two points) but this will surely eliminate a lot of the centers (this is not the case for the example in the documentation though since there is not a lot of disks there).
here is what I did: Used "imageJ" to convert the image (which is RGB color) to 8 uint (with one layer). Then, used im2bw to convert it to a binary image (set the level to get the desired surface fraction). Finally. used bwulterode!
Thanks a lot,
Regards,
Image Analyst
Image Analyst am 11 Apr. 2014
If marker controlled watershed segmentation works, then why not use it? What do you mean by "However, I do need to find the centers"? So go ahead. Just threshold, label, and call regionprops. What's wrong with that? Why do you say "however" as if you're somehow prevented from finding the centers because you split apart the blobs???
ramin bba
ramin bba am 11 Apr. 2014
Tnx for following up.
My original question is incomplete and misleading. I said "however" because in your first answer you suggested a way that can only give me the number of blobs (which based on my question was correct) but I need to know both "the location of the center of the disks" (for my analysis) and "the number of disks" (since I might not find all the locations, I can figure out how many centers I have missed by comparing "the number of centers" I have found and "the number of disks", the latter can be found via the method u described at first).
I have not tried "marker controlled watershed segmentation" yet but I will give that a try shortly.
I used "graythresh" to find the "level" for im2bw but I lowered the level in order to separate the disks. Makes the situation better but still regionprops does not work quite well. here is what I get after im2bw(I,Level):
In addition, would u mind telling me what you mean by labeling in "Just threshold, label, and call regionprops"?
Bests, Ramin
See my image segmentation tutorial in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Basically it's
thresholdValue = 100;
binaryImage = originalImage > thresholdValue; % Bright objects will be the chosen if you use >.
labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
blobMeasurements = regionprops(labeledImage, originalImage, 'all');
ramin bba
ramin bba am 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 am 12 Apr. 2014
Bearbeitet: ramin bba am 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,

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by