I want to find mean dispersion of the white particles from an image using the formula given in the figure attached with this question.

I want to find the mean dispersion of the white particles from an image using the formula given with this question. I am also attaching the figure from which mean dispersion is to be estimated. Further I want to do the curve fitting with the data obtained for the mean dispersion. Also attaching the figure to be obtained for mean dispersion. I could not get some clue how to proceed with this.

Answers (1)

First find a mask for the pile of particles. Several ways to do that - shouldn't be hard.
Then I'd use a classification routine like discriminant analysis or kmeans to classify every pixel in the image into one of the main colors. Then take the brightest cluster, which will be white. Or try using the Color Thresholder app on the Apps tab of the tool ribbon. Demos attached.
So now you have a mask of all the white pixels. Then just scan across getting the RMS distance
[rows, columns] = size(mask);
D = zeros(1, columns);
for col = 1 : columns
thisColumn = mask(:, col);
yValues = find(thisColumn);
meanY = mean(yValues);
D(col) = sqrt(mean((yValues - meanY) .^ 2))
end

6 Comments

Thank you for the reply but can you please elaborate a little that how to proceed with the suggestions given by you. Actually i have been trying to identify the location of the white particles using an image analysis software ImageJ. Please help me out with MATLAB that how it could be done. I could not understand the answer given by you this masking and all.
Well I don't have time to write the whole app for you but here is the code to find the pile of particles:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'bump.jpg';
folder = pwd;
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Crop off screenshot stuff
% rgbImage = rgbImage(132:938, 352:1566, :);
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Take one of the color channels, whichever one seems to have more contrast..
grayImage = rgb2gray(rgbImage);
% Display the color segmentation mask image.
subplot(2, 2, 2);
imshow(grayImage, []);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
%=======================================================================================
% Show the histogram
subplot(2, 2, 3);
imhist(grayImage);
grid on;
caption = sprintf('Histogram of Gray Scale Image')
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize)
ylabel('Count', 'FontSize', fontSize)
%=======================================================================================
% Threshold the image to get the disk.
lowThreshold = 150;
highThreshold = 255;
% Use interactive File Exchange utility by Image Analyst to to the interactive thresholding.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(114, 255, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
xline(lowThreshold, 'Color', 'r', 'LineWidth',2);
xline(highThreshold, 'Color', 'r', 'LineWidth',2);
% Now do clean up by hole filling, and getting rid of small blobs.
mask = bwareafilt(mask, 1); % Take largest blob only.
% Fill the mask from the top most pixel downwards in the column.
for col = 1 : columns
topRow = find(mask(:, col), 1, 'first');
if ~isempty(topRow)
mask(topRow:end, col) = true;
end
end
% Display the color segmentation mask image.
subplot(2, 2, 4);
imshow(mask, []);
title('Final Mask', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
uiwait(helpdlg('Done!'));
Thank you for the help.
I have been partially able to do which I wish to do, but the following issues still needed to be resolved given in the order
  1. How to scale the image to the X Limits( 0 to 300) and Y Limits (0 to 35)
  2. How to do curve fitting for the data points obtained from the code
The code is attached from which the mean dispersion is estimated.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'bump.jpg';
folder = pwd;
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Crop off screenshot stuff
% rgbImage = rgbImage(132:938, 352:1566, :);
% Display image.
subplot(2, 2, 1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
% Take one of the color channels, whichever one seems to have more contrast..
grayImage = rgb2gray(rgbImage);
% Display the color segmentation mask image.
subplot(2, 2, 2);
imshow(grayImage, []);
title('Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
% Show the histogram
subplot(2, 2, 3);
imhist(grayImage);
grid on;
caption = sprintf('Histogram of Gray Scale Image')
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize)
ylabel('Count', 'FontSize', fontSize)
%=======================================================================================
% Threshold the image to get the disk.
lowThreshold = 205;
highThreshold = 255;
% Use interactive File Exchange utility by Image Analyst to to the interactive thresholding.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
% [lowThreshold, highThreshold] = threshold(114, 255, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
xline(lowThreshold, 'Color', 'r', 'LineWidth',2);
xline(highThreshold, 'Color', 'r', 'LineWidth',2);
% Now do clean up by hole filling, and getting rid of small blobs.
%mask = bwareafilt(mask, 1); % Take largest blob only.
% Fill the mask from the top most pixel downwards in the column.
% for col = 1 : columns
% topRow = find(mask(:, col), 1, 'first');
% if ~isempty(topRow)
% mask(topRow:end, col) = true;
% end
% end
% Display the color segmentation mask image.
subplot(2, 2, 4);
imshow(mask, []);
title('Final Mask', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
axis('on', 'image');
drawnow;
% [y1,x1]=find(mask==1);
% miny1=min(y1);
% maxy1=max(y1);
% scanint=1;
% save_mat=[];
% currentvaly=min(y1)
% for i1=1:(maxy1-miny1+1)
% yloc=find(y1==currentvaly)
% ynow=currentvaly;
% xnow=zeros(length(yloc),1);
% for j1=1:length(yloc)
% xnow(j1)=x1(yloc(j1));
% end
% summ=0;
% xavg=mean(xnow);
% for j1=1:length(yloc)
% summ=(xavg-xnow(j1))^2;
% end
% Dispersion1=sqrt((1/length(yloc))*summ);
% savedata=[ynow,Dispersion1];
% save_mat=[save_mat; savedata];
%
%
%
% currentvaly=currentvaly+1;
% end
[y1,x1]=find(mask==1);
minx1=min(x1);
maxx1=max(x1);
scanint=1;
save_mat=[];
currentvalx=min(x1)
for i1=1:(maxx1-minx1+1)
xloc=find(x1==currentvalx)
xnow=currentvalx;
ynow=zeros(length(xloc),1);
for j1=1:length(xloc)
ynow(j1)=y1(xloc(j1));
end
summ=0;
yavg=mean(ynow);
for j1=1:length(xloc)
summ=(yavg-ynow(j1))^2;
end
Dispersion1=sqrt((1/length(xloc))*summ);
savedata=[xnow,Dispersion1];
save_mat=[save_mat; savedata];
currentvalx=currentvalx+1;
end
figure;
plot(save_mat(:,1),save_mat(:,2),'k.')
uiwait(helpdlg('Done!'));
figure;
plot(y1,x1,'k.')
I wish to make a plot something of this sort as attached with this question.
Thank in advance.
How to scale the image to the X Limits( 0 to 300) and Y Limits (0 to 35)
imshow(yourImage, 'XData', [0, 300], 'YData', [0, 35]);
"How to do curve fitting for the data points obtained from the code?" Attach 'bump.jpg' so we can see what you see. What variable do you want to fit a curve to and what equation of the curve do you want to use?
Want to find the dispersion of the white particles using the formula attached with this comment.
Which of your variables do you consider to be y? After that the formula is simple.
D = sqrt(sum((y - mean(y)).^2)/numel(y));

Sign in to comment.

Categories

Asked:

on 31 May 2022

Commented:

on 7 Jul 2022

Community Treasure Hunt

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

Start Hunting!