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

Measurement limits

Hi Yuri,
I tried to include your code in my macro unsuccessfully
Here my code ( a part of it)
Note ImHem is a McImage  istance of current image (ImHem =ThisApplication.ActiveImage) 
1° Load setting file (it works fine)
    '----------------------------------------------------------------------
    ' Load settings
    '----------------------------------------------------------------------
    With Measure.Measurements.OptionsCommands.Open(Nothing)
        .FileName = stPercorsoMorpho        '"C:\App_Iec\HistoCnt\Impostazioni\morpho.iqo"
        .FilterIndex = 1
        .Run(ImHem)
    End With
2° Set the Threshold (it works fine too)

    '----------------------------------------------------------------------
    ' Set Threshold
    '----------------------------------------------------------------------
    Dim Ranges(2) As Double
    Ranges(0)=255.0 * dSogliaMorpho  '<- this is a local varaible (Double)
    If Ranges(0)<0 Or Ranges(0)>255 Then
        Ranges(0)=20
    End If
    Ranges(1)=255
    '----------------------------------------------------------------------
    With Measure.ThresholdToolCommands.Thresholds(Nothing)
        .AllowOverlap = False
        .Interpretation = eInterpretation.Mono
        .Classes = New System.Collections.Generic.List(Of SegmentationClass)
        .Classes.Add(New SegmentationClass("Totali",System.Drawing.Color.Green,New Double(){Ranges(0),Ranges(1)}))
        .Run(ImHem)
    End With
3° count objects - No limit (it works fine )
    '----------------------------------------------------------------------
    ' eseguo conta
    '----------------------------------------------------------------------
    With Measure.MeasurementsCommands.Options(Nothing)
        .ActiveClass = 2        ' totali
        .Run(Nothing)
    End With
    With Measure.MeasurementsCommands.ExecuteCount(Nothing)
        .Run(ImHem)
    End With
4° Filter objects ( no results) '---------------------------------------------------------------------- ' Set limits '----------------------------------------------------------------------
    With Measure.MeasurementsCommands.ApplyFilters(Nothing)
        .Run(ImHem)
    End With
    Dim dMaxValore As Double = 100000000.0
    With Measure.MeasurementsCommands.Options(Nothing)
        .Segmentation.ApplyFilters=True
        .Segmentation.FilterRanges.Add( New MeasFilterEntry(eMeasures.RgnArea,dAreaMin,dMaxValore))
        .Segmentation.FilterRanges.Add( New MeasFilterEntry(eMeasures.RgnMaxDiameter,dDiamMin,dMaxValore))
        .Run(ImHem)
    End With

NOTE dAreaMin & dDiamMin are double varaibles and they are filled with the right values.
I tried to move ApplyFilters  after the filter limits setting w/o results
I added all the reference DLL (no error) but the filter operation doesn't produce any effect on the conted objects As you can see I put the filter procedure after the object count, I have tried to set filter also before the object count but nothing changes. where I am wrong? Grazie Maurizio

Answers

  • Hi Maurizio,

    You missed one line from my example:

    With Measure.MeasurementsCommands.Options(SetRanges)
                .Segmentation.ApplyFilters = True
                .Segmentation.FilterRanges = New System.Collections.Generic.List(Of MeasFilterEntry)
                    .Segmentation.FilterRanges.Add( New MeasFilterEntry(eMeasures.RgnArea,201.150999790646R,792.57957015754R))
                .Run(doc1)
            End With
    
    And you do have to execute Count or Apply filters after that.

    Yuri
Sign In or Register to comment.