void Moments(Image <Gray, byte> img, ref Double[] MomentSp, ref Double[] MomentCen, ref Double[] MomentNor)
        {
            Image <Gray, byte> imgA = new Image <Gray, byte>(img.Size);

            imgA = img.ThresholdBinary(new Gray(60), new Gray(255));
            Contour <Point> contourA = imgA.FindContours();
            MCvMoments      momentsA = contourA.GetMoments();

            for (int xOrder = 0; xOrder <= 3; xOrder++)
            {
                for (int yOrder = 0; yOrder <= 3; yOrder++)
                {
                    if (xOrder + yOrder <= 3)
                    {
                        MomentSp[3 * xOrder + yOrder]  = momentsA.GetSpatialMoment(xOrder, yOrder);
                        MomentCen[3 * xOrder + yOrder] = momentsA.GetCentralMoment(xOrder, yOrder);
                        MomentNor[3 * xOrder + yOrder] = momentsA.GetNormalizedCentralMoment(xOrder, yOrder);
                    }
                }
            }

            /*     for (int m = 0; m < 12; m++)
             *   {
             *       richTextBox4.AppendText("SP:"+MomentSp[m]+"  CEN:"+MomentCen[m]+"   Nor: "+MomentNor[m]+"\n");
             *   }*/
        }
        void Moments(Image <Gray, byte> img, ref Double[] MomentSp, ref Double[] MomentCen, ref Double[] MomentNor)
        {
            Image <Gray, byte> imgA = new Image <Gray, byte>(img.Size);

            imgA = img.ThresholdBinary(new Gray(60), new Gray(255));
            Contour <Point> contourA = imgA.FindContours();
            MCvMoments      momentsA = contourA.GetMoments();

            for (int xOrder = 0; xOrder <= 3; xOrder++)
            {
                for (int yOrder = 0; yOrder <= 3; yOrder++)
                {
                    if (xOrder + yOrder <= 3)
                    {
                        MomentSp[3 * xOrder + yOrder]  = momentsA.GetSpatialMoment(xOrder, yOrder);
                        MomentCen[3 * xOrder + yOrder] = momentsA.GetCentralMoment(xOrder, yOrder);
                        MomentNor[3 * xOrder + yOrder] = momentsA.GetNormalizedCentralMoment(xOrder, yOrder);
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////PUPIL(INNER IRIS BOUNDARY) DETECTION///////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        //return true if pupil is detected on contour detection
        //false if further hough circles need to be found
        private void PerformContourDetection()
        {
            // Detected Contours will store all the contours detected in our image, Find contours will find all the contours
            // CV_RETR_TREE retrieves all of the contours and reconstructs a full hierarchy of nested contours
            // CV_CHAIN_APPROX_SIMPLE compresses horizontal, vertical, and diagonal segments and leaves only their end points.
            Contour <Point> detectedContours = MaskedImage.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_TREE);

            //Image moments help you to calculate some features like center of the object, area of the object etc---> here the object is the contour detected
            MCvMoments moments = new MCvMoments();

            //Make sure atleast one contour is detected
            while (detectedContours != null)
            {
                //Get the Moments of the Detected Contour
                moments = detectedContours.GetMoments();

                //get the area of the detected contour--> GetCentralMoment has the area
                double AreaOfDetectedContour = moments.GetCentralMoment(IrisConstants.Zero, IrisConstants.Zero);

                if (detectedContours.Total > 1)
                {
                    //((area > IrisConstants.MaxPupilArea) && (area < IrisConstants.MinPupilEyelashAreaCombined)) :
                    // to check if whole of eyelash is detected as a contour
                    //its area is greater than the pupil, but less than the pupil+eyelash area
                    //(area < IrisConstants.MinPupilArea) :
                    //to check for very small detected contours

                    if (((AreaOfDetectedContour > IrisConstants.MaxPupilArea) && (AreaOfDetectedContour < IrisConstants.MinPupilEyelashAreaCombined)) || (AreaOfDetectedContour < IrisConstants.MinPupilArea))
                    {
                        //discard the contour and process the next
                        detectedContours = detectedContours.HNext;
                        continue;
                    }
                }


                if ((AreaOfDetectedContour > IrisConstants.MinPupilArea))
                {
                    double Pupilarea = AreaOfDetectedContour;

                    //Get the Center of the Pupil --> GetSpatialMoment ---> has the center of the detected contour
                    double x = moments.GetSpatialMoment(IrisConstants.One, IrisConstants.Zero) / AreaOfDetectedContour;
                    double y = moments.GetSpatialMoment(IrisConstants.Zero, IrisConstants.One) / AreaOfDetectedContour;

                    //Store it in PupilCenter
                    PupilCenter.X = (int)x;
                    PupilCenter.Y = (int)y;

                    //Store the contour detected image in ContourDetectedPupilImage
                    ContourDetectedPupilImage = InputImage.Clone();

                    //Filled one will have the pupil coloured black
                    FilledContourForSegmentation = InputImage.Clone();


                    //--------------------------------------------------------------------
                    //Create a color image and store the grayscale contour image and convert to color, then draw colored contour on this
                    //--------------------------------------------------------------------

                    CvInvoke.cvCvtColor(ContourDetectedPupilImage, ContourDetectedPupilImageColor, COLOR_CONVERSION.GRAY2BGR);

                    //Draw the contour over the pupil
                    // ContourDetectedPupilImage.Draw(detectedContours, new Gray(255), IrisConstants.Zero);

                    //Fill the center of the pupil black--> -1 indicates fill
                    FilledContourForSegmentation.Draw(detectedContours, new Gray(IrisConstants.Zero), -1);

                    //DRAW the Colored circle in red
                    ContourDetectedPupilImageColor.Draw(detectedContours, new Bgr(0, 0, 255), 2);


                    //If the eyebrow is detected then apply hough transform

                    if (AreaOfDetectedContour > IrisConstants.MinPupilEyelashAreaCombined)
                    {
                        //Draw the contour white
                        ContourDetectedPupilImageColor.Draw(detectedContours, new Bgr(255, 255, 255), 2);

                        //make the flag false
                        IsContourDetectionSatisfactory = false;

                        //Clone the image to apply hough transform
                        ApproximatedPupilImage = ContourDetectedPupilImage.Clone();

                        //Create image to store the approximated pupil
                        Image <Gray, Byte> ApproximatedPupilImageWithContrast = ApproximatedPupilImage.Clone();

                        //Contrast the image for histogram
                        ApproximatedPupilImageWithContrast._EqualizeHist();

                        //Perform Hough Trasform
                        PerformHoughTransform(ApproximatedPupilImageWithContrast,
                                              IrisConstants.HoughCircleThreshold, IrisConstants.MinPupilHoughCircleAccumulator, IrisConstants.MaxPupilHoughCircleAccumulator,
                                              IrisConstants.PupilHoughCircleResolution, IrisConstants.MinPupilHoughCircleDistance,
                                              IrisConstants.MinPupilHoughCircleRadius, IrisConstants.MaxPupilHoughCircleRadius, HoughTransformFlag.Pupil);
                    }
                    break;
                }
                detectedContours = detectedContours.HNext;
            }
        }