Particle size distribution using image processing in MATLAB
73 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
amrutha Priya
el 3 de Mzo. de 2013
Comentada: Image Analyst
el 2 de Mayo de 2024
I want to plot the number of fat cells in the liver versus their size. For which I wanted to use the following steps.
- Apply adaptive thresholding on the gray level image.
- Find distance transform on the thresholded image.
- Invert the distance transform and assign a high value to the background.
- Extract marker using gray scale reconstruction and assign zero value to marker.
- Apply watershed transformation on the marker embedded inverted distance image to obtain the segmented image.
- Use gray scale reconstruction to find radius of each droplet and subsequently calculate area of each labelled droplet.
In step 3 how do I assign a high value to the background and can you help me with step 4?
8 comentarios
Image Analyst
el 3 de Mzo. de 2013
I don't have time to write or debug it for you. But I did download your image and looked at its color channels and noticed that you'll get a lot better contract just using the green channel than using rgb2gray() because the red and blue channels are practically worthless and you don't want them to ruin your gray scale image.
Respuesta aceptada
Image Analyst
el 4 de Mzo. de 2013
After you process everything and get to a binary image where you have distinct, separate blobs, you call bwlabel, and call regionprops, like this (untested):
labeledImage = bwlabel(binaryImage)
measurements = regionprops(labeledImage, 'EquivDiameter');
allDiameters = [measurements.EquivDiameter];
numberOfBins = 50; % Or whatever you want.
[diamDistribution binDiameters] = hist(allDiameters, numberOfBins);
bar(binDiameters, diamDistribution, 'BarWidth', 1.0);
7 comentarios
Image Analyst
el 13 de Dic. de 2020
Not quite sure what you're saying but yes, some particle may overlap when you lay them down, and depending on the width of the histogram bins, different ECDs may be in the same bin.
Here is the full code with your code incorporated plus some improvements.
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
% Create image of specified spot sizes at random locations.
xMax = 2592;
yMax = 1944;
Arr = zeros(yMax,xMax,'logical'); % test Array
R = [1; 3; 7; 10]; % "radius" of test particles
nR = [200; 100; 50; 10]; % number of test particles
totalParticleCount = 0;
for r = 1:length(R) % radius
xx = randi(xMax,nR(r));
xx = xx(1,:);
yy = randi(yMax,nR(r));
yy = yy(:,1);
for i = 1:nR(r)
% Make sure x and y are within the borders and not 0.
xx(i) = min([xMax-R(r), xx(i)]);
xx(i) = max([R(r)+1, xx(i)]);
yy(i) = min([yMax-R(r), yy(i)]);
yy(i) = max([R(r)+1, yy(i)]);
Arr(yy(i)-R(r):yy(i)+R(r),xx(i)-R(r):xx(i)+R(r)) = true;
% Log that we've added a particle. Particle may overlap existing particles though.
totalParticleCount = totalParticleCount + 1;
end % of for i = 1:nR(r)
end % of for r = 1:length(R)
subplot(1, 2, 1);
imshow(Arr, []);
drawnow;
axis('on', 'image');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized','OuterPosition',[0 0 1 1]);
% Particle analysis
% Ask user for one integer number.
defaultValue = 50;
titleBar = 'Enter an integer value';
userPrompt = 'Enter the integer';
dialogBoxWidth = 100;
caUserInput = inputdlg(userPrompt, titleBar, [1, dialogBoxWidth], {num2str(defaultValue)});
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Round to nearest integer in case they entered a floating point number.
numberOfBins = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(numberOfBins)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
numberOfBins = defaultValue;
message = sprintf('I said it had to be an integer.\nTry replacing the user.\nI will use %d and continue.', numberOfBins);
uiwait(warndlg(message));
end
binaryImage = Arr;
labeledImage = bwlabel(binaryImage);
fprintf('Measuring particles.\n');
measurements = regionprops(labeledImage, 'EquivDiameter');
numParticles = length(measurements);
fprintf('Found %d particles from the %d that we laid down.\n', numParticles, totalParticleCount);
if numParticles == totalParticleCount
caption = sprintf('%d particles from %d laid down randomly (none overlap)', numParticles, totalParticleCount);
else
caption = sprintf('%d particles from %d laid down randomly (some overlap)', numParticles, totalParticleCount);
end
title(caption, 'FontSize', fontSize);
allDiameters = [measurements.EquivDiameter];
subplot(1, 2, 2);
histObject = histogram(allDiameters, numberOfBins)
diamDistribution = histObject.Values;
binWidth = histObject.BinEdges(2) - histObject.BinEdges(1);
% Get a number that is the center value of the bin instead of the left edge.
binDiameters = histObject.BinEdges(1:end-1) + binWidth/2;
bar(binDiameters, diamDistribution, 'BarWidth', 1.0);
% Put labels atop the bars
for k = 1 : length(diamDistribution)
x = binDiameters(k);
y = diamDistribution(k) + 2;
if diamDistribution(k) > 0
caption = sprintf('%d particles\nECD = %.2f', y, x);
text(x, y, caption, 'FontWeight', 'bold', 'FontSize', 15, 'Color', 'r', 'HorizontalAlignment', 'center');
% Report how many particles are in this bin
fprintf('The bin at %6.2f has %5d particles in it.\n', x, diamDistribution(k));
end
end
fprintf('Found %d particles from the %d that we laid down.\n', numParticles, totalParticleCount);
if numParticles ~= totalParticleCount
fprintf('Meaning that some overlapped when we laid them down.\n');
end
title('Histogram of Equivalent Diameters in Pixels', 'FontSize', fontSize);
xlabel('Equivalent Diameter in Pixels', 'FontSize', fontSize);
ylabel('Count (# of particles)', 'FontSize', fontSize);
grid on;
fprintf('Done running %s.m ...\n', mfilename);
The bin at 3.42 has 197 particles in it.
The bin at 4.77 has 1 particles in it.
The bin at 7.91 has 99 particles in it.
The bin at 16.89 has 49 particles in it.
The bin at 23.63 has 8 particles in it.
The bin at 24.08 has 1 particles in it.
The bin at 25.43 has 1 particles in it.
Found 356 particles from the 360 that we laid down.
Meaning that some overlapped when we laid them down.
Image Analyst
el 2 de Mayo de 2024
Yes, I answered you below in
Maybe you forgot you posted there. Please start your own discussion thread rather than posting comments in several different places in an 11 year old thread.
Más respuestas (2)
khaled soliman
el 10 de Jul. de 2021
Dear ImageAnalyst,
I want to determine the particular size of spray droplets which is attached
9 comentarios
Image Analyst
el 1 de Mayo de 2024
Everything is in pixels. You need to know how many nm per pixel and then multiply the diameter in pixels by the number of nm/pixel.
diameterInNm = diameterInPixels * nmPerPixel; % Pixels cancel out and you're left with units of nm.
See attached demo.
Image Analyst
el 2 de Mayo de 2024
@Aditya Sai Deepak please start your own discussion thread so we don't keep bugging @amrutha Priya with emails of activity on this thread. Attach your code and a couple of images, zipped up.
There I can help you if changing this
baseFileName = TifFiles(k).name;
to this
baseFileName = theFiles(k).name;
does not work.
Maria Luisa Muñoz Leon
el 23 de Abr. de 2023
Hi
Can you give the name of the dataset please ?
2 comentarios
Image Analyst
el 23 de Abr. de 2023
What do you mean by dataset? The image that the original poster was using was attached to the original post. Just download it.
DGM
el 23 de Abr. de 2023
Or you can look at the link that's next to the attached image in order to find the source.
Histological patterns in drug-induced liver disease
Ver también
Categorías
Más información sobre Image Segmentation and Analysis en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!