我正在尝试将指纹的本地脊线方向视为流程图。但我似乎在这样做时失败了。我的方法包括以下步骤:
- 使用
lro
功能 - 在 16x16 块中找到最主要的角度
- 创建一条线段并将其旋转主要角度以显示它
问题是虽然lro
产生的角度很好,但流程图中的这些显示根本不起作用。在那里,我得到了很多随机的角度,朝着各个方向。谁能帮我解决这个问题?
这是我正在使用的代码:
def lro(im_np):
eps = 2**(-52)
orientsmoothsigma = 4
# original
Gxx = cv2.Sobel(im_np, -1, 2, 0)
Gxy = cv2.Sobel(im_np, -1, 1, 1)
Gyy = cv2.Sobel(im_np, -1, 0, 2)
Gxx = scipy.ndimage.filters.gaussian_filter(Gxx, orientsmoothsigma)
Gxy = scipy.ndimage.filters.gaussian_filter(Gxy, orientsmoothsigma)
Gyy = scipy.ndimage.filters.gaussian_filter(Gyy, orientsmoothsigma)
angle = math.pi/2. + numpy.divide(numpy.arctan2(numpy.multiply(Gxy,2), numpy.subtract(Gxx,Gyy)),2)
return angle
def createLine(im_np):
#Assumes it is 17x17
#Takes in the block-direction
#returns a block-direction image as a numpy array
angle = numpy.max(im_np)
# print im_np.shape
im = Image.new('L', (im_np.shape[0], im_np.shape[1]), (0))
draw = ImageDraw.Draw(im)
draw.line([(0,im_np.shape[0]/2), (im_np.shape[0],im_np.shape[0]/2)], fill=255)
im = im.rotate(angle)
img_np2 = numpy.asarray(im)
# print img_np2
return img_np2
def findDomAngle(im_np):
mask = numpy.zeros((180,2))
for i in range(180):
mask[i][0] = i+1
for i in range(im_np.shape[0]):
for j in range(im_np.shape[0]):
mask[im_np[i][j]-1][1] += 1
max = 0
bestdir = 0
for i in range(180):
if mask[i][1] > max:
bestdir = i + 1
max = mask[i][1]
# print mask
# print max
return bestdir
def blkdir(angle_mat):
x = angle_mat.shape[0]
y = angle_mat.shape[1]
# print angle_mat
domAngle = findDomAngle(angle_mat)
# print domAngle
blkAngle = angle_mat
blkAngle.setflags(write=True)
for i in range(x):
for j in range(y):
blkAngle[i][j] = domAngle
return blkAngle
我正在应用另一个函数来image
逐块处理,但这种方法已被证明是有效的,所以我发现它与包含无关。