示例#1
0
    // Procedures
    public void GetRegionByGrayInvert(HObject ho_Image, out HObject ho_FoundRegion,
                                      HTuple hv_MeanMaskWidth, HTuple hv_MeanMaskHeight, HTuple hv_EmpMaskWidth, HTuple hv_EmpMaskHeight,
                                      HTuple hv_EmpFactor1, HTuple hv_EmpFactor2, HTuple hv_ThresholdMinGray, HTuple hv_ThresholdMaxGray,
                                      HTuple hv_AreaMin, HTuple hv_AreaMax)
    {
        // Local iconic variables

        HObject ho_ImageMean, ho_ImageEmphasize, ho_ImageInvert;
        HObject ho_ImageAbsDiff, ho_ImageEmphasize2, ho_Areas, ho_ConnectedRegions1;
        HObject ho_RegionFillUp, ho_SelectedRegions;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_FoundRegion);
        HOperatorSet.GenEmptyObj(out ho_ImageMean);
        HOperatorSet.GenEmptyObj(out ho_ImageEmphasize);
        HOperatorSet.GenEmptyObj(out ho_ImageInvert);
        HOperatorSet.GenEmptyObj(out ho_ImageAbsDiff);
        HOperatorSet.GenEmptyObj(out ho_ImageEmphasize2);
        HOperatorSet.GenEmptyObj(out ho_Areas);
        HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
        HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
        HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
        //extract and enhance edges

        ho_ImageMean.Dispose();
        HOperatorSet.MeanSp(ho_Image, out ho_ImageMean, hv_MeanMaskHeight, hv_MeanMaskWidth,
                            1, 254);

        ho_ImageEmphasize.Dispose();
        HOperatorSet.Emphasize(ho_ImageMean, out ho_ImageEmphasize, hv_EmpMaskWidth,
                               hv_EmpMaskHeight, hv_EmpFactor1);

        ho_ImageInvert.Dispose();
        HOperatorSet.InvertImage(ho_ImageEmphasize, out ho_ImageInvert);
        ho_ImageAbsDiff.Dispose();
        HOperatorSet.AbsDiffImage(ho_ImageEmphasize, ho_ImageInvert, out ho_ImageAbsDiff,
                                  1);

        ho_ImageEmphasize2.Dispose();
        HOperatorSet.Emphasize(ho_ImageAbsDiff, out ho_ImageEmphasize2, hv_EmpMaskWidth,
                               hv_EmpMaskHeight, hv_EmpFactor2);

        //extract regions
        ho_Areas.Dispose();
        HOperatorSet.Threshold(ho_ImageEmphasize2, out ho_Areas, hv_ThresholdMinGray,
                               hv_ThresholdMaxGray);
        ho_ConnectedRegions1.Dispose();
        HOperatorSet.Connection(ho_Areas, out ho_ConnectedRegions1);
        ho_RegionFillUp.Dispose();
        HOperatorSet.FillUp(ho_ConnectedRegions1, out ho_RegionFillUp);

        //select region
        ho_SelectedRegions.Dispose();
        HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions, "area", "and",
                                 hv_AreaMin, hv_AreaMax);
        ho_FoundRegion.Dispose();
        HOperatorSet.MoveRegion(ho_SelectedRegions, out ho_FoundRegion, 0, 0);

        ho_ImageMean.Dispose();
        ho_ImageEmphasize.Dispose();
        ho_ImageInvert.Dispose();
        ho_ImageAbsDiff.Dispose();
        ho_ImageEmphasize2.Dispose();
        ho_Areas.Dispose();
        ho_ConnectedRegions1.Dispose();
        ho_RegionFillUp.Dispose();
        ho_SelectedRegions.Dispose();

        return;
    }