Solved question video analysis
Mostra commenti meno recenti
Hey all, so i have this script that analyzes the contact angle of a sessile droplet right now i do it with the code attached below and on the video attached to this. The issue is mainly that the aquired contact angles are quite jaggery and inconsitent since it is depended on the surface selection could anyone help me solve this?(i edited the question to make my issue and the answer more logical for readers)
contact_angle_left = NaN;
contact_angle_right = NaN;
contact_angle_avg = NaN;
if is_impact
dropletMask = false(size(filledImage));
dropletMask(dropletStats.PixelIdxList) = true;
% Find droplet boundary
dropletBoundary = bwboundaries(dropletMask);
if ~isempty(dropletBoundary)
outline = dropletBoundary{1};
x_outline = outline(:,2); % Column indices (x-coordinates)
y_outline = outline(:,1); % Row indices (y-coordinates)
if numel(x_outline) >= 20 % Need sufficient points
% Convert to physical coordinates (meters)
x_phys = x_outline * scale_Image * 1e-6;
y_phys = y_outline * scale_Image * 1e-6;
% Find contact points (points near the surface)
surface_y_phys = minYSurface * scale_Image * 1e-6;
contact_threshold = equiv_radius * 0.3; % 30% of droplet radius
% Find all points near the surface
near_surface_indices = find(abs(y_phys - surface_y_phys) < contact_threshold);
if length(near_surface_indices) >= 4
% Find the leftmost and rightmost contact points
x_contact = x_phys(near_surface_indices);
y_contact = y_phys(near_surface_indices);
[x_min, left_idx] = min(x_contact);
[x_max, right_idx] = max(x_contact);
left_contact_point = [x_min, y_contact(left_idx)];
right_contact_point = [x_max, y_contact(right_idx)];
% Calculate contact angles using tangent method
% For each contact point, find nearby points to calculate tangent
tangent_range = equiv_radius * 0.2; % Distance for tangent calculation
% LEFT CONTACT ANGLE
left_contact_idx = near_surface_indices(left_idx);
% Find points within tangent range from left contact point
distances_from_left = sqrt((x_phys - left_contact_point(1)).^2 + ...
(y_phys - left_contact_point(2)).^2);
tangent_indices_left = find(distances_from_left <= tangent_range & ...
distances_from_left > 0);
if length(tangent_indices_left) >= 3
% Filter points that are above the contact point (droplet side)
above_contact = tangent_indices_left(y_phys(tangent_indices_left) < left_contact_point(2));
if length(above_contact) >= 3
% Fit line to these points
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
% Remove outliers and sort by x
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
% Linear fit with error handling
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_left = polyfit(x_fit, y_fit, 1);
slope_left = p_left(1);
catch
slope_left = NaN;
end
else
slope_left = NaN;
end
% Contact angle calculations with error handling
if ~isnan(slope_left)
angle_rad_left = atan(slope_left);
contact_angle_left = 180 - rad2deg(angle_rad_left);
% Ensure angle is in valid range
if contact_angle_left < 0
contact_angle_left = contact_angle_left + 180;
elseif contact_angle_left > 180
contact_angle_left = contact_angle_left - 180;
end
end
end
end
% RIGHT CONTACT ANGLE
right_contact_idx = near_surface_indices(right_idx);
% Find points within tangent range from right contact point
distances_from_right = sqrt((x_phys - right_contact_point(1)).^2 + ...
(y_phys - right_contact_point(2)).^2);
tangent_indices_right = find(distances_from_right <= tangent_range & ...
distances_from_right > 0);
if length(tangent_indices_right) >= 3
% Filter points that are above the contact point (droplet side)
above_contact = tangent_indices_right(y_phys(tangent_indices_right) < right_contact_point(2));
if length(above_contact) >= 3
% Fit line to these points
x_fit = x_phys(above_contact);
y_fit = y_phys(above_contact);
% Remove outliers and sort by x
[x_fit, sort_idx] = sort(x_fit);
y_fit = y_fit(sort_idx);
% Linear fit with error handling
if length(unique(x_fit)) >= 2 && length(x_fit) >= 2
try
p_right = polyfit(x_fit, y_fit, 1);
slope_right = p_right(1);
catch
slope_right = NaN;
end
else
slope_right = NaN;
end
% Contact angle calculations with error handling
if ~isnan(slope_right)
angle_rad_right = atan(slope_right);
contact_angle_right = rad2deg(angle_rad_right);
% Ensure angle is in valid range
if contact_angle_right < 0
contact_angle_right = contact_angle_right + 180;
elseif contact_angle_right > 180
contact_angle_right = contact_angle_right - 180;
end
end
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Image Category Classification in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

