// Procedures
    public void ChangeDomainForRectangle(HObject ho_InputImage, out HObject ho_ImageResult,
                                         HTuple hv_LineStartPoint_Row, HTuple hv_LineStartPoint_Column, HTuple hv_LineEndPoint_Row,
                                         HTuple hv_LineEndPoint_Column, HTuple hv_RoiWidthLen, HTuple hv_DilationWidth,
                                         HTuple hv_DilationHeight)
    {
        // Local iconic variables

        HObject ho_Rectangle, ho_RegionDilation;


        // Local control variables

        HTuple hv_TmpCtrl_Row = null, hv_TmpCtrl_Column = null;
        HTuple hv_TmpCtrl_Dr = null, hv_TmpCtrl_Dc = null, hv_TmpCtrl_Phi = null;
        HTuple hv_TmpCtrl_Len1 = null, hv_TmpCtrl_Len2 = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_ImageResult);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);

        //Measure 01: Convert coordinates to rectangle2 type
        hv_TmpCtrl_Row    = 0.5 * (hv_LineStartPoint_Row + hv_LineEndPoint_Row);
        hv_TmpCtrl_Column = 0.5 * (hv_LineStartPoint_Column + hv_LineEndPoint_Column);
        hv_TmpCtrl_Dr     = hv_LineStartPoint_Row - hv_LineEndPoint_Row;
        hv_TmpCtrl_Dc     = hv_LineEndPoint_Column - hv_LineStartPoint_Column;
        hv_TmpCtrl_Phi    = hv_TmpCtrl_Dr.TupleAtan2(hv_TmpCtrl_Dc);
        hv_TmpCtrl_Len1   = 0.5 * ((((hv_TmpCtrl_Dr * hv_TmpCtrl_Dr) + (hv_TmpCtrl_Dc * hv_TmpCtrl_Dc))).TupleSqrt()
                                   );
        hv_TmpCtrl_Len2 = hv_RoiWidthLen.Clone();
        ho_Rectangle.Dispose();
        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_TmpCtrl_Row, hv_TmpCtrl_Column,
                                   hv_TmpCtrl_Phi, hv_TmpCtrl_Len1, hv_TmpCtrl_Len2);

        ho_RegionDilation.Dispose();
        HOperatorSet.DilationRectangle1(ho_Rectangle, out ho_RegionDilation, hv_DilationWidth,
                                        hv_DilationHeight);

        ho_ImageResult.Dispose();
        HOperatorSet.ChangeDomain(ho_InputImage, ho_RegionDilation, out ho_ImageResult
                                  );

        ho_Rectangle.Dispose();
        ho_RegionDilation.Dispose();

        return;
    }
