Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2014-05-30 03:05:41

OusGh
Guest

Distance Invariant to scale and rotation

Hello everyone,

I need your help for my project. I am tracking a face with my kinect and I am retrieiving some points from the face. I need to compute distances between two points of these in order to get a certain number of distances but I need the distance between each two points to be scale and rotation-invariant. I used mahanalobis distance but with only two points it returns a constant for every face in front of the kinect. Thank you for your help.

#2 2014-05-30 19:30:14

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

hi OusGh

Welcome to the forum.

I'd not met this way of computing distance before so I had to look it up:

http://en.wikipedia.org/wiki/Mahalanobis_distance

It seems to depend on the distribution of a large sample of points, so maybe just using two points is causing this result.  If you haven't got an answer elsewhere, you could try posting more details:  eg. the relevant code and data.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#3 2014-05-31 00:25:17

OusGh
Member
Registered: 2014-05-31
Posts: 4

Re: Distance Invariant to scale and rotation

Thank you for your answer. I think that is the reason why is returns the same constant everytime a face is in front of the kinect sensor. But I need to compute a distance between two points that is invariant to scale. Here is my code:

public static double MinusX(Vector3DF p1, Vector3DF p2)
        {
            return (p1.X - p2.X) * (p1.X - p2.X);
        }

        public static double MinusY(Vector3DF p1, Vector3DF p2)
        {
            return (p1.Y - p2.Y) * (p1.Y - p2.Y);
        }

        public static double MinusZ(Vector3DF p1, Vector3DF p2)
        {
            return (p1.Z - p2.Z) * (p1.Z - p2.Z);
        }

        public static Dictionary<string,double> MahanalobisDistances(FaceTrackFrame faceFrame)
        {
            Vector3DF eyesCenterVector = new Vector3DF(Math.Abs((faceFrame.Get3DShape()[FeaturePoint.InnerCornerLeftEye].X - faceFrame.Get3DShape()[FeaturePoint.InnerCornerRightEye].X)/2),
                                                        Math.Abs((faceFrame.Get3DShape()[FeaturePoint.InnerCornerLeftEye].Y - faceFrame.Get3DShape()[FeaturePoint.InnerCornerRightEye].Y)/2),
                                                        Math.Abs((faceFrame.Get3DShape()[FeaturePoint.InnerCornerLeftEye].Z - faceFrame.Get3DShape()[FeaturePoint.InnerCornerRightEye].Z)/2)
                                                        );

            //ED: EyesDistance
            double eyesDist = MahanalobisDistance(faceFrame.Get3DShape()[FeaturePoint.InnerCornerLeftEye], faceFrame.Get3DShape()[FeaturePoint.InnerCornerRightEye]);
           
            //ECD: Eyes Corner Distance
            double eyesCornerDist = MahanalobisDistance(faceFrame.Get3DShape()[FeaturePoint.OuterCornerOfLeftEye], faceFrame.Get3DShape()[FeaturePoint.OuterCornerOfRightEye]);

            //NW: Nose Width
            double noseWidth = MahanalobisDistance(faceFrame.Get3DShape()[26], faceFrame.Get3DShape()[59]);

            //NL: Nose Length
            double noseLength = MahanalobisDistance(faceFrame.Get3DShape()[37], faceFrame.Get3DShape()[39]);

            //NMD: Nose Mouth Distance
            double noseMouthDist = MahanalobisDistance(faceFrame.Get3DShape()[37], faceFrame.Get3DShape()[8]);

            //SaveDistances(eyesDist, eyesCornerDist,noseWidth);

            Console.WriteLine("ed"+eyesDist+" ecd "+eyesCornerDist+" nw "+noseWidth+" nl "+noseLength+" nmd "+noseMouthDist);

            return new Dictionary<string,double>{{"ED",eyesDist},{"ECD",eyesCornerDist},{"NW",noseWidth},{"NL",noseLength},{"NMD",noseMouthDist}};
        }

        public static double MahanalobisDistance(Vector3DF p1, Vector3DF p2)
        {
            double[] xVector = new double[] { p1.X, p2.X };
            double[] yVector = new double[] { p1.Y, p2.Y };
            double[] zVector = new double[] { p1.Z, p2.Z };


            double dist = Math.Abs((MinusX(p1, p2) / StandardDerivation(xVector)) + (MinusY(p1, p2)/StandardDerivation(yVector)) + (MinusZ(p1, p2)/ StandardDerivation(zVector)));

            return dist;
        }

Offline

#4 2014-05-31 06:45:11

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

Ok thanks.  Now I've got to learn how that distance function works, so I'll be thinking for a while ..........  dizzy

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#5 2014-05-31 20:17:38

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

What language are you using?  I'm having trouble following your code.  dizzy

