Different Filter Ranges for Counting

(Originally posted by Geeda on 3/1/2006)

I am currently writing a macro that performs segmentation/counting on three different classes of objects. One of the main criterion for each class is its area range. For example, white objects with areas within RangeA need to be counted, and brown objects with areas within RangeB need to be counted. Objects outside the ranges need to be discarded. The problem is that the ranges are not the same for different classes.

Currently, I first segment based on color for each class, and then call IpBlbCount() three times on the same image, passing a different set of values through IpBlbSetFilterRange() for each class. However, I find it confusing for the user and would like to find way to display the results of all three class counts (each class filtered individually) on the count screen. The user needs to be able to add/remove count objects.

Any suggestions or help on this matter would be greatly appreciated.


  • edited June 2013

    (Originally posted by Chris Tully on 3/3/2006)

    I would suggest that you define the filter range on area to be include RangeA, RangeB and RangeC. Define all three color classes at the same time and then do a single count. You will then need to manually filter the objects in your macro. First call IpBlbUpdate(4) to delete any objects that did not meet the expended filter range. Then use IpBlbGet and IpBlbData to get the Areas for all of the objects. The following code snippet should get you going on the right track:

    	Dim nRanges As Integer
    	Dim Obj As Integer
    	Dim Range As Integer
    	Dim numObjects As Integer
    	Dim lnumObjects As Long
    	nRanges = 3
    	ReDim Max(nRanges) As Single
    	ReDim Min(nRanges) As Single
    	For Range = 0 To nRanges - 1
    		'set the active segmentation range
    		ret = IpBlbRange(Range)
    		'get the number of objects in that range then get the objects
    		ret = IpBlbGet(GETNUMOBJ, 0, BLB_ACTIVERANGE, numObjects)
    		If numObjects >= 1 Then
    			lnumObjects = numObjects
    			ReDim Areas(numObjects) As Single
    			ret = IpBlbData(BLBM_AREA, 0&, lnumObjects - 1, Areas(0))
    			For Obj = 0 numObjects - 1
    				If (Areas(Obj) >= Min(Range)) Or (Areas(Obj) <= Max(Range)) Then
    					ret = IpBlbHideObject(Obj, Range, 0)
    				End If
    			Next Obj
    		End If
    	Next Range
Sign In or Register to comment.