예제 #2
0
    // Procedures
    public void EnhanceEdgeArea2(HObject ho_InputImage, out HObject ho_EnhancedImage,
                                 HTuple hv_LineStartPoint_Row, HTuple hv_LineStartPoint_Column, HTuple hv_LineEndPoint_Row,
                                 HTuple hv_LineEndPoint_Column, HTuple hv_RoiWidthLen, HTuple hv_EmpMaskWidth,
                                 HTuple hv_EmpMaskHeight, HTuple hv_EmpMaskFactor, HTuple hv_MeanMaskWidth, HTuple hv_MeanMaskHeight,
                                 HTuple hv_MinThresh, HTuple hv_MaxThresh)
    {
        // Local iconic variables

        HObject ho_Rectangle, ho_RegionDilation, ho_ReducedImage;
        HObject ho_ImageOpening = null, ho_EmphasizeImage, ho_ImageOpening2 = null;
        HObject ho_ImageMean;


        // Local control variables

        HTuple hv_TmpCtrl_Row = null, hv_TmpCtrl_Column = null;
        HTuple hv_TmpCtrl_Dr = null, hv_TmpCtrl_Dc = null, hv_TmpCtrl_Phi = null;
        HTuple hv_TmpCtrl_Len1 = null, hv_TmpCtrl_Len2 = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_EnhancedImage);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);
        HOperatorSet.GenEmptyObj(out ho_ReducedImage);
        HOperatorSet.GenEmptyObj(out ho_ImageOpening);
        HOperatorSet.GenEmptyObj(out ho_EmphasizeImage);
        HOperatorSet.GenEmptyObj(out ho_ImageOpening2);
        HOperatorSet.GenEmptyObj(out ho_ImageMean);

        //
        //init
        //FilterAlpha := 6
        //Measure 01: Convert coordinates to rectangle2 type
        hv_TmpCtrl_Row    = 0.5 * (hv_LineStartPoint_Row + hv_LineEndPoint_Row);
        hv_TmpCtrl_Column = 0.5 * (hv_LineStartPoint_Column + hv_LineEndPoint_Column);
        hv_TmpCtrl_Dr     = hv_LineStartPoint_Row - hv_LineEndPoint_Row;
        hv_TmpCtrl_Dc     = hv_LineEndPoint_Column - hv_LineStartPoint_Column;
        hv_TmpCtrl_Phi    = hv_TmpCtrl_Dr.TupleAtan2(hv_TmpCtrl_Dc);
        hv_TmpCtrl_Len1   = 0.5 * ((((hv_TmpCtrl_Dr * hv_TmpCtrl_Dr) + (hv_TmpCtrl_Dc * hv_TmpCtrl_Dc))).TupleSqrt()
                                   );
        hv_TmpCtrl_Len2 = hv_RoiWidthLen.Clone();
        ho_Rectangle.Dispose();
        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_TmpCtrl_Row, hv_TmpCtrl_Column,
                                   hv_TmpCtrl_Phi, hv_TmpCtrl_Len1, hv_TmpCtrl_Len2);

        ho_RegionDilation.Dispose();
        HOperatorSet.DilationRectangle1(ho_Rectangle, out ho_RegionDilation, 20, 20);

        ho_ReducedImage.Dispose();
        HOperatorSet.ReduceDomain(ho_InputImage, ho_RegionDilation, out ho_ReducedImage
                                  );

        if ((int)(new HTuple(hv_EmpMaskWidth.TupleLess(hv_EmpMaskHeight))) != 0)
        {
            ho_ImageOpening.Dispose();
            HOperatorSet.GrayOpeningRect(ho_ReducedImage, out ho_ImageOpening, 3, 7);
        }
        else
        {
            ho_ImageOpening.Dispose();
            HOperatorSet.GrayOpeningRect(ho_ReducedImage, out ho_ImageOpening, 7, 3);
        }

        ho_EmphasizeImage.Dispose();
        HOperatorSet.Emphasize(ho_ImageOpening, out ho_EmphasizeImage, hv_EmpMaskWidth,
                               hv_EmpMaskHeight, hv_EmpMaskFactor);

        if ((int)(new HTuple(hv_EmpMaskWidth.TupleLess(hv_EmpMaskHeight))) != 0)
        {
            ho_ImageOpening2.Dispose();
            HOperatorSet.GrayOpeningRect(ho_EmphasizeImage, out ho_ImageOpening2, 3, 7);
        }
        else
        {
            ho_ImageOpening2.Dispose();
            HOperatorSet.GrayOpeningRect(ho_EmphasizeImage, out ho_ImageOpening2, 7, 3);
        }


        ho_ImageMean.Dispose();
        HOperatorSet.MeanSp(ho_ImageOpening2, out ho_ImageMean, hv_MeanMaskWidth, hv_MeanMaskHeight,
                            hv_MinThresh, hv_MaxThresh);

        if ((int)(new HTuple(hv_EmpMaskWidth.TupleLess(hv_EmpMaskHeight))) != 0)
        {
            ho_EnhancedImage.Dispose();
            HOperatorSet.GrayOpeningRect(ho_ImageMean, out ho_EnhancedImage, 3, 7);
        }
        else
        {
            ho_EnhancedImage.Dispose();
            HOperatorSet.GrayOpeningRect(ho_ImageMean, out ho_EnhancedImage, 7, 3);
        }


        ho_Rectangle.Dispose();
        ho_RegionDilation.Dispose();
        ho_ReducedImage.Dispose();
        ho_ImageOpening.Dispose();
        ho_EmphasizeImage.Dispose();
        ho_ImageOpening2.Dispose();
        ho_ImageMean.Dispose();

        return;
    }