Please would you write out an algorithm for what you are doing (in simple terms please for my old brain smile

eg. Get coordinates for .......

Compute distances using Euclidean distance.

Compute .........

Thanks

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#6 2014-05-31 21:59:28

OusGh
Member
Registered: 2014-05-31
Posts: 4

Re: Distance Invariant to scale and rotation

I am using C#, okay I'll write an algorithm:

algorithme MahalanobisDistances(faceTrackFrame: image where to look for the face points){

//ED: EyesDistance
           
              double eyesDist = MahalanobisDist(LeftinnerCornerOfRightEyePoint,RightInnerCornerOfLeftEyePoint);
            //do the same thing of the others distance: call MahanalobisDist method to compute distance between each two points
              double eyesCornerDist = ...
              double noseWidth = ...
               ...

            //here I return all distance I computed in a Dictionnary(a list with indexes)
            return new Dictionary<string,double>{{"ED",eyesDist},{"ECD",eyesCornerDist},{"NW",noseWidth},{"NL",noseLength},{"NMD",noseMouthDist}};
}



//The function I call to compute the mahalanobis distance between two points
algorithme MahanalobisDist(point1, point2)
        {
            //Create three vectors with the x,y,z coordinates of each point (will be used for standard derivation)
            double[] xVector = new double[] { point1.X, point2.X };
            double[] yVector = new double[] { point1.Y, point2.Y };
            double[] zVector = new double[] { point1.Z, point2.Z };


            // compute the distance between the two points,
            //MinusX(point1,point2) = (point1.x - point2.x)^2
            //MinusY(point1,point2) = (point1.y - point2.y)^2
            //MinusZ(point1,point2) = (point1.z - point2.z)^2

            double dist = Math.Abs((MinusX(p1, p2) / StandardDerivation(xVector)) + (MinusY(p1, p2)/StandardDerivation(yVector)) + (MinusZ(p1, p2)/ StandardDerivation(zVector)));
            return dist;
        }

I hope this is okay. Thank you for your concern.

Offline

#7 2014-06-01 18:34:19

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

Sorry, but that hasn't helped as it still contains code.  What I meant was something like this:

(1) Get the coordinates of these points ..........  Max and min values are .................

(2) Compute the distances between ....

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#8 2014-06-02 08:11:52

OusGh
Member
Registered: 2014-05-31
Posts: 4

Re: Distance Invariant to scale and rotation

Okay,

1)Get the coordinates of these points (InnerLeftEyePoint = p1,InnerRightEyePoint = p2)
2) compute distance for these two points: (Xp1-Xp2)^2 / standardDeviation(Xp1,Xp2)+(Yp1-Yp2)^2 / standardDeviation(Yp1,Yp2)+(Zp1-Zp2)^2 / standardDeviation(Zp1,Zp2); here Xp1, Yp1, Zp1 are x,y,z coordinates of the point p1.  ^2 means Power 2.

The problem is that is returns a constant equal to 2 because of the standard derivation of two points. I am looking for another formula to compute a distance that is scale invariant and invariant to rotation.

Offline

#9 2014-06-02 20:15:54

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

hi OusGh

Using the formula for standard deviation, and substituting those coordinates, I would expect that you would get 2 + 2 + 2.  The coordinates cancel out and just leave those numbers, whatever coordinates you have.

Standard deviation is intended to be applied to a much larger data set, and, as I understand it, Mahalanobis distance is also intended to take account of a large set of data.  So my best guess is that you should create an array to hold the measurements for lots of facial features, and then use the statistical parameters from that set to 'scale' the measurements.

Suggestions:

(1) Do an on-line search to see if you can find a similar example;

(2) Explain here, more fully, what this is all about; eg.  are you trying to create your own facial recognition system?  Maybe someone will have a brilliant idea.

Bob

Last edited by Bob (2014-06-02 20:22:47)


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

#10 2014-06-02 20:52:27

OusGh
Member
Registered: 2014-05-31
Posts: 4

Re: Distance Invariant to scale and rotation

Thank you for your answer Bob, yes that what I found out too about the constant and I looked on the net without a good result. For my project I use the kinect sensor and face tracking SDK to track a face a get facial feature points. I want to implement my own facial recognition system using these facial features, I wanted to compute distances between some feature points like distance between eyes, nose length and width, jaw width. If someone have some idea to help me that would be great. I tried to compute distance using normalized euclidean distance but the distance changes after a certain period of time, I think it's caused by incertity measure of the sensor. Thank you.

Offline

#11 2014-06-03 00:11:19

Bob
Administrator
Registered: 2010-06-20
Posts: 10,163

Re: Distance Invariant to scale and rotation

hi OusGh

Here's my suggestion.

Get the face values:

(1) Get the coordinates of lots of identifiable points.

(2) Compute as many distances as you can between points.

(3) Set these up in an array.

(4) Compute the mean and standard deviation of these data.

(5) Scale the values in the array by (x - mean)/sd and save the new values in a second array, in non volatile memory.

Test a face.

(6) Repeat steps 1 to 5 for the test face.

(7) Hypothesis: the new sample is from the original population  I'm not sure which statistical test is best here.  I think it's the t-test.  bobbym: if you are reading this perhaps you can advise.

(8) Or maybe you could test the values using the Chi squared test?

Will it work?  Who knows; you'd have to check it with lots of test faces, valid and not valid.

If it does, you could store the values for several different faces and run the test face against them all to say whether it matches any.

If you do try it, let us know how you get on.

Bob


Children are not defined by school ...........The Fonz
You cannot teach a man anything;  you can only help him find it within himself..........Galileo Galilei
Sometimes I deliberately make mistakes, just to test you!  …………….Bob smile

Offline

Board footer

Powered by FluxBB