How do I calculate the spreading length of an image of a droplet spreading and find the ROI and automate the process

3 次查看(过去 30 天)
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 spreading length binary
  3 个评论
naygarp
naygarp 2021-6-9
using regionprops the width and height of the blob could be acquired also probably if I use for loops then the width calculation for whole sequence of images could be automated. But I am having a problem of thresholding as a few more white spots are left on the binary image as a result the blob isn't getting singled out and BoundingBox is not able to capture the region of interest. I am attaching the images.
clc;clear;
folder = 'C:\Users\Pragyan\Documents\MATLAB\Image processing';
baseFileName = '0.25 cmc 2mm with scale bar.jpg';
fullFileName = fullfile(folder, baseFileName);
[grayImage,map] = imread(fullFileName);
%impixelinfo;
grayImage = rgb2gray(grayImage);
%size(grayImage)
imshow(grayImage,map)
binaryImage = ~imbinarize(grayImage);
imshow(binaryImage)
binimg2 = imfill(binaryImage,'holes');
imshow(binimg2)
[L n]= bwlabel(binimg2);
blobs= regionprops(L,'BoundingBox');
blobs(1).BoundingBox
rectangle('Position',blobs(1).BoundingBox,'Edgecolor','g')

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-6-9
编辑:Image Analyst 2021-6-10
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by