Home Image-Pro Automation (Macros, Apps, Reports)
Options

CREATE CIRCULAR MEASUREMENT OBJECT WITH HOLE . . .

2022-06-29-160135

All --

The IPX FILE attached to this QUESTION will create an IMAGE-PRO IMAGE with TWO CIRCULAR MEASUREMENTS / FEATURES as illustrated here.

 
I would like to alter the CODE in the IPX FILE so that the SMALLER CIRCULAR MEASUREMENT / FEATURE is a HOLE in the LARGER CIRCULAR MEASUREMENT FEATURE.

This is illustrated here by measuring this BRIGHT RING.

These images illustrate that in the first image, the LARGE CIRCLE is about 100,000 SQ PIX in AREA and the SMALL CIRCLE is approximately 12,000 SQ PIX.  The RING is approximately 100,000 - 12,000 = 88,000 SQ PIX in AREA.

What change needs to be made to the CODE

        With Measure.MeasurementsCommands.Add(NewMacro)
            .MeasurementType = McMeasurements.enumMMSTypes.mmtsCircle
            .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
            .Points.Add(New System.Drawing.PointF(239.4515F,237.3418F))
            .Points.Add(New System.Drawing.PointF(124.5977F,28.30075F))
            .FeatureName = "C2"
            .SnapFeature = False
            .Run(image1, meas2)
        End With

so it will create a CIRCULAR HOLE and the resulting image will have one RING with an AREA of approximately 88,000 SQ PIX?

Thanks in advance.

-- Matt

Best Answer

  • Options
    Answer ✓
    Hi Matt,

    It's not possible to draw measurement object with a hole in a macro. You can use other way: draw 2 circular ROI's, activate XOR mode and execute Count with whole range.
    Here is the macro:

        Public Function AddObjectWithHole() As SimpleScript
            AddObjectWithHole = New SimpleScript
            Dim image1, doc1
    
            With Application.DocumentCommands.ActiveImage(AddObjectWithHole)
                .Run(image1)
            End With
    
            With [Select].RoiCommands.Add(AddObjectWithHole)
                .ROIType = Features.ROI.ROITypes.Circle
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                .Points.Add(New System.Drawing.PointF(48F,56F))
                .Points.Add(New System.Drawing.PointF(49.67897F,49.67897F))
                .Angle = 0R
                .Run(image1)
            End With
    
            With [Select].RoiCommands.Add(AddObjectWithHole)
                .ROIType = Features.ROI.ROITypes.Circle
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
                .Points.Add(New System.Drawing.PointF(47F,56F))
                .Points.Add(New System.Drawing.PointF(21.26029F,21.26029F))
                .Angle = 0R
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Define(AddObjectWithHole)
                .Run(image1, doc1)
            End With
    
            With [Select].RoiCommands.XORROIs(AddObjectWithHole)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Run(doc1)
            End With
    
            With [Select].RoiCommands.ShowMask(AddObjectWithHole)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Overlay = Overlays.OverlayType.ROIOverlay
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.Options(AddObjectWithHole)
                .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual
                .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
                .Run(doc1)
            End With
    
            With Measure.ThresholdToolCommands.Thresholds(AddObjectWithHole)
                .AllowOverlap = False
                .Interpretation = eInterpretation.Mono
                .Classes = New System.Collections.Generic.List(Of SegmentationClass)
                .Classes.Add(New SegmentationClass("Class 1",System.Drawing.Color.Blue,New Double(){0R,255R}))
                .Run(image1)
            End With
    
            With Measure.MeasurementsCommands.ExecuteCount(AddObjectWithHole)
                .Run(doc1)
            End With
    
            With [Select].RoiCommands.DeleteAll(AddObjectWithHole)
                .Run(doc1)
            End With
    
        End Function
    

    Regards,

    Yuri

