필터 지우기
필터 지우기

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

조회 수: 6 (최근 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월 10일
You're replying to KSSV's comment. Did you even see or try my Answer below? I believe it works.

댓글을 달려면 로그인하십시오.

채택된 답변

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
naygarp
naygarp 2021년 6월 10일
Right, thanks again. I'll try running the code inside a loop and see if it works.

댓글을 달려면 로그인하십시오.

추가 답변 (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