How do i measure the diameter of a droplet
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everybody i hope you are doing well i have a small problem, I want to measure the diameter of a droplet using a video and matlab.to measure this, i use the image of the droplet (using ImageJ) and determine the pixel width after that i use this in my matlab code but when i run this i have an error and i don't know if this has anything to do with my matlab version because it doesn't work if someone can help me thanks
i have the following error: Error in Diameter (line 14)
vid_Obj = VideoReader(data_path); % Creating a VideoReader Object.
clear all;
close all hidden
seq = [3]; % Sequence of files to be analysed
folder_path = 'C:\Users\rodri\Desktop\Bias\'; % Folder path of the AVI files
test_series = 'Video_Test_1';
quantity = length(seq);
framerate = 30; % Video recording rate
fps = 1000; % for correct real-time calculation
scalefactor = 74.1568; % in Pixel pro mm
for nbr = 1: quantity
data_path = strcat(folder_path ,test_series ,'_',int2str(seq(nbr)),'.avi');
vid_Obj = VideoReader(data_path); % Creating a VideoReader Object
%%
fig1 = subplot (2,2,1); %title('Cut ') ;
fig2 = subplot (2,2,2); %title('Contrast reworked ') ;
fig3 = subplot (2,2,3); %title('Edge detection ') ;
fig4 = subplot (2,2,4); %title('Raw data with detected edges ') ;
%%
vid_Obj.CurrentTime = 0; % Playback time in s
dist = [];
%%
while vid_Obj.CurrentTime < vid_Obj.Duration
img_struct = readFrame(vid_Obj ,'native '); % Read next image
img = img_struct.cdata; % Transfer grey values as uint8
img_cr2 = imcrop(img ,[220 0 548 768]); % Crop image
frame = round(vid_Obj.CurrentTime * vid_Obj.Framerate); % Calculate the current frame
im_adj = imadjust(img_cr2 ,[0.3; 1] ,[0; 0.8] ,1); % Adjust contrast/gamma
BW = edge(im_adj ,'canny ' ,0.2,sqrt (20)); % Edge detection with Canny
algorithmus
[B,L] = bwboundaries(im_adj ,'noholes '); % Edge detection with coordinate detection
imshow(img_cr2 ,'parent ',fig1); imshow(im_adj ,'parent ',fig2);imshow(BW ,'parent ',fig3); imshow(img_cr2 ,'parent ',fig4);
text (-500,-200, strcat('frame: ',int2str(frame)));
zeit = frame/fps;
text (-500,-100, strcat('realtime: ',sprintf('%.3f',zeit)));
drawnow; hold on
size = [];
for k = 1: length(B) % Plot all detected edges
boundary = B{k};
plot(boundary (:,2), boundary (:,1), 'r','linewidth ' ,1)
size(k,1) = length(boundary);
end
% Detection of the longest detected edge
[a,b] = max(size);
max_boundary = B{b}; %
plot(max_boundary (:,2), max_boundary (:,1), 'g','linewidth ' ,1); % Plot longest edge in green
dist(frame) = max(max_boundary (:,2)) - min(max_boundary (:,2)); % Maximum distance in X direction
drawnow;
hold off
end
%%
figure
time_axis = [1: length(dist)]/fps;
plot(time_axis ,dist/scalefactor)
xlabel('Zeit [s]');
ylabel('Tropfendurchmesser [mm]');
end
2 comentarios
Adam
el 3 de Nov. de 2021
Follow the error message and check if what is in your
data_path
variable actually exists or not.
If it is a full path (i.e. folders too) then it should not need to be on the Matlab path, but it does need to be a valid file location on your system.
Respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!