Home Image-Pro Plus Automation with Macros

Getting grayscale values from an image

(Originally posted by Jingsong Wang on 7/26/2006)

I need to read pixel intensity of each line from a grayscale image using IP macro coding. How can I get the intensity of position at position (I, J) ? Thanks.

 

Comments

  • edited June 2013

    (Originally posted by Paul on 7/26/2006)

    This code snippet will do the trick, and is flexible enough to do all sorts of other things with:

    
    Sub getGsVals()
     Dim i As Integer
     Dim j As Integer
    
     Dim docId As Integer
     Dim docInfo As IPDOCINFO
    
     Dim hstStats(10) As Single
    
     ret = IpDocGet(GETACTDOC, 0, docId)
    
     ret = IpDocGet(GETDOCINFO, docId, docInfo)
    
    'Create AOI per pixel, iterate through height and width of image
     For i = 0 To docInfo.height
      For j = 0 To docInfo.width
       ipRect.Left = j
       ipRect.Right = j
       ipRect.top = i
       ipRect.bottom = i
       ret = IpAoiCreateBox(ipRect)
    'Get histogram stats
    'for a 1x1 AOI, hstStats(0), 
    'the mean value, will suffice
       ret = IpHstGet(GETSTATS, 0, hstStats(0))
       Debug.Print Str(i) & ", " & Str(j) & _ 
          ": " & Str(hstStats(0))
      Next j
     Next i
    End Sub
    

     

  • (Originally posted by KevinR on 7/26/2006)


    If you wish to get individual pixel values (rather than statistics for an area/line), take a look at "IpDocGetArea" in the AutoPro help files. This function lets you get areas from an image into an IpBasic array for closer examination.

     

  • (Originally posted by Jingsong Wang on 7/26/2006)

    Thanks for the solutions. I will try IpDocGetLine as well.

    BTW, what is the maximun number of 16-bit greyscale data in an one dimension array within IpBasic? How many arrays I can assign ?

     

  • (Originally posted by KevinR on 7/28/2006)

    Images are limited to 64K on a side - the frame size limit of ~750MB is usually more constraining.

    Declare your images and index the arrays with 'Long' variables to avoid short integer limits of +/-32K.

    I believe that arrays can have 5 or more dimensions, although I have _never_ found it necessary to create an array with a dimension greater than 3 for any practical purposes. I haven't run into any limits on the number of arrays you can declare, although if you are looking to create one per line of an image I would strongly recommend creating a 2D array instead.

     

  • there are a few methods you can try to get pixel walues, here is sdk you can make use of  which provide high-performance image retrieve information slutions  to detect and retireve image pixel and other information. quite useful, you can give a try, i hope it is helpful to you.

Sign In or Register to comment.