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

How can CODE access the TRESHOLD VALUES set by a USER ithe THRESHOLD DIALOG BOX?

All --

I have modified the

    Function SetThreshold

posted by YURI during AUG-2014 in response to a query by STCB to be

Public Sub TestThresDrk ()

        Dim doc1

        With Measure.ThresholdTool.Gadgets.Histogram(Nothing)
            .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
            .Run()
        End With

        With Application.DocumentCommands.Active(Nothing)
            .Run(doc1)
        End With

        With Measure.MeasurementsCommands.Options(Nothing)
            .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpDarkest
            .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
            .Run(doc1)
        End With

        With Measure.ThresholdToolCommands.Thresholds(Nothing)
            .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,20R}))
            .Prompt = "Please adjust threshold."
            .Interactive = True
            .Run(doc1)
        End With

        With Measure.ThresholdTool.Gadgets.Histogram(Nothing)
            .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Unchecked
            .Run()
        End With

End Sub


Public Sub TestThresMan ()

        Dim doc1

        With Measure.ThresholdTool.Gadgets.Histogram(Nothing)
            .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
            .Run()
        End With

        With Application.DocumentCommands.Active(Nothing)
            .Run(doc1)
        End With

        With Measure.MeasurementsCommands.Options(Nothing)
            .Segmentation.AutoFindPhase = MediaCy.IQL.Features.mcFindPhase.mcfpManual
            .Segmentation.SegmentationType = McMMOptions.mcmmSegmentationType.mcmmstThresholdSegmentation
            .Run(doc1)
        End With

        With Measure.ThresholdToolCommands.Thresholds(Nothing)
            .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,20R}))
            .Prompt = "Please adjust threshold."
            .Interactive = True
            .Run(doc1)
        End With

        With Measure.ThresholdTool.Gadgets.Histogram(Nothing)
            .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Unchecked
            .Run()
        End With

End Sub

Where I can call

    TestThresDrk

when I want the USER to start "fresh" with an AUTODARK THRESHOLD and I can call

    TestThresMan

when I want the USER to start with the CURRENT THRESHOLD.

???

How do I access the THRESHOLD VALUES that are set by the user so that I can report these in the DATA FILE?

Thanks.

-- Matt

Best Answers

  • edited June 2015 Answer ✓

    Matt,

    The Threshold commands reads current parameters when initialized, so you can get the values using the macro like this:

        Public Sub PrintCurrentThresholds
            With Measure.ThresholdToolCommands.Thresholds(Nothing)
                For Each cl As SegmentationClass In .Classes
                    Debug.Print cl.Channels(0).ThresholdMin & ", " & cl.Channels(0).ThresholdMax
                Next
            End With
        End Sub
    Regards,

    Yuri
  • Answer ✓
    Yes, if you need just one property of the command, you can call it without "With":

    Debug.Print Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMin

    Yuri

Answers

  • Yuri --

    Thank you for the reply and the SAMPLE CODE.

    The code accesses the THRESHOLDMIN and THRESHOLDMAX values that I'm looking for so this will show ANSWERED.

    Additional information please . . . 

    If I know I just have one class, is there a simpler version of this?

    When I try to do this with a single command, I do not see the

        THRESHOLDMIN
        THRESHOLDMAX
        or
        CLASSES

    PROPERTY for

        Measure.ThresholdToolCommands.Thresholds
        or
        Measure.ThresholdToolCommands.Thresholds.Thresholds   

    and I don't see

        Measure.ThresholdToolCommands.Thresholds.SegmentationClass
        Measure.ThresholdToolCommands.Thresholds.Classes
        or   
        Measure.ThresholdToolCommands.Thresholds.Channels

    THRESHOLDMIN seems to be only documented in AUTOMATION HELP as a property of

    ThresholdMin Property

    and I don't see SEGMENTATIONCHANNEL as a PROPERTY of

        Measure.ThresholdTool
        or
        Measure.ThresholdToolCommands

    Thanks again.

    -- Matt

  • edited June 2015
    Matt,

    SegmentationChannel is exposed in the collection of Channels of SegmentationClass: 


    If you have only 1 class and only 1 channel, you can use:

        Public Sub PrintCurrentThresholds
            With Measure.ThresholdToolCommands.Thresholds(Nothing)
                Debug.Print .Classes(0).Channels(0).ThresholdMin
            End With
        End Sub
    or even 

        Public Sub PrintCurrentThresholds
             Debug.Print Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMin
        End Sub
    

    Yuri
  • Yuri --

    Thank you for the NEW CODE.

    It does the job without the loop.

    I don't understand why 

            With Measure.ThresholdToolCommands.Thresholds(Nothing)
                Debug.Print .Classes(0).Channels(0).ThresholdMin
            End With
    cannot be replaced with
    Debug.Print Measure.ThresholdToolCommands.Thresholds.Classes(0).Channels(0).ThresholdMin
    or maybe
    Debug.Print Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMin
    Thanks.

    -- Matt



  • Yuri --

    Thank you for your reply on 20-JUN.

    I've been working on other sections of this project and have just implemented your suggested SINGLE STATEMENT version of the CODE to access the THRESHOLD VALUES.

    In my code I have

                'Update the dialog box
                 textBox_Layer03ThresholdMin.Text = _
                     Str(Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMin)
                 textBox_Layer03ThresholdMax.Text = _
                     Str(Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMax)
    and it does just what is needed.

    Thanks again.

    -- Matt
  • All --

    I've revised the CODE above to take out the BLANK that precedes the THRESHOLD. 

                'Update the dialog box
                 textBox_Layer03ThresholdMin.Text = _
                     Trim(Str(Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMin))
                 textBox_Layer03ThresholdMax.Text = _
                     Trim(Str(Measure.ThresholdToolCommands.Thresholds(Nothing).Classes(0).Channels(0).ThresholdMax))
     
    This makes it a bit easier to EDIT / set the THRESHOLD using the TEXT BOX using

            Try
    
                    If ( ( MyThresholdTextMin = "" ) And ( MyThresholdTextMax = "" ) ) _
                        Then
    
                            With Measure.ThresholdToolCommands.Thresholds(Nothing)
                                .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,20R}))
                                .Prompt = "Please adjust threshold."
                                .Interactive = True
                                .Run(ThisApplication.ActiveDocument)
                            End With
    
                        Else
    
                            With Measure.ThresholdToolCommands.Thresholds(Nothing)
                                .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() _
                                    { _
                                    Val(MyThresholdTextMin), _
                                    Val(MyThresholdTextMax) _
                                    }))
                                .Prompt = "Please adjust threshold."
                                .Interactive = True
                                .Run(ThisApplication.ActiveDocument)
                            End With
    
                        End If
    
                Catch
    
                    'Do nothing
    
                Finally
    
                    'Do nothing
    
                End Try
    where

        MyThresholdTextMin = textBox_Layer03ThresholdMin.Text
        and
        MyThresholdTextMan = textBox_Layer03ThresholdMax.Text
       

    -- Matt





Sign In or Register to comment.