python - implementation of an orientation map for fingerprint enhancement -


i'm implementing function orientation map of fingerprint image using opencv , python wrong don't know code

def compute_real_orientation(array_i, w=17, h=17, low_pass_filter=cv2.blur,filter_size=(5,5),blur_size=(5,5),**kwargs):     row, col = array_i.shape     array_i = array_i.astype(np.float)     ox = array_i[0:row-h+1:h,0:col-w+1:w].copy()     ox[:] = 0.0     vx = ox.copy()     vy = vx.copy()     oy = ox.copy()     angle = vx.copy()#array contain 17*17 blocks's orientatons     c = r = -1     in xrange(0, row-h+1, h):         r+=1         j in xrange(0, col-w+1, w):             c+=1             dx = cv2.sobel(array_i[i:i+h,j:j+w],-1,1,0)#gradient component x 17*17block             dy = cv2.sobel(array_i[i:i+h,j:j+w],-1,0,1)#gradient component y 17*17 block             k in range(0,h):                 l in range(0,w):                     vy[r][c] += ((dx[k][l])*(dy[k][l]))**2                     vx[r][c] += 2*(dx[k][l])*(dy[k][l])         angle[r][c] = 0.5*(math.atan(vy[r][c]/vx[r][c]))#get orientation angle given 16*16 block     c = -1     #smoothing process of whole array angle     row, col = angle.shape     in range(0, row):         j in range(0, col):             ox[i][j] = math.cos(2*angle[i][j])             oy[i][j] = math.sin(2*angle[i][j])     ox = low_pass_filter(ox, blur_size)     oy = low_pass_filter(oy, blur_size)     in range(0, row):         j in range(0, col):             angle[i][j] = 0.5*math.atan(oy[i][j]/ox[i][j])#take final orientation of 17*17 blocks     return angle 

i'm implementing following algorithm algorithm @ 2.4 orientation image section code not working properly, don't right orientation map. can 1 me troubleshooting this?

b.r

the code working properly. if want visualise orientation map remeber tangent definition.

 tan(a) = (y1-y0)/(x1-x0) (1)  y1 = (x1-x0)*tan(a)+y0 (2) 

where (x0,y0) coordinate of center of wxw block. plot line (x0,y0) (x1,y1) draw orientation line. length = x1-x0 (2) have:

 y1 = length*tan(a)+y0 (3)  x1 = x0 + length (4)  'a' in 'tan(a)' orientation angle @ pixel of (x0,y0) coordinates  

here python function using matplotlib

import cv2 import numpy np import math import matplotlib.pyplot plt  def plot_point(point, angle, length, ax):  '''      point - tuple (x, y) coordinates of pixel      angle - orientation angle @ (x,y) pixel.      length - length of line want plot.       plot line on 10 x 10 plot.      '''       # unpack first point      x, y = point      # find end point      endx = x + length      endy = length*math.tan(angle)+y      ax.plot([x, endx], [y,endy],color='blue')  def draw_orientation_map(angles,                          block_size,                          center_coordinates,                          fingerprint_filename,                          length):      img = cv2.imread(fingerprint_filename)     row, col = img.shape     x_center = y_center = block_size/2#y rowq , x columns     r,c = angles.shape #note center_coordinates.shape = angles.shape     fig = plt.figure()     ax = plt.subplot(111)     ax.set_ylim([0, row])   # set bounds 10, 10     ax.set_xlim([0, col])     plt.imshow(img, zorder=0, extent=[0,col,0,row])     in xrange(0,r):         j in xrange(0,c):             plot_point((j*w + y_center, i*w + x_center),                         angles[i][j],                         length,ax)     plt.show()     

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -