/////////////////////////////////////////////////////////////////////////////////
        ///
        /// Function Name: IVA_GetPoint
        ///
        /// Description  : Retrieves a point from the PointsResults array
        ///
        /// Parameters   : ivaData     -  Internal data structure
        ///                stepIndex   -  Index of the step that produced the point
        ///                pointIndex  -  Index of the x value.
        ///
        /// Return Value : point
        ///
        /////////////////////////////////////////////////////////////////////////////////
        public static PointContour IVA_GetPoint(IVA_Data ivaData, int stepIndex, int pointIndex)
        {
            PointContour point = new PointContour();

            if ((pointIndex + 1) < ivaData.stepResults[stepIndex].results.Count)
            {
                point.X = ivaData.stepResults[stepIndex].results[pointIndex].resultVal.numVal;
                point.Y = ivaData.stepResults[stepIndex].results[pointIndex + 1].resultVal.numVal;
            }
            return(point);
        }
        /////////////////////////////////////////////////////////////////////////////////
        ///
        /// Function Name: IVA_PushBuffer
        ///
        /// Description  : Stores an image in a buffer
        ///
        /// Parameters   : ivaData       -  Internal data structure
        ///                image         -  image
        ///                bufferNumber  -  Buffer index
        ///
        /// Return Value : success
        ///
        /////////////////////////////////////////////////////////////////////////////////
        public static void IVA_PushBuffer(IVA_Data ivaData, VisionImage image, int bufferNumber)
        {
            /// Release the previous image that was contained in the buffer
            ivaData.buffers[bufferNumber].Dispose();

            /// Creates an image buffer of the same type of the source image.
            ivaData.buffers[bufferNumber] = new VisionImage(image.Type, 7);

            /// Copies the image in the buffer.
            Algorithms.Copy(image, ivaData.buffers[bufferNumber]);
        }
        /////////////////////////////////////////////////////////////////////////////////
        ///
        /// Function Name: IVA_GetNumericResult
        ///
        /// Description  : Retrieves a numeric result value from the data manager.
        ///
        /// Parameters   : ivaData      -  Internal data structure
        ///                stepIndex    -  Index of the step that produced the result
        ///                resultIndex  -  result index.
        ///
        /// Return Value : numeric result value
        ///
        /////////////////////////////////////////////////////////////////////////////////
        public static double IVA_GetNumericResult(IVA_Data ivaData, int stepIndex, int resultIndex)
        {
            double value = 0;

            if (resultIndex < ivaData.stepResults[stepIndex].results.Count)
            {
                value = ivaData.stepResults[stepIndex].results[resultIndex].resultVal.numVal;
            }

            return(value);
        }
        public PaletteType ProcessImage(VisionImage image)
        {
            // Initialize the IVA_Data structure to pass results and coordinate systems.
            IVA_Data ivaData = new IVA_Data(7, 0);

            // Extract Color Plane
            using (VisionImage plane = new VisionImage(ImageType.U8, 7))
            {
                // Extract the red color plane and copy it to the main image.
                Algorithms.ExtractColorPlanes(image, ColorMode.Rgb, plane, null, null);
                Algorithms.Copy(plane, image);
            }

            // Filters: Convolution - Applies a linear filter to an image by convolving the image with a filtering kernel.
            double[] vaCoefficients = { 1, 2, 4, 2, 1, 2, 4, 8, 4, 2, 4, 8, 16, 8, 4, 2, 4, 8, 4, 2, 1, 2, 4, 2, 1 };
            Algorithms.Convolute(image, image, new Kernel(5, 5, vaCoefficients));

            // Filters: Convolution - Applies a linear filter to an image by convolving the image with a filtering kernel.
            double[] vaCoefficients2 = { -1, -1, -1, -1, 10, -1, -1, -1, -1 };
            Algorithms.Convolute(image, image, new Kernel(3, 3, vaCoefficients2));

            // Automatic Threshold
            Algorithms.AutoThreshold(image, image, 2, ThresholdMethod.Clustering);

            // Basic Morphology - Applies morphological transformations to binary images.
            int[] vaCoefficients3           = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            StructuringElement vaStructElem = new StructuringElement(7, 7, vaCoefficients3);

            vaStructElem.Shape = StructuringElementShape.Hexagon;
            // Applies morphological transformations
            Algorithms.Morphology(image, image, MorphologyMethod.Open, vaStructElem);

            // Lookup Table: Equalize
            // Calculates the histogram of the image and redistributes pixel values
            // accross the desired range to maintain the same pixel value distribution.
            Range equalizeRange = new Range(0, 255);

            if (image.Type != ImageType.U8)
            {
                equalizeRange.Maximum = 0;
            }
            Algorithms.Equalize(image, image, null, equalizeRange, null);

            // Creates a new, empty region of interest.
            Roi roi = new Roi();
            // Creates a new RectangleContour using the given values.
            RectangleContour vaRect = new RectangleContour(0, 0, image.Width, image.Height);

            roi.Add(vaRect);
            // Classifies all the objects located in the given ROI.
            string vaClassifierFilePath = "C:\\DATA\\#hasilscan2\\Ukuran Classifier.clf";

            vaClassifierReports = IVA_Classify(image, roi, vaClassifierFilePath);

            roi.Dispose();

            // Dispose the IVA_Data structure.
            ivaData.Dispose();

            // Return the palette type of the final image.
            return(PaletteType.Binary);
        }
 /////////////////////////////////////////////////////////////////////////////////
 ///
 /// Function Name: IVA_PopBuffer
 ///
 /// Description  : Retrieves an image from a buffer
 ///
 /// Parameters   : ivaData       -  Internal data structure
 ///                bufferNumber  -  Buffer index
 ///
 /// Return Value : success
 ///
 /////////////////////////////////////////////////////////////////////////////////
 public static VisionImage IVA_GetBuffer(IVA_Data ivaData, int bufferNumber)
 {
     return(ivaData.buffers[bufferNumber]);
 }
 /////////////////////////////////////////////////////////////////////////////////
 ///
 /// Function Name: IVA_DisposeStepResults
 ///
 /// Description  : Dispose of the results of a specific step.
 ///
 /// Parameters   : ivaData    -  Internal data structure
 ///                stepIndex  -  step index
 ///
 /// Return Value : success
 ///
 /////////////////////////////////////////////////////////////////////////////////
 public static void IVA_DisposeStepResults(IVA_Data ivaData, int stepIndex)
 {
     ivaData.stepResults[stepIndex].results.Clear();
 }