Home Image-Pro Plus Automation with Macros

Macro for creating irregular AOI in Image-Pro Plus


I am trying to have a macro in IPP that identifies the outline of an irregular object across an image and make it an irregular AOI.  Then be able to count the objects inside of that AOI and classify them based on area.  When I recorded a macro and identified the irregular AOI it gave me the below code.  However, when it runs on its own it fails to identify the AOI and therefore the counts the wrong objects. 

 ret = IpWsLoad("F:file.tif","tif")
 ret = IpAoiMultShow(1)
 ret = IpAoiMultAppend(1)
 ret = IpBlbShow(1)
 ret = IpBlbCount()
 ret = IpBlbShowSingleClass(0, ipBins(0), 2, 1)
 ipBins(0) = .2866733
 ipBins(1) = 26.0
 ipBins(2) = 1070.983
 ret = IpBlbShowSingleClass(0, ipBins(0), 2, 1)
 ret = IpBlbCreateMask()
End Sub

When I looked it up in the manual it states to use the below code but I don't quite understand what the points are that they mention?  Are they pixels or intensity values? 

 ret = IpListPts
 ret = IpAoiCreateIrregular (Pts (0), 7)



Best Answer

  • Answer ✓
    You are asking about converting Count outlines (which you can create based on threshold segmentation) to AOIs.
    I've found an old macro that does this:

    Sub Count_To_Aoi()
    Dim numpoints As Integer
    Dim numobj As Integer
    Dim i As Integer, status As Integer

    ' number of objects
    ret = IpBlbGet(GETNUMOBJ, 0, 0, numobj)
    If numobj < 1 Then
    ret = IpMacroStop("Please count objects first", MS_MODAL)
    GoTo end_aoi_objects
    End If

    ' reset the multiple Aoi
    ret = IpAoiMultShow(1)
    ret = IpAoiMultAppend(0)

    For i = 0 To numobj - 1

    ' is object in range?
    ret = IpBlbGet(GETSTATUS, i, 0, status)

    If status >= 0 Then

    ' get the object's outline
            numpoints = IpBlbGet(GETPOINTS, i, 1000, Pts(0))

    If numpoints > 0 Then
    ' create an AOI from the outline
              ret = IpAoiCreateIrregular(Pts(0), numpoints)
    ret = IpAoiMultAppend(1)

            End If
       End If
    Next i

    End Sub

    You just have to create some segmented objects (using Count) and then run this macro.

    BTW, in the current version of Image-Pro, Image-Pro Premier this can be done easily using Features Manager (conversion between AOIs, Measurement outlines, Annotations,...).



  • It works correctly in my tests. You should get something like this:

    Sub IrregularAOI()
       ret = IpListPts(Pts(0), "157 86 47 219 181 379 158 222 312 292 275 108 277 108 277 107 278 107 ")
       ret = IpAoiCreateIrregular(Pts(0), 9)
    End Sub

    Tested in IPPlus 7.0.1


  • What are the points it is listing? Are they pixels or intensity values? And are you making up the points or is it finding them?
  • These are X and Y coordinates of the polygon, they are recorded as you click image drawing AOI.
  • Okay, so you got those points by recording and doing it manually?  Maybe I didn't get those because I used the wand tool to create my polygon? 
  • Maybe, just try drawing the polygon, so you get recorded coordinates.
  • Yes that worked! Thanks! 

    I have another question though and I am hoping this is possible? I will have multiple images where the object that I want to be the area of interest may be in different places.  Since I had to do this manually to record and find the points (and these points may not be the same for every image analyzed), is there anyway for it to go through the image and find the points automatically? Or maybe find points based on grayscale value? 

  • Great and once I convert the initial count outline to an AOI can I then count the objects inside of the AOI to classify them?  Sorry if I am being difficult!  And I know Premier would be better for what I am trying to do except I need the automated image capture with StagePro and Premier does not have that capability yet.  So I am trying to do see how much I can do with macros in IPP.
  • Yes, the new Count will be executed within AOIs only.
  • Perfect.  Thank you so much for your help!
Sign In or Register to comment.