Process principle analysis of finger vein thinning algorithm and Python implementation refinement algorithm

Source: Internet
Author: User
Tags function prototype

Some of the pictures and ideas in this article are all references to the ideas of https://www.cnblogs.com/My-code-z/p/5712524.html and their own personal understanding.

The principle of thinning algorithm is not difficult to understand, the use of the Matrix nine Gongge to achieve. The nine Gongge are defined and numbered into the following format.

  It is necessary to take a look at what the book says before explaining it:

The book is still relatively concise, after all, is written by Daniel, they feel very simple and easy to understand things, we do not seem to be the case. Well, gossip doesn't talk much about getting into the subject.

The first step: in order not to affect the original image of some other operations, the original image is copied to the refinement of processing, after the refinement of the picture back.

Step two: As you can see in the book, there are four conditions that need to be met in order to delete that point pixel. This is the beginning of the deletion along the southeastern border.

1: A. 2<= p2+p3+p4+p5+p6+p7+p8+p9<=6  

          A value greater than or equal to 2 guarantees that the P1 point is not an endpoint or an outlier, because deleting endpoints and outliers is unreasonable, and less than or equal to 6 guarantees that the P1 point is a boundary point, not an internal point. equals 0, there is no pixel equal to 1, so the P1 is an outlier, equal to 1, the surrounding only 1 grayscale equals 1 pixels, so is the endpoint ( Note: The endpoint is surrounded by and can only have 1 values of 1 pixels).

          

       2: here to meet T (p1) =1 here T (p1) refers to the P2,P3...P8P9 is the P1 neighbor point to rotate

The rotation here is from the beginning of the P2 with the subsequent points of the composition of the format of the tuple (P2,P3) (P3,P4) (P4,P5) ... (P9,P2) See if all tuples of this composition are in the (0,1) format exactly 1

If it is 1 and satisfies the other three conditions at the same time, then he will look like this [[0,1,1] in such a rotation there is exactly one (0,1) and 1 adjacent to the point must also have a pixel value 1 so that is a unicom area this time P1 is the boundary point can be deleted.

[0,1,0]

[0,0,0]]

Probably the meaning is this, my Chinese is not good, can not say very clearly, but you use the book to draw can understand my meaning to forgive ha!!

       3: p2*p4*p6 = 0

4:P4*P6*P8 = 0

Here P4,p6 appeared two times on the top of the rotation judgment if the boundary conditions are met then there is bound to be a 0 in p4,p6 as for why P4,P6 is because this is the first refinement along the southeastern boundary.

The index value of the satisfied point is stored in an array, and the point value of the corresponding position in the image is set to 0 based on the index value coordinates of the midpoint of the array to complete the edge refinement

Step three: Here is a refinement along the northwest direction

Almost the same as the previous step, the only change is the third and fourth conditions, because this is to be refined along the northwest direction, so to be adjusted to:P2*P4*P8 = 0 p2*p6*p8 = 0 Here the P2,P8 appears two times the same reason as the p4,p6 of the previous step    

       The index value of the satisfied point is stored in an array, and the point value of the corresponding position in the image is set to 0 based on the index value coordinates of the midpoint of the array to complete the edge refinement

Finally: Repeat the second and fourth steps, continuous refinement of the left and right until there is no point can be refined then we get the refined skeleton structure

Now that the principle has been explained, let's look at how Python implements the refinement algorithm

defNeighbours (x,y,image):"Return 8-neighbours of Image Point P1 (x, y)img=image x_1, y_1, x1, y1= X-1, Y-1, x+1, y+1return[Img[x_1][y], img[x_1][y1], img[x][y1], img[x1][y1],#P2,P3,P4,P5Img[x1][y], img[x1][y_1], img[x][y_1], img[x_1][y_1]#P6,P7,P8,P9deftransitions (Neighbours):N= Neighbours + neighbours[0:1]#P2, P3, ..., P8, P9, P2    returnSUM ((n1, n2) = = (0, 1) forN1, N2inchZip (n, n[1:]))#( p2,p3), (P3,P4), ..., (P8,P9), (P9,P2)#refine the white vein area into a skeleton structuredefRefine (image):image_thinned= Image.copy ()#deepcopy to protect the original imagechanging1 = Changing2 = 1#The points to be removed (set as 0)     whileChanging1orChanging2:#iterates until no further changes occur in the image        #Step 1Changing1 =[] rows, Columns= Image_thinned.shape#x for rows, y for columns         forXinchRange (1, rows-1):#No. of rows             forYinchRange (1, columns-1):#No. of columnsP2,P3,P4,P5,P6,P7,P8,P9 = n =neighbours (x, Y, image_thinned)if(Image_thinned[x][y] = = 1 and    #Condition 0:point P1 in the object regions2 <= sum (n) <= 6 and    #Condition 1:2<= N (P1) <= 6 The guarantee is not a isolated point and an endpoint or a internal pointTransitions (n) = = 1 and    #Condition 2:s (P1) =1 (0,1) the number of rotation of the structure are 1, and the boundary point can be determined by Adding other conditionsP2 * P4 * P6 = = 0 and    #Condition 3 Remove the southeast boundary PointP4 * P6 * P8 = = 0):#Condition 4Changing1.append ((x, y)) forX, yinchChanging1:image_thinned[x][y]=0#Step 2Changing2 = []                 forXinchRange (1, rows-1):             forYinchRange (1, columns-1): P2,p3,p4,p5,p6,p7,p8,p9= n =neighbours (x, Y, image_thinned)if(Image_thinned[x][y] = = 1 and        #Condition 02 <= sum (n) <= 6 and       #Condition 1Transitions (n) = = 1 and      #Condition 2P2 * P4 * P8 = = 0 and       #Condition 3 Remove the Northwest border PointP2 * P6 * P8 = = 0):#Condition 4Changing2.append ((x, y)) forX, yinchChanging2:image_thinned[x][y]=0returnimage_thinned


Although my English is very poor, but I have Baidu translation ah, all my comments are translated into English.

Here I refer to the function prototype of the algorithm, as to how to call the middle code I will not give, anyway, if you need to use this algorithm, as long as it will be normalized to (0,1) two value of the image in the incoming call on the line

After looking at the refined

Original:

Refine the Picture:

The vein of the original is black, and I'm working on it. Turn black and white two value upside down white represents venous area

Summarize and generalize:

1, see out of this thinning algorithm or there is insufficient, not so beautiful, the image at the fork point in the presence of pixel redundancy, that is, non-single pixel point, which will make it possible to extract the feature points after the trouble.

This requires refinement of the algorithm, which can be used in some template operators to remove the image.

2, as for the original finger vein image noise and shadows will produce various burrs in the skeleton image, these burrs will also affect the later processing. removing burrs can be searched by starting at 0 points from each endpoint until

Stop at the intersection point. In this process, the number of points traversed on each endpoint is recorded, and then a threshold value is set to 0 on the search path of the endpoint that is less than the threshold. This completes the cropping of the image.

Process principle analysis of finger vein thinning algorithm and Python implementation refinement algorithm

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.