How do I capture the ROI with bounding box when the image is low in brightness and grainy on one side?

5 vues (au cours des 30 derniers jours)
I have an image of a droplet falling on another stationary drop. The left side of the image is poorly illuminated and overall the brightness is not that good. I have applied a code that normally captures the ROI which is the blob of an other a well lit image but unable to do so in this case. I have uploaded the actual image and the processed image in this query (the original file is in .zip format and the processed image output is in .jpg). What modification can be done in order to capture the blob accurately? I tried to use imadjust but it's not working
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 containing the image
folder = 'H:\Images sorted for calculation\For 0.4 m_sec\0.25 CMC\head on';
% Base filename of the image
baseFileName = '0.25 cmc head on_0213.tif';
% Full path of the image
fullFileName = fullfile(folder, baseFileName);
% Check if file exists
if ~isfile(fullFileName)
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
fullFileName = fullFileNameOnSearchPath;
end
% Read the image
[grayImage, map] = imread(fullFileName);
% **Brightness adjustment**
% Replace the following line with your preferred method:
% Option 1: Add a constant value to all pixels (simple but might clip values)
% brightImage = grayImage + 50; % Adjust the value (50) as needed
% Option 2: Use imadjust function for more control
brightImage = imadjust(grayImage, [0 1], [0.5 1], 0.5); % Increase brightness and contrast
% Convert to grayscale if needed
brightImage = rgb2gray(brightImage);
% ... (rest of the code remains the same, using brightImage instead of grayImage)
binaryImage = ~imbinarize(brightImage, graythresh(brightImage)); % Use adaptive thresholding
binaryImage = imerode(binaryImage, strel('disk', 2)); % Erode to separate needle
binaryImage = imfill(binaryImage, 'holes');
% Isolate droplet region (adjust based on image characteristics)
[labeledImage, numObjects] = bwlabel(binaryImage);
dropletBlob = labeledImage == 2; % Assuming droplet is the second largest object
% Calculate properties and display
% Erase from line 758 down:
%binaryImage(800: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', 0.5)
fprintf('Done running %s.m ...\n', mfilename);

Réponse acceptée

maor shaul
maor shaul le 7 Mar 2024
you can try using the imflatfield function
https://www.mathworks.com/help/images/ref/imflatfield.html
  1 commentaire
Pragyan Kumar Sarma
Pragyan Kumar Sarma le 15 Mar 2024
Thanks for your reply. I have now used imflatfield in the above code. And now the code recognises the blob.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by