Python implements Gabor filter extract texture feature extract finger vein texture characteristic finger vein cutting code

Source: Internet
Author: User



Reference Blog: 51533953



17797641



Fourier transform is a powerful tool in signal processing, which can help us convert images from airspace to frequency domain, and extract the features that are not easily extracted in airspace. But after the Fourier transform,



The frequency characteristics of images in different locations are often mixed together, but Gabor filter can extract spatial local frequency characteristics and is an effective texture detection tool.



In image processing, the Gabor function is a linear filter for edge extraction. The frequency and direction of the Gabor filter is similar to that of the human visual system. The study found that Gabor filters are well suited for texture expression and separation. In the spatial domain, a two-dimensional Gabor filter is a Gaussian kernel function modulated by a sinusoidal plane wave.






The expression of the Gabor kernel function:



Complex expressions:






Can be disassembled: the real part:






Imaginary part:






which






And









Parameter description:



Direction (θ): This parameter specifies the direction of the Gabor function parallel stripe, which has a value of 0-360 degrees









Wavelength (λ): Its value is specified in pixels, usually greater than or equal to 2. But not greater than one-fifth of the input image size.









Phase offset (φ): It has a value range of 180 degrees to 180 degrees. The 0he180 degrees correspond to the central symmetric center-on function and the Center-off function respectively, while the 90 and 90 degrees correspond to the opposing function.









Aspect ratio (gamma): The spatial aspect ratio determines the ellipse rate (ellipticity) of the Gabor function shape (support, which I translate into shapes). When γ= 1 o'clock, the shape is round. When γ< 1 o'clock, the shape is elongated with the direction of the parallel stripes. Typically this value is 0.5











Bandwidth (b): The ratio of half-response space frequency bandwidth B and σ/λ for the Gabor filter , where σ represents the standard deviation of the Gaussian factor of the Gabor function, as follows:








The value of σ cannot be set directly, it only changes with bandwidth B. The bandwidth value must be a positive real number, usually 1, when the relationship between the standard deviation and the wavelength is:σ= 0.56λ. The smaller the bandwidth, the larger the standard deviation, the larger the Gabor shape, the more visible the parallel excitation and suppressed stripe number.






Good introduction finished.



Now into the theme, we extract the texture features.



Extract texture features, as well as enhance texture features, many times we have to extract the ROI area of interest to operate. Many of the other spaces in the picture actually do not have much effect on us, and also affect the speed of the program. We only take the ROI region for texture extraction.



First look at the original picture of the finger vein:



  






This picture area is many, we only need the middle part refers to the most vein texture ROI region.






Code:


#! / usr / bin / python
#coding: utf-8
import numpy as np
import os
import cv2

def pathFile (path):
    return os.getcwd () + ‘/‘ + path

def brightestColumn (img):
    w, h = img.shape
    r = range (h / 2, h-1)
    c = range (0, w-1)
    return img [c] [:, r] .sum (axis = 0) .argmax ()

#Build GABOR filter
def build_filters ():
    "" "returns a list of kernels in several orientations
    "" "
    filters = []
    ksize = 31 #gaborl scale here is a
    for theta in np.arange (0, np.pi, np.pi / 4): #gaborl direction 0 45 90 135 Different angle scales will result in different images after filtering
        
        params = {‘ksize‘ :( ksize, ksize), ‘sigma‘: 3.3, ‘theta’: theta, ‘lambd’: 18.3,
                  ‘Gamma’: 4.5, ‘psi‘: 0.89, ‘ktype‘: cv2.CV_32F}
                                                                            #gamma the larger the kernel function is, the smaller the image is, and the number of stripes remains the same. The larger the sigma, the larger the stripes and the image
                                                                            #psi here is close to 0 degrees with white stripes as the center, and 180 degrees with black stripes as the center
                                                                            #theta represents the rotation angle of the stripes
                                                                            #lambd is the wavelength, the greater the wavelength, the greater the fringe
        kern = cv2.getGaborKernel (** params) #Create kernel
        kern / = 1.5 * kern.sum ()
        filters.append ((kern, params))
    return filters

