Home Image-Pro Plus Automation with Macros
Options

Using IPAlignFindPattern to rank value

(Originally posted by August on 5/21/2006)

Initial working material are a plenty of images of the text of bad quality. Using the set pattern, and applying function IPAlignFindPattern, I sort images correlate with a rank equal 1.
To me it is not understandable, why when I see incorrectly correlate the image with a pattern, function IPAlignFindPattern all the same returns OutParam (ALGN_PM_OUT_RANK) equal 1?
I use the following parameters of function IPAlignFindPattern: DoRotate=0, DoScale=0, DotTranslate=1, Phase=1.Amount the number of expected objects I set equal 10.

 

Comments

  • Options
    edited June 2013

    (Originally posted by YuriG on 5/22/2006)

    Ranking value is a normalized intensity value of the cross-correlation product of the target image and search pattern.

    The normalization is done by intensity range of the cross-correlation image, so the maximum intensity will have rank of 1 and the minimum is 0. Rank 1 means that the object and search pattern have highest correlation on THIS IMAGE and it does not mean that it's the perfect match.

    Rank is provided to limit the number of found objects on one image using the given threshold.
    Rank is not normalized by maximum when only one object is expected calling IpAlignGetCrossCorrelValues function (check ipc32.bas for syntax), so you can call this function to check the rank of the best-match object on the image.

     

     

  • Options
    edited June 2013

    (Originally posged by YuriG on 5/22/2006)

    You can find the syntax of the function in ipc32.bas. Here is the snippet:

    
    ' The function performs cross-correlation between RefImage and TargetImage 
    ' (images are defined by Vri, RECT and FrameNumber) 
    ' and returns translation, rotation and scale of the transform, which moves the defined area on RefImage to TargetImage 
    ' in the array of doubles defined by lpOutParam 
    ' OutParam[0] - translation X 
    ' OutParam[1] - translation Y 
    ' OutParam[2] - angle 
    ' OutParam[3] - scale 
    ' OutParam[4] - rank value that shows the degree of cross-correlation 
    Declare Function IpAlignGetCrossCorrelValues Lib "IPALGN32" (ByVal sRefImageVri%, ByVal sRefFrame%, RefRect As RECT, ByVal sTargetImageVri%, ByVal sTargetFrame%, TargetRect As RECT, ByVal bDoRotate%, ByVal bDoScale%, ByVal bDoTranslate%, ByVal bPhaseCorr%, lpOutParam As Any) As Long
    



    The function takes the same parameters as IpAlignSetSearchPattern and IpAlignFindPattern.

    Here is the test macro that uses IpAlignGetCrossCorrelValues. On the first click you define the search pattern image and on the second the Target image to find the pattern on. It draws then a rectangle around the found area.

    
    Sub TestCrossCorrel()
    	Dim mypt1 As POINTAPI, mypt2 As POINTAPI
    	Dim docid1 As Integer, docid2 As Integer
    
    	docid1 = IpDocClick("Select search pattern image", mypt1)
    	If docid1 < 0 Then
    		Exit Sub
    	End If
    
    	Dim dInfo1 As IPDOCINFO
    	ret = IpDocGet(GETDOCINFO, docid1, dInfo1)
    	Dim aoirect1 As RECT
    	ret = IpAoiGet(GETBOUNDS, 0, aoirect1)
    	If ret<0 Then
    		aoirect1=dInfo1.Extent
    	End If
    
        docid2 = IpDocClick("Select target image", mypt2)
    	If docid2 < 0 Then
    		Exit Sub
    	End If
    
    	Dim dInfo2 As IPDOCINFO
    	ret = IpDocGet(GETDOCINFO, docid2, dInfo2)
    	Dim aoirect2 As RECT
    	ret = IpAoiGet(GETBOUNDS, 0, aoirect2)
    	If ret<0 Then
    		aoirect2=dInfo2.Extent
    	End If
    
    	Dim OutParam(5) As Double
    	Dim hVri1%,hVri2%
    	ret = IpDocGet(GETDOCVRI, docid1, hVri1)
    	ret = IpDocGet(GETDOCVRI, docid2, hVri2)
    
    	ret=IpAlignGetCrossCorrelValues(hVri1, 0, aoirect1, hVri2, 0, aoirect2, 0, 0, 1, 1,OutParam(0))
    
    	Dim dx!,dy!
    	dx=OutParam(0)
    	dy=OutParam(1)
    	'draw rect around found object
    	ret = IpAnCreateObj(GO_OBJ_POLY)
    	Pts(0).x=aoirect1.Left-dx
    	Pts(0).y=aoirect1.top-dy
    	Pts(1).x=aoirect1.Right-dx
    	Pts(1).y=aoirect1.top-dy
    	Pts(2).x=aoirect1.Right-dx
    	Pts(2).y=aoirect1.bottom-dy
    	Pts(3).x=aoirect1.Left-dx
    	Pts(3).y=aoirect1.bottom-dy
    	Pts(4).x=aoirect1.Left-dx
    	Pts(4).y=aoirect1.top-dy
    	ret = IpAnPolyAddPtArray(Pts(0), 5)
    
    
    	Debug.Print "ret =" & ret
    	Debug.Print "Translation X=" & OutParam(0)
    	Debug.Print "Translation Y=" & OutParam(1)
    	Debug.Print "Angle 		  =" & OutParam(2)*180/3.1415
    	Debug.Print "Scale		  =" & OutParam(3)
    	Debug.Print "Rank		  =" & OutParam(4)
    
    	MsgBox "Check results"
    	ret = IpAnDeleteObj()
    
    
    End Sub
    
Sign In or Register to comment.