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

Automation example question

Hi, 
I am having trouble replicating one of the Automation reference examples. The example appears here: IMcRegions. SetFromMaskMethod Property. In the function copied below, I am not able to access the McOpGT method. I'm running IP Premier, v9.2 build 6156. Thanks for your help!


'This function gets a bit mask of thresholded regions within the AOI
' of the ActiveImage that are larger than 200 pixels in size
Private Function fGetBitMaskFromBigRegions() As McBitMask
    With ActiveImage
        .RegionFeatures.Threshold.Execute 'get some regions
        Dim selBigOnes As McObject
        Set selBigOnes = McOpGT(.RegionFeatures.mRgnArea, 200)  'larger than 200 pixels
        Dim myBitMask As McBitMask
        Set myBitMask = .RegionFeatures.CreateFeatureMask(mcfmfReturnMcBitMask, selBigOnes, .Aoi.BoundingRect)
        Output.PrintMessage "The mask of big regions has " & myBitMask.BlobCount & " blobs."
        Output.PrintMessage "It is " & myBitMask.Width & " wide by " & myBitMask.Height & " high."
        myBitMask.BoundsRect = Empty 'set bounds to minimal bounds
        Output.PrintMessage "Minimal bounds are " & myBitMask.Width & " wide by " & myBitMask.Height & " high."
        Set fGetBitMaskFromBigRegions = myBitMask
    End With 'ActiveImage
End Function 'fGetBitMaskFromBigRegions

Comments

  • edited August 2016
    Hi Nan,

    Some of the examples are written for the previous version of Premier, in VB6 style, so some adjustments has to be made to make it work in the current version:
    1. Use ThisApplication as the main application object.
    2. Remove Set statements.
    3. Add missing namespaces (if you don't have corresponded Imports).

    The corrected code looks like this:

    
        Public Sub MaskTest
            Dim mask As MediaCy.IQL.Features.McBitMask=fGetBitMaskFromBigRegions
            mask.CreateMaskImage(MediaCy.IQL.Features.mcMaskImageType.mcmitBinaryImage).Visible=True
        End Sub
    
        'This function gets a bit mask of thresholded regions within the AOI
        ' of the ActiveImage that are larger than 200 pixels in size
        Private Function fGetBitMaskFromBigRegions() As MediaCy.IQL.Features.McBitMask
            With ThisApplication.ActiveImage
                .RegionFeatures.Threshold.Execute 'get some regions
                Dim selBigOnes As MediaCy.IQL.ObjectManager.McObject
                selBigOnes = ThisApplication.GlobalTools.McOpGT(.RegionFeatures.mRgnArea, 200)  'larger than 200 pixels
                Dim myBitMask As MediaCy.IQL.Features.McBitMask
                myBitMask = .RegionFeatures.CreateFeatureMask(MediaCy.IQL.Features.mcFeatureMaskFlags.mcfmfReturnMcBitMask, selBigOnes, .Aoi.BoundingRect)
                ThisApplication.Output.Show
                ThisApplication.Output.PrintMessage "The mask of big regions has " & myBitMask.BlobCount & " blobs."
                ThisApplication.Output.PrintMessage "It is " & myBitMask.Width & " wide by " & myBitMask.Height & " high."
                myBitMask.BoundsRect = Nothing 'set bounds to minimal bounds
                ThisApplication.Output.PrintMessage "Minimal bounds are " & myBitMask.Width & " wide by " & myBitMask.Height & " high."
                Return myBitMask
            End With 'ActiveImage
        End Function 'fGetBitMaskFromBigRegions
    
    Regards,

    Yuri
  • Thanks for this! Very useful.

    Is there a collection of .net code examples similar to the VB6 examples included in the help files?  The examples available in the "app center" mostly demonstrate workflow creation using simple scripts. I am looking for examples demonstrating lower level control over region features and histograms.

  • The app center can be a good place to start, there are some apps that mostly use IQL code, such as Fibers, Wound Healing, Parent/Child...
    You can also look at some demo projects in the Scripts folder (UserMeasuremts, Debugging,...).

    There are multiple IQL code snippets on the forum.

    Also, you can always post your question here if you have any specific issue.

    Yuri
Sign In or Register to comment.