Matlab Simulation of Face Recognition Algorithm Based on Morphological Processing

Table of contents

1. Theoretical basis

1.1 Morphological processing

1.2 Face recognition

1.3 Face recognition model

1.4 Morphological processing algorithm

1.5 Implementation steps

2. Core program

3. Simulation conclusion


1. Theoretical basis


      In recent years, face recognition technology has been widely used, and it can be used in security, finance, medical and other fields. Face recognition based on morphological processing algorithm is a commonly used face recognition method. It performs morphological processing on face images to extract face features, thereby realizing face recognition.


1.1 Morphological processing

        Morphological processing is an image processing technology based on shape and structure, which extracts the shape and structure information of the image by performing morphological operations on the image. Commonly used morphological operations include erosion, dilation, opening and closing operations.

1.2 Face recognition

       In face recognition based on morphological processing algorithms, the commonly used feature extraction method is Local Binary Pattern (LBP). LBP is a grayscale image processing method, which compares the grayscale value of each pixel with the grayscale value of surrounding pixels to obtain a binary number, which is used to represent the local characteristics of the pixel. The mathematical formula of LBP is as follows:

$$LBP(x_c,y_c)=\sum_{p=0}^{P-1}s(g_p-g_c)2^p$$

Among them, $x_c$ and $y_c$ are the coordinates of the center pixel, $g_c$ is the gray value of the center pixel, $g_p$ is the gray value of the surrounding pixels, $P$ is the number of surrounding pixels, $s( x)$ is a sign function, indicating the sign of $x$.

The LBP method obtains an LBP image by calculating the LBP value of each pixel in the image, and then performs morphological processing on the LBP image to extract face features for face recognition.

1.3 Face recognition model

The basic steps of the face recognition model based on the morphological processing algorithm are as follows:

Convert face image to grayscale image.

The LBP feature extraction is performed on the grayscale image to obtain an LBP image.

Perform morphological processing on the LBP image to extract facial features.

Calculate the distance between facial features to determine whether they are the same person.

1.4 Morphological processing algorithm

       In face recognition based on morphological processing algorithms, commonly used morphological processing algorithms include opening and closing operations. The opening operation can remove small noises and details in the image, and retain the general outline of the image; the closing operation can fill in small holes and details in the image, and retain the details and textures in the image.

The mathematical formulas for opening and closing operations are as follows:

Open operation:

$$A\circ B=(A\ominus B)\oplus B$$

Closing operation:

$$A\bullet B=(A\oplus B)\ominus B$$

Among them, $A$ is the original image, $B$ is the structural element, $\ominus$ represents the erosion operation, and $\oplus$ represents the expansion operation.

1.5 Implementation steps


The implementation steps of face recognition based on morphological processing algorithm are as follows:

Convert face image to grayscale image.
Converting a color face image to a grayscale image can be implemented using functions in the image processing library.

The LBP feature extraction is performed on the grayscale image to obtain an LBP image.
       For each pixel, calculate the difference between the gray value of the surrounding pixels and the gray value of the center pixel, and obtain a binary number, which is used to represent the local characteristics of the pixel. For the entire image, the following formula can be used for calculation:

$$LBP(x_c,y_c)=\sum_{p=0}^{P-1}s(g_p-g_c)2^p$$

      Among them, $x_c$ and $y_c$ are the coordinates of the center pixel, $g_c$ is the gray value of the center pixel, $g_p$ is the gray value of the surrounding pixels, $P$ is the number of surrounding pixels, $s( x)$ is a sign function, indicating the sign of $x$. After obtaining an LBP image, subsequent morphological processing can be performed.

      Perform morphological processing on the LBP image to extract facial features. Commonly used morphological processing algorithms include opening operation and closing operation, and different processing methods can be selected according to specific situations. For the opening operation, the following formula can be used:

$$A\circ B=(A\ominus B)\oplus B$$

      Among them, $A$ is the LBP image, $B$ is the structural element, $\ominus$ represents the erosion operation, and $\oplus$ represents the expansion operation. For the closing operation, the following formula can be used:

$$A\bullet B=(A\oplus B)\ominus B$$

Among them, $A$ is the LBP image, $B$ is the structural element, $\oplus$ represents the expansion operation, and $\ominus$ represents the erosion operation.

After morphological processing, an image with facial features extracted can be obtained for subsequent face recognition.

       Calculate the distance between facial features to determine whether they are the same person. For images with facial features extracted, it is possible to determine whether they belong to the same person by calculating the distance between different images. Commonly used distance calculation methods include Euclidean distance, Manhattan distance, cosine distance, etc., and different methods can be selected according to specific situations.
       Face recognition based on morphological processing algorithm is a commonly used face recognition method. It performs morphological processing on face images to extract face features, thereby realizing face recognition. In the implementation process, it is necessary to perform LBP feature extraction on grayscale images, then perform morphological processing, and finally calculate the distance between different images. This method has the advantages of small calculation amount and fast speed, and has been widely used in practical applications.

2. Core program

......................................................................

L = bwlabel(BW,8);%%%函数bwlabel是把四连通或八连通的区域连接起来
%regionprops统计被标记的区域的面积分布,显示区域总数.返回值是结构数组,其相应域定义了每一个区域相应属性下的度量.
BB  = regionprops(L, 'BoundingBox');%‘BoundingBox’包含相应区域的最小矩形
BB1=struct2cell(BB);%把结构体转换为元胞数组
BB2=cell2mat(BB1);%一个由多个矩阵构成的元胞数组转换成一个矩阵。意即把元胞数组中的多个矩阵合并成一个矩阵。
[s1 s2]=size(BB2);
mx=0;
for k=3:4:s2-1
    p=BB2(1,k)*BB2(1,k+1);
    if p>mx & (BB2(1,k)/BB2(1,k+1))<1.8
        mx=p;
        j=k;
    end
end
figure,imshow(I);
hold on;
%rectangle函数功能:创建二维矩形对象。
rectangle('Position',[BB2(1,j-2),BB2(1,j-1),BB2(1,j),BB2(1,j+1)],'EdgeColor','r' )%从点(x,y)开始绘制一个宽w高h的矩形,
up2146

3. Simulation conclusion

Guess you like

Origin blog.csdn.net/ccsss22/article/details/131424393
Recommended