예제 #3
0
    // Procedures
    public void EnhanceEdgeArea(HObject ho_InputImage, out HObject ho_EnhancedImage,
                                HTuple hv_LineStartPoint_Row, HTuple hv_LineStartPoint_Column, HTuple hv_LineEndPoint_Row,
                                HTuple hv_LineEndPoint_Column, HTuple hv_RoiWidthLen, HTuple hv_EmpMaskWidth,
                                HTuple hv_EmpMaskHeight, HTuple hv_EmpMaskFactor, HTuple hv_MeanMaskWidth, HTuple hv_MeanMaskHeight,
                                HTuple hv_IterationCount, HTuple hv_MinGray, HTuple hv_MaxGray, HTuple hv_Grayval,
                                HTuple hv_ClosingWidth, HTuple hv_ClosingHeight, HTuple hv_DilationRadius)
    {
        // Stack for temporary objects
        HObject[] OTemp = new HObject[20];

        // Local iconic variables

        HObject ho_Rectangle, ho_RegionDilation, ho_MeanImage = null;
        HObject ho_ImageEmphasize = null, ho_Seg, ho_ConnectedRegions;
        HObject ho_SelectedRegions, ho_RegionClosing, ho_RegionBorder;
        HObject ho_RegionBorder2;


        // Local control variables

        HTuple hv_TmpCtrl_Row = null, hv_TmpCtrl_Column = null;
        HTuple hv_TmpCtrl_Dr = null, hv_TmpCtrl_Dc = null, hv_TmpCtrl_Phi = null;
        HTuple hv_TmpCtrl_Len1 = null, hv_TmpCtrl_Len2 = null;
        HTuple hv_Index = null;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_EnhancedImage);
        HOperatorSet.GenEmptyObj(out ho_Rectangle);
        HOperatorSet.GenEmptyObj(out ho_RegionDilation);
        HOperatorSet.GenEmptyObj(out ho_MeanImage);
        HOperatorSet.GenEmptyObj(out ho_ImageEmphasize);
        HOperatorSet.GenEmptyObj(out ho_Seg);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        HOperatorSet.GenEmptyObj(out ho_RegionClosing);
        HOperatorSet.GenEmptyObj(out ho_RegionBorder);
        HOperatorSet.GenEmptyObj(out ho_RegionBorder2);

        //
        //init
        //FilterAlpha := 6
        //Measure 01: Convert coordinates to rectangle2 type
        hv_TmpCtrl_Row    = 0.5 * (hv_LineStartPoint_Row + hv_LineEndPoint_Row);
        hv_TmpCtrl_Column = 0.5 * (hv_LineStartPoint_Column + hv_LineEndPoint_Column);
        hv_TmpCtrl_Dr     = hv_LineStartPoint_Row - hv_LineEndPoint_Row;
        hv_TmpCtrl_Dc     = hv_LineEndPoint_Column - hv_LineStartPoint_Column;
        hv_TmpCtrl_Phi    = hv_TmpCtrl_Dr.TupleAtan2(hv_TmpCtrl_Dc);
        hv_TmpCtrl_Len1   = 0.5 * ((((hv_TmpCtrl_Dr * hv_TmpCtrl_Dr) + (hv_TmpCtrl_Dc * hv_TmpCtrl_Dc))).TupleSqrt()
                                   );
        hv_TmpCtrl_Len2 = hv_RoiWidthLen.Clone();
        ho_Rectangle.Dispose();
        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_TmpCtrl_Row, hv_TmpCtrl_Column,
                                   hv_TmpCtrl_Phi, hv_TmpCtrl_Len1, hv_TmpCtrl_Len2);

        ho_RegionDilation.Dispose();
        HOperatorSet.DilationRectangle1(ho_Rectangle, out ho_RegionDilation, 100, 100);

        ho_EnhancedImage.Dispose();
        HOperatorSet.ReduceDomain(ho_InputImage, ho_RegionDilation, out ho_EnhancedImage
                                  );

        HTuple end_val17  = hv_IterationCount;
        HTuple step_val17 = 1;

        for (hv_Index = 1; hv_Index.Continue(end_val17, step_val17); hv_Index = hv_Index.TupleAdd(step_val17))
        {
            ho_MeanImage.Dispose();
            HOperatorSet.MeanImage(ho_EnhancedImage, out ho_MeanImage, hv_MeanMaskWidth,
                                   hv_MeanMaskHeight);
            ho_ImageEmphasize.Dispose();
            HOperatorSet.Emphasize(ho_MeanImage, out ho_ImageEmphasize, hv_EmpMaskWidth,
                                   hv_EmpMaskHeight, hv_EmpMaskFactor);
            ho_EnhancedImage.Dispose();
            HOperatorSet.MeanImage(ho_ImageEmphasize, out ho_EnhancedImage, 2, 2);
            //median_separate (ImageEmphasize, EnhancedImage, MeanMaskWidth, MeanMaskHeight, 'continued')
        }


        ho_Seg.Dispose();
        HOperatorSet.FastThreshold(ho_EnhancedImage, out ho_Seg, hv_MinGray, hv_MaxGray,
                                   150);
        ho_ConnectedRegions.Dispose();
        HOperatorSet.Connection(ho_Seg, out ho_ConnectedRegions);
        ho_SelectedRegions.Dispose();
        HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, "area",
                                 "and", 1000, 9999999);
        //opening_rectange1(SelectedRegions, RegionOpening, ClosingWidth, ClosingHeight)
        ho_RegionClosing.Dispose();
        HOperatorSet.ClosingRectangle1(ho_SelectedRegions, out ho_RegionClosing, hv_ClosingWidth,
                                       hv_ClosingHeight);

        ho_RegionBorder.Dispose();
        HOperatorSet.Boundary(ho_RegionClosing, out ho_RegionBorder, "inner");
        ho_RegionDilation.Dispose();
        HOperatorSet.DilationCircle(ho_RegionClosing, out ho_RegionDilation, hv_DilationRadius);
        ho_RegionBorder2.Dispose();
        HOperatorSet.Boundary(ho_RegionDilation, out ho_RegionBorder2, "inner");


        HOperatorSet.PaintRegion(ho_RegionDilation, ho_EnhancedImage, out OTemp[0], hv_Grayval,
                                 "fill");
        ho_EnhancedImage.Dispose();
        ho_EnhancedImage = OTemp[0];
        //region_to_bin (RegionDilation, EnhancedImage, 255, 0, 512, 512)

        ho_Rectangle.Dispose();
        ho_RegionDilation.Dispose();
        ho_MeanImage.Dispose();
        ho_ImageEmphasize.Dispose();
        ho_Seg.Dispose();
        ho_ConnectedRegions.Dispose();
        ho_SelectedRegions.Dispose();
        ho_RegionClosing.Dispose();
        ho_RegionBorder.Dispose();
        ho_RegionBorder2.Dispose();

        return;
    }