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

Finds the index of the feature under a given point.

Dear sir,

I used 'ret = IpBlbHitTest(x,y)' to get object Index on Image Pro Plus 7.

How to get the feature name or index with give xy point on IP10?
We need to hide object when it's on the corner.

i try to ues 'FeatureFromPoint' and 'PointClosestToPoint'. They always return -1.

Best Answer

  • Options
    Answer ✓
    WesanSyu,

    The FeatureFromPoint is for low level functions. If you use Count/Size then you should use higher level functions, below is the macro that hides corner objects:
        Public Sub GetBoundingBoxes()
            Dim im As McImage=ThisApplication.ActiveImage
            If im Is Nothing Then Exit Sub
            Dim md As McMMData=im.MeasurementsData
            If md.Count=0 Then Exit Sub
            Dim rgns As MediaCy.IQL.Features.McRegions=md(0).MainSubFeature.GetFeatures()
            If rgns Is Nothing Then Exit Sub'it's not regions
            'ger ROI box
            Dim r As Mediacy.IQL.ObjectManager.SINGLERECT=im.Aoi.BoundingRect
            Dim bl As Single,br As Single, bt As Single,bb As Single
            Dim sides As Integer=0
            For Each sf As McMMSubFeature In md.SubFeatures
                sides=0
                sf.GetBoundingBox(bl,bt,br,bb)'get object bounding box
                'print array of values
                'Debug.Print(String.Format("{0} - [{1},{2},{3},{4}]", sf.Name,bl,bt,br,bb))
                If r.top=bt Then sides+=1
                If r.bottom=bb Then sides+=1
                If r.left=bl Then sides+=1
                If r.right=br Then sides+=1
                If sides=2 Then
                    'corner object
                    Debug.Print(String.Format("{0} - [{1},{2},{3},{4}]", sf.Name,bl,bt,br,bb))
                    'hide it
                    sf.Show=False
                End If
            Next
        End Sub

    I've also attached the macro project.

    The result will look like this:



    Yuri

Answers

  • Options
    2018-07-27-110234

    WesanSyu --

    The IpBlbHitTest function is not one that I have used very often but it has come in handy occasionally.

    I went into my library of CODE for IMAGE-PRO PLUS and found a an example of my use of this function.

    I have extracted what I think is the appropriate section of CODE and included it below.

    This code does kind of the opposite of what you want to do in that it eliminates all objects except the object selected but I hope this I hope this information is helpful.

    -- Matt

    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

        'Declare required variables
        Dim MyPoint1 As POINTAPI
        Dim MyDocID1 As Integer
        Dim MyBlobID1 As Long

        'Ask the user to select an object on the original image
        MyDocID1 = IpDocClick("Please . . . " & vbCr & vbCr & "CLICK on a point within the AXON CLUSTER you want to split!", MyPoint1 )

        'Debug.Print "MyDocID1 = " & Str(MyDocID1)

        'Determine which blob the point was within
        MyBlobID1 = IpBlbHitTest (MyPoint1.X, MyPoint1.Y)

        'Debug.Print "MyBlobID1 = " & Str(MyBlobID1)

        'Error trap
        If ( Not(MyDocID1 > -1 And MyBlobID1 > -1) ) Then

                'Jump to the end of the subroutine
                GoTo MYENDER

            End If

        'Make a mask of the original objects and remember its id
        Dim ID_MaskA As Integer
        ID_MaskA = IpBlbCreateMask()

        'Change the name for the mask image
        ret = IpWsChangeDescription(INF_NAME, "MaskA")

        'Activate the original image
        ret = IpAppSelectDoc(ID_Original)

        'Get the boundary points for the object selected by the user
        Dim numpoints As Integer
        ReDim blbpts(1000) As POINTAPI
        numpoints = IpBlbGet(GETPOINTS, MyBlobID1, 1000, blbpts(0))

        'Delete all existing objects
        ret = IpBlbDelete()

        'Create AOI out of the selected object's outline
        ret = IpAoiCreateIrregular(blbpts(0), numpoints)

        'Change the aoi into a new object that is the same as the selected object
        ret = IpBlbFromAoi(1)
  • Options
    WesanSyu,

    If you want to hide a measurement object in Image-Pro 10, the easiest way would be to select this object (using an interactive macro command) and then delete or hide it.(the commands are recordable).

    Yuri

  • Options
    edited July 2018
    Hi Yuri,

    I know how to select one or more object by using macro command. 

    The following is my measure step: 
    1. Get any picture with particles.
    2. Add a fixed size ROI to the image.
    3. Set measurement conditions. Then counting object.
    4. The corner object index is not the same in every pictures.  So I have to get the feature index of these particles which is in the corner.



    I don't want to select object with mouse click. I want to select and hide certain objects automatically.
    That I known ROI's corner point. Maybe I can use the  'FeatureFromPoint' command to get measurement feature Index.
    Currently, I want to know How to use 'FeatureFromPoint' command?


  • Options
    2018-07-30-111411

    WesanSyu --

    I thought you were looking for how to use the IpBlbHitTest function in IPP7.

    I missed that you were looking for the equivalent function in IP10.

    I am sorry that I misinterpreted your question but I am glad that Yuri was able to provide some information.

    If you are unable to tackle your challenge in an elegant way with the OBJECT INDEXES, perhaps you could tackle the issue by:

    ** Working with the DISTANCE from the CENTROID to the corners of the ROI

    or

    ** With a MASK that is created with masks from the OBJECTS in your IMAGE and the CORNERS of the ROI.

    I hope this information is helpful.

    -- Matt
  • Options
    Thank you very much, Yuri.
    This is very helpful for me.


    Dear matt,
    Thank you for your assistance.
    Actually,I was not description clearly. 
    I know that you assisted the questioners in the forum.
    Many answers are very useful for me.

    Wesan
Sign In or Register to comment.