How do I calculate the spreading length of an image of a droplet spreading and find the ROI and automate the process
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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)
![8 bit gray image](https://www.mathworks.com/matlabcentral/answers/uploaded_files/647320/8%20bit%20gray%20image.jpeg)
![spreading length](https://www.mathworks.com/matlabcentral/answers/uploaded_files/647325/spreading%20length.jpeg)
![binary](https://www.mathworks.com/matlabcentral/answers/uploaded_files/647330/binary.jpeg)
3 Commenti
Image Analyst
il 10 Giu 2021
You're replying to KSSV's comment. Did you even see or try my Answer below? I believe it works.
Risposta accettata
Image Analyst
il 9 Giu 2021
Modificato: Image Analyst
il 10 Giu 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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/648450/image.png)
If it doesn't work, let me know what went wrong.
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Image Data Workflows in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!