Answers

  • Options
    2022-06-30-171024

    Yuri --

    Thank you for your guidance on this.

    I copied your

    Function AddObjectWithHole()

    into my

        FORUM-QUESTION.ipx

    PROJECT FILE.

    The PROJECT would not load until I added REFERENCES as shown here

    and added IMPORTS to the IPP FILE as shown here

    After that, the PROJECT did LOAD but running

        AddObjectWithHole

    Did not generate the results expected.

    I created an "AddObjectWithHole2" from "AddObjectWithHole" and did a bit of tweaking so that after running

        NewMacro
        and
        AddObjectWithHole2 (below)

    the result is an image with a MEASUREMENT OBJECT with the same proper boundaries and AREA MEASUREMENT of approximately 88,000 SQ PIX from above.  The result of running

        NewMacro
        +
        AddObjectWithHole2

    is shown here


    The CODE that needed to be modified to make "AddObjectWithHole2" work with the IMAGE from "NewMacro" is COMMENTED OUT and followed immediately by the 2 CODE.

    Oops . . .

    I almost forgot to mention that I needed to set the

        MEASUREMENT OPTIONS
        +
        CLEAN BORDERS OPTION = NONE

    I have posted all of this for the folks that may find this example helpful.

    Thank you very much for your assistance.

    -- Matt

        Public Function AddObjectWithHole2() As SimpleScript
            AddObjectWithHole2 = New SimpleScript
            Dim image1, doc1
    
            With Application.DocumentCommands.ActiveImage(AddObjectWithHole2)
                .Run(image1)
            End With
    
            With [Select].RoiCommands.Add(AddObjectWithHole2)
                .ROIType = Features.ROI.ROITypes.Circle
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
    '            .Points.Add(New System.Drawing.PointF(48F,56F))
    '            .Points.Add(New System.Drawing.PointF(49.67897F,49.67897F))
                .Points.Add(New System.Drawing.PointF(238.3966F,243.6709F))
                .Points.Add(New System.Drawing.PointF(356.7896F,356.7896F))
                .Angle = 0R
                .Run(image1)
            End With
    
            With [Select].RoiCommands.Add(AddObjectWithHole2)
                .ROIType = Features.ROI.ROITypes.Circle
                .Points = New System.Collections.Generic.List(Of System.Drawing.PointF)
    '            .Points.Add(New System.Drawing.PointF(47F,56F))
    '            .Points.Add(New System.Drawing.PointF(21.26029F,21.26029F))
                .Points.Add(New System.Drawing.PointF(239.4515F,237.3418F))
                .Points.Add(New System.Drawing.PointF(124.5977F,124.5977F))
                .Angle = 0R
                .Run(image1)
            End With
    
            With Application.DocumentCommands.Define(AddObjectWithHole2)
                .Run(image1, doc1)
            End With
    
            With [Select].RoiCommands.XORROIs(AddObjectWithHole2)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Run(doc1)
            End With
    
            With [Select].RoiCommands.ShowMask(AddObjectWithHole2)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Overlay = Overlays.OverlayType.ROIOverlay
                .Run(doc1)
            End With
    
            With Measure.MeasurementsCommands.Options(AddObjectWithHole2)
                .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual
                .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
                .Run(doc1)
            End With
    
            With Measure.ThresholdToolCommands.Thresholds(AddObjectWithHole2)
                .AllowOverlap = False
                .Interpretation = eInterpretation.Mono
                .Classes = New System.Collections.Generic.List(Of SegmentationClass)
    '            .Classes.Add(New SegmentationClass("Class 1",System.Drawing.Color.Blue,New Double(){0R,255R}))
                .Classes.Add(New SegmentationClass("Class 1",System.Drawing.Color.Blue,New Double(){0R,65280R}))
                .Run(image1)
            End With
    
            With Measure.MeasurementsCommands.ExecuteCount(AddObjectWithHole2)
                .Run(doc1)
            End With
    
            With [Select].RoiCommands.DeleteAll(AddObjectWithHole2)
                .Run(doc1)
            End With
    
        End Function
    









  • Options
    Hi Matt,

    Glad that you made it worke and figured out missing references!

    Yuri
  • Options
    2022-07-01-145025

    Yuri --

    I just keep saying

        WHAT WOULD YURI DO?

    ; - )

    -- Matt


Sign In or Register to comment.