Пример #1
0
def findMaxGradientValueOnNormal(gradient_magnitude, gradient_orientation, p1, p2, normal_orientation):
    #Get integer coordinates on the straight line between p1 and p2
	pts = SIGBTools.getLineCoordinates(p1, p2)
	values = gradient_magnitude[pts[:,1],pts[:,0]]
	#orientations = gradient_orientation[pts[:,1],pts[:,0]]
	#normal_angle = np.arctan2(normal_orientation[1], normal_orientation[0]) * (180 / math.pi)

	# orientation_difference = abs(orientations - normal_angle)
	# print orientation_difference[0:10]
	# max_index = 0 #np.argmax(values)
	# max_value = 0
	# for index in range(len(values)):
	# 	if orientation_difference[index] < 20:
	# 		if values[index] > max_value:
	# 			max_index = index
	# 			max_value = values[index]
	#print orientations[max_index], normal_angle
	max_index = np.argmax(values)
	return pts[max_index]
Пример #2
0
def findMaxGradientValueOnNormal(gm, gd,resolution,p1,p2):
	pts = SIGBTools.getLineCoordinates(p1, p2)
	temp=pts/resolution
	normVal=gm[temp[:,1],temp[:,0]]	
	found=False
	temp=len(normVal)
	accuracy=6
	bestAngle=360.0
	if temp<accuracy:
		accuracy=temp
	while found!=True | accuracy>1:
		maxValueIndexes=np.where(normVal==max(normVal))
		maxValueIndex=maxValueIndexes[0][0]
		maxX=pts[maxValueIndex][0]
		maxY=pts[maxValueIndex][1]
		vect=np.subtract(p1,p2)
		endX=vect[0]
		endY=vect[1]
		length=math.sqrt(math.pow(endX, 2)+math.pow(endY, 2))
		p1NormX,p1NormY=endX/length, endY/length
		length=math.sqrt(math.pow(maxX, 2)+math.pow(maxY, 2))
		p2NormX,p2NormY=maxX/length, maxY/length 
		dot=np.dot((p1NormX,p1NormY),(p2NormX,p2NormY))
		angle=math.degrees(math.acos(dot))
		if angle>180:
			angle=math.fabs(angle-360)
		if angle<20:
			found=True
			retX,retY=maxX,maxY
			return retX, retY			
		else:
			if angle<bestAngle:
				bestAngle=angle
				retX,retY=maxX,maxY
			normVal=np.delete(normVal, maxValueIndex, axis=0)
		accuracy=accuracy-1
	return retX, retY