How do I calculate the spreading length of an image of a droplet spreading and find the ROI and automate the process
7 views (last 30 days)
Show older comments
I have a series of images of droplet impacting on another droplet. The images are in RGB color and I converted to grayscale and binarizeid it. Now from the code (using 'ginput') given below I could calculate the pixel distance from end to end of the horizontal spreading part. But I have a series (50 images) of images where the spread length is changing continously. Hence I need to identify a ROI and from that calculate the spreading distance automatically. How do I do so? Does 'ginput' give the pixel distance accurately after pointing and clicking on the two extremeties of white zone in the binary image?
clc;clear;
folder = 'C:\Users\Pragyan\Documents\MATLAB\Image processing';
baseFileName = '0.25_cmc_2mm_8_bit.jpg';
fullFileName = fullfile(folder, baseFileName);
[grayImage,map] = imread(fullFileName);
%impixelinfo;
grayImage = rgb2gray(grayImage);
imshow(grayImage,map)
binaryImage = ~imbinarize(grayImage);
imshow(binaryImage)
[x y]=ginput(6);
x=round(x);
y=round(y);
image_dist=sqrt((x(2)^2-x(1)^2)+y(2)^2-y(1)^2)
3 Comments
Image Analyst
on 10 Jun 2021
You're replying to KSSV's comment. Did you even see or try my Answer below? I believe it works.
Accepted Answer
Image Analyst
on 9 Jun 2021
Edited: Image Analyst
on 10 Jun 2021
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 18;
folder = 'C:\Users\Pragyan\Documents\MATLAB\Image processing';
baseFileName = '0.25_cmc_2mm_8_bit.jpg';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~isfile(fullFileName)
% 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
fullFileName = fullFileNameOnSearchPath;
end
[grayImage,map] = imread(fullFileName);
grayImage = rgb2gray(grayImage);
imshow(grayImage,map)
binaryImage = ~imbinarize(grayImage);
% Erase from line 758 down:
binaryImage(758:end, :) = false;
% Fill holes.
binaryImage = imfill(binaryImage, 'holes');
% Get rid of any msall noise blobs.
binaryImage = bwareafilt(binaryImage, 1); % Take largest blob only.
imshow(binaryImage)
impixelinfo;
props = regionprops(binaryImage, 'BoundingBox');
spreadingWidth = props.BoundingBox(3)
rectangle('Position', props.BoundingBox, 'Edgecolor', 'g', 'LineWidth', 2)
fprintf('Done running %s.m ...\n', mfilename);
If it doesn't work, let me know what went wrong.
4 Comments
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox 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!