![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284225/image.png)
Droplet Dynamic Dimension determination image processing
4 views (last 30 days)
Show older comments
Hello, I have a code there is a droplet separating from a injector and it flows and change shapes. When you run the code it asks you to crop the image around the area which the droplet is moving and then the rest of the code executes. I used to use a circle for recognition of the droplet, now since the droplet is changing shape, my code is not working and I want to count pixels of my pixel! can someone help me with this? The part that says CODE BELOW in a comment mode I want to add my image. I am only attaching one image of 175 images. I just need a hint how to do such thing except from circling the droplet which is from some image forward is not circular anymore.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284140/image.jpeg)
analysis part.
clear
clc
close all
AutoThreshold = true;
CropImage = true;
Shadowgraphy = true; %// For OH chemiluminescence = false
ExportTracking = false;
StartTime = 50; %// Start time of video data in ms
%//-------------------------------------------------------------------------------------------------------------------------------------//
folder = pwd;
if AutoThreshold == false
prompt = {'Enter Threshold value (0-1):'};
boxTitle = 'Threshold';
definput = {'Shadowgraphy: 0.2 / OH chemiluminecsence: 0.5'};
threshold = str2double(inputdlg(prompt,boxTitle,[1 50],definput));
end
imageFiles = [dir([folder '\*.jpg']);dir([folder '\*.png'])];
numFiles = length(imageFiles);
data(1:numFiles,1:3) = NaN;
for trackingNo = 0:9 %// check if old tracking exist and make new folder
if trackingNo == 0 && exist([folder '\Tracking'], 'dir')
exportPath = ['\Tracking_' num2str(trackingNo+1)];
elseif trackingNo == 0 && ~exist([folder 'Tracking'], 'dir')
exportPath = ['\Tracking_' num2str(trackingNo+1)];
end
if trackingNo > 0 && exist([folder '\Tracking_' num2str(trackingNo)], 'dir')
exportPath = ['\Tracking_' num2str(trackingNo+1)];
end
end
mkdir(folder, exportPath);
for x = 1:numFiles
%// Calculate actual time
if Shadowgraphy == true
time = (x-1)/2000*1000+StartTime;
else
time = (x-1)/1600*1000+StartTime;
end
%// Load image & select cropping position
A = imread([folder '\' imageFiles(x).name]);
if CropImage == true && x == 1
cropFigure = figure('Name','Crop Image: Draw a rectangle','NumberTitle','off','units','normalized','outerposition',[0 0 1 1]);
imshow(A);
crop = imrect;
addNewPositionCallback(crop,@(p) title(mat2str(p,3)));
fcn = makeConstrainToRectFcn('imrect',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(crop,fcn);
position = wait(crop);
cropPosition = getPosition(crop);
close(cropFigure);
end
%// Crop image
if CropImage == true
cropPosition = round(cropPosition);
A = imcrop(A,cropPosition);
end
%// Treshold image
if AutoThreshold == true
if Shadowgraphy == true
threshold = isodata(A);
else
threshold = graythresh(A);
end
end
%//---------------CODE BELOW-------------------------------------------------------
A1 = A;
minGL = min(A1(:));
maxGL = max(A1(:));
meanGL = mean(A1(:));
% [X, Y] = param_detect02(175,A1,150,maxGL,0,0,0,0.1);
%
% A = im2bw(A,threshold);
% A = bwareafilt(A, 1);
% BW1 = double(im2bw(A,0.15));
% [accum, circen, cirrad] = CircularHough_Grd(A1, [15 2000]);
% BW1 = imfill(A1, 'holes');
% % labeledImage = bwlabel(A);
% A1 = edge(A1,'sobel',threshold);
%// Save data
data(x,1) = time;
data(x,2) = x; %radius of circle
data(x,3) = 0; %x position of circle
data(x,4) = 0; %y position of circle
%//----------------------------------------------------------------CODE ABOVE------------------------------------------------------
%// Display every 10th image
selector = 1:10:401;
if ismember(x,selector)
subplot(4,5,ceil(x/10))
imshow( A1);
hold on
% subplot(circen(1,1), circen(1,2), cirrad, 32, 'g');
%title(['Image ' num2str(x)],'FontSize',16);
title(['t = ' num2str(time) ' ms'],'FontSize',16);
end
if x == numFiles
export_fig([folder exportPath '\Overview.png']);
end
%// Export images with tracking
if ExportTracking == true
figure('Units','normalized','Position',[0 0 1 1])
imshow(A1);
hold on
title(['Image ' num2str(x)],'FontSize',16);
export_fig([folder exportPath '\Tracking_' num2str(x) '.png']);
close;
end
%// Display progress in %
Progress = round(x/numFiles*100);
end
%// Show & export regression plot
% figure('Name','Diameter Regression Plot','NumberTitle','off','units','normalized','outerposition',[0 0 1 1]);
% plot(data(:,1),data(:,2));
%
% title('Diameter Regression');
% xlabel('Time [ms]');
% ylabel('Diameter [px]');
% export_fig([folder exportPath '\Diameter-Regression.png']);
%// Clear all NaN rows & export data
data = data(all(~isnan(data),2),:);
csvwrite([folder exportPath '\Diameter-Regression.txt'], data);
7 Comments
Accepted Answer
darova
on 14 Apr 2020
Here is an idea:
- i cropped region of interest and reduced/dilated to separate each area
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284392/image.png)
- i expanded each area separately in for loop
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284393/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284394/image.png)
- then i want to ask user to pick area of interest
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284395/image.png)
- choose correct threshold for your image
graythresh-0.3 graythresh-0.0
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284396/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/284397/image.png)
I1 = im2bw(I,graythresh(I)-0.1); % binarize
6 Comments
darova
on 27 Apr 2020
this line
disp(['ERROR: ', str])
produces something like
ERROR image1
ERROR image2
...
You take all problem images to another folder and process them there
- No actually I have not.
Then you should try
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!