how to join points at the edges of a face on an image using a curve?

Hi.Suppose i have a face image with 3 selected points at the edges.One point is at the chin edge,another is the right cheek edge and another is at the left cheek edge.Now i wanted to join these three points along the edges of the face using a curve.So that it appears like a 'U' shape on the edges of the face.How cud i do this...Any one plz help..??

Answers (3)

What am gonna do is to first i ll use ginput to get the (x,y) coordinates of those three points.Then i ll mark those points as a dot using the plot fun on the image at those three points for our reference to see the selected points on the image.Now i wanted to join these three dots which are at the edges using a cure..I donno how to do this last part..can anyone suggest me something..??
You might try my spline demo:
% function SmoothSplineCurve()
clc; % Clear command window.
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.
set(gcf,'name','Spline Demo by ImageAnalyst','numbertitle','off')
axis([0 10 0 10])
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Spline Demo', 'FontSize', fontSize);
hold on
% Initially, the list of points is empty.
knots = [];
numberOfPointsClicked = 0;
% Prompt the user
message = sprintf('Left click to draw some vertex points.\nRight click the final point to finish drawing.');
uiwait(msgbox(message));
buttonThatWasClicked = 1;
% Enter a loop asking user to click on the knot vertexes.
while buttonThatWasClicked == 1
[xKnot, yKnot, buttonThatWasClicked] = ginput(1);
plot(xKnot, yKnot, 'ro', 'LineWidth', 2)
numberOfPointsClicked = numberOfPointsClicked+1;
% Make this coordinate a new column.
knots(:, numberOfPointsClicked) = [xKnot; yKnot];
end
% Calculate the area within the blue spline curve.
% You do not need to connect the last point back to the first point.
x = knots(1, :);
y = knots(2, :);
areaOfPolygon = polyarea(x,y);
% Interpolate with a spline curve and finer spacing.
originalSpacing = 1 : numberOfPointsClicked;
% Make 9 points in between our original points that the user clicked on.
finerSpacing = 1 : 0.1 : numberOfPointsClicked;
% Do the spline interpolation.
splineXY = spline(originalSpacing, knots, finerSpacing);
% Plot the interpolated curve.
hold off;
plot(knots(1, :), knots(2, :), 'ro',...
splineXY(1, :), splineXY(2, :), 'b+-', 'LineWidth', 2, 'MarkerSize', 16);
title('Blue Spline Between Red Knots', 'FontSize', fontSize);
legend('Knots', 'Spline');
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
grid on;
hold off;
% Calculate the area within the blue spline curve.
% You do not need to connect the last point back to the first point.
x = splineXY(1, :);
y = splineXY(2, :);
areaInsideSplineCurve = polyarea(x,y);
% Give the area calculations.
message = sprintf('The area inside the polygon you drew is %.2f.\nThe area inside the blue spline curve is %.2f', ...
areaOfPolygon, areaInsideSplineCurve);
fprintf(1, '%s', message); % Print to command window.
msgbox(message); % Show user via a popup message box.

5 Comments

I tried ur code sir..But there is some problem,the curve is not following the contour of the face.The curve through the three points lying at the contour points of the face is deviating from the contour line..so how to make the curve follow the contour of the face..??
It interpolates between the "knot" points. Were your knot points on the contour of the face? If so, then this code should fill in the "missing" coordinates smoothly. It should follow the contour of the face if your knot points are good. Keep in mind that it tries to match up slopes at knot points - that's how splines work - so it's possible if you have aberrant points the slope might be severe enough to cause the "in between" points to not lie along the contour.
it may seem a little late for this but i hv a question directed to Image Analyst; based on your demo code is it possible to draw those points directly on a certain input image or feed your code with predefined pixels? so that the resulted curve will be drawn on that image itself. Thanks
Yes. You'd have to call imline to burn lines between the knots into the image. Search for imline - I've posted demos on that before. If no luck, then paste this code, or your code, and ask in a new thread.
Thanks man, imline, how could i possibly hv missed that ! you are truly an Image Analyst genius! thanks again for your quick reply.

Sign in to comment.

Categories

Asked:

on 16 Feb 2012

Edited:

on 15 Oct 2013

Community Treasure Hunt

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

Start Hunting!