#Filtering process
def process (img, filters):
    "" "returns the img filtered by the filter list
    "" "
    accum = np.zeros_like (img) #Initialize the same size img matrix
    for kern, params in filters:
        fimg = cv2.filter2D (img, cv2.CV_8UC3, kern) # 2D filter function kern is its filter template
        np.maximum (accum, fimg, accum) #Parameter 1 is compared with parameter 2 bit by bit, whichever is greater is stored in parameter 3 Here is the display of texture features is more obvious
    return accum

#Get the top and bottom values of the area of interest for cutting the display image
def getRoiHCut2 (img, p0):
    h, w = img.shape

    maxTop = np.argmax (img [0: h / 2, 0]) #Travel to select the edge of the finger vein in a certain area
    minTop = np.argmax (img [0: h / 2, w-1])
    if (maxTop <65):
        maxBottom = np.argmax (img [(13 * h / 16): 40 * h / 48, 0]) + 3 * h / 4
        minBottom = np.argmax (img [(13 * h / 16): 40 * h / 48, w-1]) + 3 * h / 4
    else:
        maxBottom = np.argmax (img [(3 * h / 4): h, 0]) + 3 * h / 4
        minBottom = np.argmax (img [(3 * h / 4): h, w-1]) + 3 * h / 4
    maxTop = (2 * maxTop + minTop) / 3
    maxBottom = (maxBottom + 2 * minBottom) / 3

    return img [maxTop: maxBottom ,:]

#Get the area of interest
def getRoi (img):
    height, width = img.shape
    heightDist = height / 4

    w = img.copy ()
    w1 = w [heightDist: 3 * heightDist, width / 4:]
    p0 = brightestColumn (w1) + heightDist + height / 2 #Add the height of the edge of the finger to three quarters of the original height
    pCol = w [:, p0: p0 + 1]

    pColInv = pCol [::-1]

    clahe = cv2.createCLAHE (clipLimit = 2.0, tileGridSize = (8,8)) #Build a limited contrast adaptive histogram equalizer

    w1_2 = clahe.apply (w [:, (p0 / 20) :( p0 + p0 / 2)]) #The width of the interception area is about 1.5 times the height of p0. apply is to get a return value. Here is for the convenience of parameters transfer
    w2 = getRoiHCut2 (w1_2, p0)

    res = cv2.resize (w2, (270, 150), interpolation = cv2.INTER_CUBIC)

    return clahe.apply (res)

def logImg (img):
    return img.astype (float) / 255 #Convert image data to 0-1 storage

mDir = []
imgs = []
dbDir = os.getcwd () + "/ db100 /"
people = os.listdir (dbDir)
people.sort ()

for person in people:
    personDir = dbDir + person + "/"
    hands = os.listdir (personDir)

    for hand in hands:
        handDir = personDir + hand + "/"
        mDir + = [handDir]
        mg = os.listdir (handDir)
        mg.sort ()
        imgs = imgs + [handDir + s.split (".") [0] for s in mg if not s.split (".") [0] == "Thumbs"]

p0Imgs = [i.replace (‘db’, ‘gab_roi_db’) for i in imgs] # p0Imgs is the path of each file, mDir is the path that needs to be created. All folders store pre-processed pictures
mDir = [i.replace (‘db‘, ‘gab_roi_db‘) for i in mDir]

#Determine whether the path exists or not, create a path
for path in mDir:
    if not os.path.exists (path):
        os.makedirs (path)

filters = build_filters ()
for index, imgPath in enumerate (imgs):
    img = cv2.imread (imgPath + ".bmp", 0)
    res0 = process (getRoi (img), filters) #Obtain ROI for histogram equalization after cutting and filter in gabor
    cv2.imwrite (p0Imgs [index] + ".png", res0)
    print index


cv2.waitKey (0)
cv2.destroyAllWindows () 


Okay, now look at the image of the treated finger vein:






It looks pretty good, after preprocessing you can do texture feature extraction into the file for pattern matching ah, finger vein recognition ah. Interested in looking forward to the blog after the next.



http://www.cnblogs.com/DOMLX/p/8989836.html Extracting texture features



http://www.cnblogs.com/DOMLX/p/8672489.html finger vein thinning algorithm



http://www.cnblogs.com/DOMLX/p/8111507.html finger vein Cutting process






Python implements Gabor filter extract texture feature extract finger vein texture characteristic finger vein cutting code


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.