I want to find mean dispersion of the white particles from an image using the formula given in the figure attached with this question.
Show older comments
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)
Image Analyst
on 31 May 2022
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
AASHNA SUNEJA
on 31 May 2022
Image Analyst
on 31 May 2022
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!'));

AASHNA SUNEJA
on 6 Jul 2022
Edited: Image Analyst
on 7 Jul 2022
Image Analyst
on 7 Jul 2022
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?
AASHNA SUNEJA
on 7 Jul 2022
Image Analyst
on 7 Jul 2022
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));
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!