How shall I ignore the reflection in an image and select the rest of the image in a bounding box and obtain the results also automate it in order to process multiple images?

2 views (last 30 days)
I have a number of images of a combined droplet spreading on a surface. I need to do image processing in order to calculate the droplet spreading length and height as indicated in the attached images. I have run a code which binarizes and thresholds the image and a applies a boundingbox to capture the dimension of the blob. Now it can be seen from the image that there is a reflection of the combined droplet blob which is visible as the solid substrate is glass. The Matlab code accurately captures the spreading width horizontally through the bounding box but for the vertical direction it includes the reflected portion as well. So how can it be done? Also how could I automate it so the code loads a series of images (say 25 images) processes those image files and returns both the pixel size of the length and breadth?
What modifications on this code could be incorporated
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\Admin\Desktop\Droplet images for calculation\0.50 cmc on water\0.5 cmc head on\fixing time';
baseFileName = '0.5 cmc head on0211.tif';
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(687:end, :) = false; % 758
% 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)
droplet_height = props.BoundingBox(4)
rectangle('Position', props.BoundingBox, 'Edgecolor', 'g', 'LineWidth', 2)
fprintf('Done running %s.m ...\n', mfilename);

Accepted Answer

Image Analyst
Image Analyst on 20 Jan 2024
Rather than remove it, just scan across your binary image finding where it's white
[rows, columns] = size(binaryImage)
topRows = nan(1, columns);
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'first');
if ~isempty(t)
topRows(col) = t;
end
end
inDroplet = ~isnan(topRows);
leftColumn = find(inDroplet, 1, 'first')
rightColumn = find(inDroplet, 1, 'last')
spreadingWidth = rightColumn - leftColumn; % Pixel center to pixel center. Add 1 if you want whole pixels.
  4 Comments
Pragyan Kumar Sarma
Pragyan Kumar Sarma on 21 Jan 2024
Edited: Pragyan Kumar Sarma on 21 Jan 2024
Thanks for your answer. I also need to get the vertical distance of the coalesced drop, so in order to do so I need to ignore the reflected part of the image. So any more modification that could scan and identify the vertical distance part?
For this does it need to be something like
spreadingHeight = topRow - bottomRow

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!