Hi,
I am using the code below to generate the droplet image and measure the contact angle. After truncation, I only can get the subtrate image but not the actual droplet image i need. Can somebody help me to look into it?
Thanks you.
% Surface Tension Measurements Using the Pendant Drop Method
[filename, pathname] = ...
uigetfile({'*.jpg';'*.tif';'*.gif';'*.*'},'Select an image'); %Open standard dialog box for retrieving files
rgbImage = imread([pathname,filename]); im = im2double(rgb2gray(rgbImage)); % Convert image to gray imshow(im); % Display image
BW = im2bw(im); L = bwlabeln(1-BW, 4); % Label White Spots S = regionprops(L, 'Area'); % Measure Area of Spots BW2 = ismember(L, find([S.Area] ==max( [S.Area]) )); % Find Largest Spot BW2(1,:) = 1; % Turn First Row White imshow(BW2);
figure(2);clf; BW3 = imfill( BW2, 'holes' ); % Fill In Holes in Image imshow(BW3);
[x_coordinates y_coordinates Pixel_vals] = impixel; rot_line = polyfit(x_coordinates ,y_coordinates ,1 ); % Replicate Substrate rot_point = round( polyval( rot_line, 1 )); % Truncation Point rot_angle = atan( rot_line(1) ); % Correction Angle BW4 = BW3( rot_point:end,: ); % Truncation BW4 = imrotate( BW4, -rot_angle*180/pi ); % Correction BW4 = BW4( -y_coordinates(2) + rot_point:end,: ); % Truncation Correction imshow( BW4 ); % Display Image
Function_ContactAngleb([200 300], 250, BW4)
[val, status, message] = fminsearch( @(cntr_radius) ...
Function_ContactAngleb( cntr_radius(1:2), cntr_radius(3), BW4 ), ...
[200, 200, 100], optimset('display', 'iter' ) );
crcl = Function_ContactAngle( val(1:2), val(3), size(BW4) ); % Optimized Generated Circle imagesc( 10*crcl+BW4 ); % Picture/Optimization Overlay axis image; % Show axes
% Math manipulation to calculate contact points based on radius and
% location of the center of the circle
contact_pt = [ (sqrt( val(3)^2 - ( 1-val(1) )^2 ) + val(2)), ...
-(sqrt( val(3)^2 - ( 1-val(1) )^2 ) + val(2)) ];
% Determine tangent lines of contact points
tangent_slope = -( contact_pt-val(2) )/( 1-val(1) );
contact_angle = atan(tangent_slope); % Contact Angle
contact_angle = (contact_angle*180/pi); % Radians to Degrees
corrected_angle = [ mod( 180-contact_angle(1), 180 ),...
mod( 180+contact_angle(2), 180)]; % Correction for proper domain
return
%*******************************************************************************
% Finish Main Program
No products are associated with this question.
Your array Function_ContactAngle is not initialized anywhere in the code you show.
The portion of your code starting at "Math manipulation" references the variable "val" which is previously unreferenced.
A reasonable hypothesis would be that the portion of your code starting at "Math manipulation" should be a function named Function_ContactAngle .
With regards to plotting not working as you expect, please read my graphics advice in http://www.mathworks.co.uk/matlabcentral/answers/22208-show-figure
I would be concerned about your lines
subim(round(min(end, max(1,center(1)+[-radius:radius]) )), ...
round(min(end, max(1,center(2)+[-radius:radius]) )) ) = tmp; % Draw CircleIn those lines, you may vary the index range to write into (to prevent writing past the beginning or end of the array), but you do not adjust the size of "tmp" when you do that. If the restriction conditions can ever be met then you would get dimension mismatches; if the restriction conditions cannot be met then there is no point in putting in the restrictions.
Hi,
Thanks for your reply.
I have a problem when I need to truncate the substrate in order to get my actual droplet especially when those droplet with reflection on the substrate. Is it the problem with the truncation?
[x_coordinates y_coordinates Pixel_vals] = impixel; rot_line = polyfit(x_coordinates ,y_coordinates ,1 ); % Replicate Substrate rot_point = round( polyval( rot_line, 1 )); % Truncation Point rot_angle = atan( rot_line(1) ); % Correction Angle BW4 = BW3( rot_point:end,: ); % Truncation BW4 = imrotate( BW4, -rot_angle*180/pi ); % Correction BW4 = BW4( -y_coordinates(2) + rot_point:end,: ); % Truncation Correction imshow( BW4 ); % Display Image
Kind regards,
Voon Loong
I do not understand what you mean by "truncation" in this context?
2 Comments
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46317#comment_95259
And how can we do that? (Put yourself in our position and think a minute.)
Direct link to this comment:
http://mathworks.com/matlabcentral/answers/46317#comment_95274
... For example, is the cameraman image a suitable input?