Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize face Detection after Matlab Image processing

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to achieve face detection after Matlab processing images. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. Block diagram of face detection principle

The overall idea is to find the largest connected domain in the picture and identify it as a human face.

The first step of mean filtering is to reduce the relevant details of the image so as not to affect the formation of the connected domain in the later stage. Binarization facilitates morphological processing and reduces the amount of computation. Considering that the face has black and white yellow people, and the black skin is darker, it is not easy to form a large connected region in the facial region after binarization. If the method of morphological boundary extraction is adopted, this problem can be avoided. As long as the structural elements are large enough, a large closed connected domain can be formed.

Then there is the longitudinal closure operation. In this step, I choose to use vertical strip structural elements for closure operation, because people's face and neck as well as hair and clothing are all longitudinally distributed. When extracting morphological boundaries, it is easy to separate these close components, which is very disadvantageous to the judgment of connected domains, so vertical structural elements are used to perform closure operations longitudinally. Reconnect the upper and lower parts of the face.

Then I use the horizontal strip structure element to calculate the horizontal erosion, because when there are a large number of connected domains in the body part below the head, it is easy to interfere with the judgment of the most Dalian connected domain, and because the lower part is mostly distributed longitudinally, the connected domains of these large blocks can be separated by horizontal corrosion, but it should be noted that the degree of separation should not be too great. Otherwise, it will make the previous closing operation meaningless.

Then, due to background sundries and other factors, there will also be a large number of connected domains, which will interfere with the final decision, so it should be eliminated.

After layer by layer screening, the largest connected domain is selected among the remaining connected domains, and the size and shape that meet the requirements are framed with a rectangle as the result of face detection.

2 step 2.1 mean filtering h = ones (9) / 81 (I) = uint8 (conv2 (I)); figure,imshow (I), title ('linear mean filtering')

9x9 template is used for linear mean filtering, because the gpuArray () function is called later to convert the input data, so the data format is converted into 8-bit unsigned shaping data again after two-dimensional convolution.

2.2 binarization BW = imbinarize (I); figure,imshow (BW), title ('binarization')

Directly call imbinarize to binarize the image

2.3. Morphological boundary extraction B = ones (21);% structural elements BW =-imerode (BW,B) + BW;figure,imshow (BW), title ('morphological boundary extraction') BW = bwmorph (BW,'thicken'); figure,imshow (BW), title ('thickened boundary') BW = not (bwareaopen (not (BW), 300); figure,imshow (BW), title ('fill the hole')

The structural element adopts the all-1 matrix of 21x21 size. The etching is carried out by calling imrode (), and then the etching result is subtracted from the original image to get the boundary. To make the boundary more obvious, call the bmworph function, passing in the 'thicken' parameter, which is intended to thicken the boundary. Finally, in order to fill the hole with a continuous small black block, call the bwareaopen () function, which removes the white block with an area less than 300. in order to remove the black block, first call not (BW) to reverse the original binary image, remove the white block with an area less than 300 after inversion, and reverse it again to achieve the purpose of removing the black block with an area less than 300.

2.4 Longitudinal closure and transverse corrosion% for morphological operations B = strel ('line',50,90); BW = imdilate (BW,B); BW = imerode (BW,B); figure,imshow (BW), title (' after re-closing operation') B = strel ('line',10,0); BW = imerode (BW,B); figure,imshow (BW), title (' corrosion after closed operation') BW = gpuArray (BW)

Call the strel () function to generate a specific structure element, and the first step calls strel ('line',50,90), which means calling a linear structure element with a length of 50 and an angle of 90 degrees, that is, a vertical strip structure element. Then use B to call imdilate and imerode, first expand and then corrode to complete the closed operation. Next, continue to generate horizontal strip structural elements and carry out corrosion operations. Note that the structural elements here should not be too large in area and too long in length, otherwise they will unduly affect the results of the previous step.

Finally, in order to speed up the operation during the loop, the data type can be changed to gpuArray (), which can be calculated on GPU to save time.

2.5 eliminate the boundary redundant connected domain% minimize the background% subdivide div = 10 n2/div r = floor (n1/div);% divide into 10 rows c = floor (n2/div);% divide into 10 columns x1 = 1x x 2 = r Ting% corresponding line initialization s = r counters% block area% judge whether the human face is around the picture, if not, blacken% figurefor i=1:div Y1 = 1x x 2 = c % initialization of the corresponding column for j=1:div loc = find (BW (x1BW x2Magney1Glo y2) = 0);% statistics of the position of this black pixel num = length (loc); rate = num*100/s;% statistics of black pixel ratio if (y2=0.8*div*c) | | (x1=r*div) if rate

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report