Clear Filters
Clear Filters

What modification is required in the given code on image processing to accurately capture the dimensions of a spreading blob from a series of images?

4 views (last 30 days)
I have a series of images of a drop of liquid spreading on a solid surface, the google drive link for the images are attached in this query mail. The images are taken with a help of a high speed camera and I need to find the spreading length of the liquid blob. I have constructed a code which reads all the images in a folder and processes them and returns the spreading width and height. The code correctly thresholds some of the images but fails to do so for some of the image due to reflection of light on the spreading blob. What modification is required in the code so as to get all the blob captured correctly and returns the almost accurate spreading datas? link for the image folder on Google Drive
The code is given in the following :
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format short;
format compact;
fontSize = 18;
% Ask user to enter the conversion factor
%conversionFactor = input('Enter the conversion factor to convert pixel dimensions to real dimensions: ');
conversionFactor = 0.021636;
% Folder containing images
folder = 'H:\Reduced no. files for analysis\at 1.64 m_sec\on 0.25 cmc\water on 0.25 cmc\4 mm off';
% Get a list of all files in the folder
fileList = dir(fullfile(folder, '*.tif'));
% Initialize arrays to store spreading width and droplet height
spreadingWidthArray = [];
dropletHeightArray = [];
% Process each image
for i = 1:numel(fileList)
baseFileName = fileList(i).name;
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
% Read the image
[grayImage, map] = imread(fullFileName);
grayImage = imflatfield(grayImage, 6); % Correct uneven illumination *50 for 1 cmc on 1 cmc (1 m_sec)
grayImage = rgb2gray(grayImage);
% Display preprocessed image
figure;
imshow(grayImage, map);
title('Preprocessed Image');
% Thresholding
binaryImage = ~imbinarize(grayImage);
% Erase from line 758 down:
binaryImage(773:end, :) = false; % 758 % 725 for 1 m/sec surface tension contrast % 759 for a little bit bright *743 for 1 on 1 (1 m/sec)
% Fill holes
binaryImage = imfill(binaryImage, 'holes');
% Get rid of small noise blobs
binaryImage = bwareafilt(binaryImage, 1); % Take largest blob only
% Compute properties of the binary image
props = regionprops(binaryImage, 'BoundingBox');
spreadingWidth = props.BoundingBox(3);
dropletHeight = props.BoundingBox(4);
% Convert pixel dimensions to real dimensions
spreadingWidthReal = spreadingWidth * conversionFactor;
dropletHeightReal = dropletHeight * conversionFactor;
% Round to 4 decimal places
spreadingWidthReal = round(spreadingWidthReal, 4);
dropletHeightReal = round(dropletHeightReal, 4);
% Store spreading width and droplet height in real dimensions
spreadingWidthArray = [spreadingWidthArray, spreadingWidthReal];
dropletHeightArray = [dropletHeightArray, dropletHeightReal];
% Display binary image with bounding box
figure;
imshow(binaryImage);
hold on;
rectangle('Position', props.BoundingBox, 'Edgecolor', 'g', 'LineWidth', 0.25);
hold off;
title('Binary Image with Bounding Box');
impixelinfo;
fprintf('Done running %s.m ...\n', mfilename);
end
% Display the arrays of real dimension values
disp('Spreading Widths in Real Dimensions:');
fprintf('%.4f\n', spreadingWidthArray);
disp('Droplet Heights in Real Dimensions:');
fprintf('%.4f\n', dropletHeightArray);

Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!