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

Add measurement conditions

Hi,
We developed a macro on IP-10 version 10.0.10

How can I add other conditions to the existing [Selected Measurement/Filters].

Because the macro will use [New System.Collections.Generic.List(Of MeasFilterEntry)] to create a new filter, I need to add a new one to the old condition.

        With Measure.MeasurementsCommands.Options(NewMacro)
            .SelMeasurements = New MeasCollection()
                .SelMeasurements.Add( New MeasEntry(eMeasures.RgnArea))
            .Segmentation.FilterRanges = New System.Collections.Generic.List(Of MeasFilterEntry)
                .Segmentation.FilterRanges.Add( New MeasFilterEntry(eMeasures.RgnArea,0R,20R))
            .Run(doc1)
        End With


Thanks!



Answers

  • Hi Kyle1996,

    The easiest way is to record a macro where you define multiple filters, so you will see the code and can edit it, if necessary.

    But I would recommend you using IQO file to restore all your measurements filters and other measurement options., such as segmentation thresholds or recipe Just set all your options and filters, save the measurement options to an IQO file, then activate recording and load IQO file and click the Count and use that macro for you analysis.

    You can check this video that demonstrates using of IQO files in macros https://youtu.be/GytLqW3mXxE

    Regards,

    Yuri
  • Hi YuriG
    Thank you for your reply

    I provided the [iqo] option on the user interface,


    But now I want to add the filter condition of [area] to the existing condition when I press the button.

    Is there any way to achieve it?


    Thanks!



  • Ok, if you just want to set filter ranges dynamically, then you can use your existing macro and set Min/Max from variables:

        Public MinArea As Double=0
        Public MaxArea As Double=50
    
        Public Sub SetNewRanges
            With Measure.MeasurementsCommands.Options(Nothing)
                .SelMeasurements = New MeasCollection()
                    .SelMeasurements.Add( New MeasEntry(eMeasures.RgnArea))
                .Segmentation.FilterRanges = New System.Collections.Generic.List(Of MeasFilterEntry)
                    .Segmentation.FilterRanges.Add( New MeasFilterEntry(eMeasures.RgnArea,MinArea,MaxArea))
                .Run(ThisApplication.ActiveImage)
            End With
        End Sub
    

    where you set MinArea and MaxArea from your code and then call SetNewRanges.

    Yuri

  • Hi YuriG
    Thank you for your reply

    But, I use this code, the old conditions will be cleared.




     I want to keep the old [IQO] file filter content.
    and
     When I press the button, the condition of [area] will be added.



    Is there any way to achieve it?

    Thanks!

  • Ok, now I understand what you need. Yes, it's possible, here is the code:

        Public MinArea As Double=35
        Public MaxArea As Double=1E+308
    
        Public Sub SetNewAreaRanges
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData = im.MeasurementsData
            Dim mArea As MeasEntry = New MeasEntry(eMeasures.RgnArea)
            With md.Options.Segmentation
                Dim f As MeasFilterEntry
                If .FilterRanges.ContainsKey(mArea.CombinedName) Then
                    'modify existing range
                    f = .FilterRanges(mArea.CombinedName)
                    f.RangeStart = MinArea
                    f.RangeEnd = MaxArea
                End If
            End With
        End Sub
    

    Yuri
  • Hi YuriG
    Thank you for your reply

    I try the code you suggested.
             If .FilterRanges.ContainsKey(mArea.CombinedName) Then
                    f = .FilterRanges(mArea.CombinedName)
                    f.RangeStart = MinArea
                    f.RangeEnd = MaxArea
             End If
    But,in this paragraph 【.FilterRanges.ContainsKey(mArea.CombinedName)】judgment formula.
    Because I haven’t added a [area] condition yet, it will always be in [False] state.

    And I try 【.Options.SelMeasurements.Add( New MeasEntry(eMeasures.RgnArea))】when there is no [area] item.
                If .FilterRanges.ContainsKey(mArea.CombinedName) Then
                    f = .FilterRanges(mArea.CombinedName)
                    f.RangeStart = MinArea
                    f.RangeEnd = MaxArea
                Else
                    md.Options.SelMeasurements.Add( New MeasEntry(eMeasures.RgnArea))
                End If
    Can add [area] item, but it is in [unchecked] state.
    So,【.FilterRanges.ContainsKey(mArea.CombinedName)】judgment formula still [False].
    How can I let it in [checked] state ?



    This is the event I want. (like this picture)
    Is there a better way to achieve?



    Thanks!
  • Hi YuriG
    I adjusted a part,and that works.
                If .FilterRanges.ContainsKey(mArea.CombinedName) Then
                    f = .FilterRanges(mArea.CombinedName)
                    f.RangeStart = MinArea
                    f.RangeEnd = MaxArea
                Else
                    md.Options.SelMeasurements.Add(New MeasEntry(eMeasures.RgnArea))
                    md.Options.Segmentation.FilterRanges.Add(mArea.CombinedName, New MeasFilterEntry(eMeasures.RgnArea,MinArea,MaxArea))
                End If

    Thanks for your help !
  • Yes, that's the right code, when your IQO file doesn't contain Area measurement.

    Yuri

Sign In or Register to comment.