CN107123088A - A kind of method of automatic replacing photo background color - Google Patents

A kind of method of automatic replacing photo background color Download PDF

Info

Publication number
CN107123088A
CN107123088A CN201710264952.8A CN201710264952A CN107123088A CN 107123088 A CN107123088 A CN 107123088A CN 201710264952 A CN201710264952 A CN 201710264952A CN 107123088 A CN107123088 A CN 107123088A
Authority
CN
China
Prior art keywords
image
gradient
certificate photo
edge
background
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201710264952.8A
Other languages
Chinese (zh)
Other versions
CN107123088B (en
Inventor
刘治
朱耀文
许建中
邱清晨
曹艳坤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shandong University
Original Assignee
Shandong University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shandong University filed Critical Shandong University
Priority to CN201710264952.8A priority Critical patent/CN107123088B/en
Publication of CN107123088A publication Critical patent/CN107123088A/en
Application granted granted Critical
Publication of CN107123088B publication Critical patent/CN107123088B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/40Scaling of whole images or parts thereof, e.g. expanding or contracting
    • G06T3/4038Image mosaicing, e.g. composing plane images from plane sub-images
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/194Segmentation; Edge detection involving foreground-background segmentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Image Analysis (AREA)

Abstract

Rim detection is carried out the invention discloses a kind of method of automatic replacing photo background color, including to certificate photo image, certificate photo edge image is obtained;The outer profile image in human target region is extracted from certificate photo edge image;The mask value needed for image synthesis is calculated using the digital matting algorithm based on overall situation study;The mask value obtained according to calculating, using 1 and mask value difference and mask value as the solid background image of certificate photo image and the coefficient of preceding background image, the solid background image of certificate photo image and preceding background image are subjected to linear superposition, the certificate photo image after synthesis is finally given.The present invention can not only meet applicant without it is outgoing can self-help replacing photo background demand, moreover it is possible to complete it is quick, efficiently, it is accurate, automatically obtain image background regions, realize that preferable certificate photo refoots effect.

Description

Method for automatically replacing background color of certificate photo
Technical Field
The invention belongs to the technical field of image processing, and particularly relates to a method for automatically replacing background colors of a certificate photo.
Background
Along with the development of society, the types of various certificates applied and transacted by people are increasing, and according to different regions and the transacting types of different certificates, the transacting organ has strict requirements on the background color of the certificate photo on the certificate. For example, the exit-entry certificate photo of Sichuan province requires the background to be white, and the exit-entry certificate photo of Guangdong province requires the background to be blue; for example, the certificate of signing certificate is required to be white when China transacts the signing certificate for the beauty and the pass for Taiwan in China, and the certificate of signing certificate is required to be red when China transacts the applied form of rural pension.
In the actual process of taking the certificate photo, each applicant is difficult to set background cloth shooting according to the correct background standard of the certificate photo, so that in the actual process of making the certificate photo, the certificate photo is often required to be subjected to background changing processing through a software program according to different requirements, so that the certificate photo meets the certificate making requirement.
The traditional identification photo processing method mainly adopts manual judgment of an image background area, and then performs related operations such as drawing of a figure object edge and the like through image processing software to replace background colors, however, in actual operation, the traditional methods have many defects: the method has the advantages of strong dependence on manual work, low time consumption, low labor consumption and efficiency, low accuracy of the acquired image background area, serious loss of figure target edge information and poor certificate photo bottom changing effect. Obviously, the traditional method cannot be suitable for acquiring background areas of various certificate photo images, cannot meet the development requirement of fully automatically acquiring the background of the certificate photo images, and cannot meet the application requirement of self-help certificate photo making of common people.
Disclosure of Invention
In order to solve the defects of strong manual dependence, low time consumption, low labor consumption and efficiency, low accuracy of an acquired image background area, serious loss of figure target edge information and poor certificate photo background changing effect in the prior art, the invention provides a method for automatically changing the certificate photo background color, which can meet the requirement that an applicant can automatically change the certificate photo background without going out, can also finish quickly, efficiently, accurately and automatically acquiring the image background area and realize better certificate photo background changing effect.
The invention discloses a method for automatically changing background color of a certificate photo, which is applied to a server and comprises the following steps:
carrying out edge detection on the certificate photo image to obtain a certificate photo edge image;
extracting an outer contour image of a character target area from the edge image of the certificate photo;
calculating a mask value required in image synthesis by adopting a digital matting algorithm based on global learning;
and according to the mask value obtained by calculation, taking the difference between 1 and the mask value as coefficients of a solid background image and a front background image of the certificate photo image respectively, and linearly superposing the solid background image and the front background image of the certificate photo image to finally obtain a synthesized certificate photo image.
Further, edge detection is carried out on the certificate photo image by adopting an edge detection algorithm fusing Sobel and K-means to obtain the certificate photo edge image.
Further, the specific process of performing edge detection on the certificate image by adopting an edge detection algorithm fusing Sobel and K-means comprises the following steps:
(1-1): carrying out convolution on the four convolution templates and the identification photo image to obtain four gradient images Gx,Gy, G45,G135And four corresponding gradient histograms; the four convolution templates are detection convolution templates of Sobel operators for edges in the x direction, the y direction and 45 degrees and 135 degrees respectively;
(1-2): listing the gradient value ranges of the four gradient images obtained in the step (1-1);
(1-3): adopting a K-means algorithm to self-adaptively select a threshold, respectively carrying out threshold segmentation on the gradient image obtained in the step (1-1), and dividing all pixel points in the gradient image into two types: one belonging to the edge and one belonging to the background;
(1-4): classifying the gradient value of each pixel point in the gradient image;
(1-5): for each cluster, recalculating the centroid of the respective class;
(1-6): repeating the steps (1-4) to (1-5) until the variation amplitude of the mass center is in a range meeting the requirement;
(1-7): calculating a gradient threshold, wherein the optimal gradient threshold is a maximum value point in the background class or a minimum value point in the edge class;
(1-8): evaluating whether the selected gradient threshold is the optimal gradient threshold by adopting an Ostu algorithm, dividing all gradient values in the gradient image into two classes according to the gradient threshold selected in the step (1-7), and calculating the inter-class variance and the global variance to enable the threshold when the ratio of the two classes is the maximum to be the optimal gradient threshold;
(1-9): binarizing the gradient image according to the optimal gradient threshold value obtained in the steps (1-7) and (1-8) to obtain an edge image;
(1-10): respectively taking absolute values of the four gradient images obtained in the step (1-1) to obtain | Gx|、|Gy|、|G45|、|G135And (4) obtaining an edge image by using the steps (1-2) to (1-9) for each absolute value-taken gradient image, and performing exclusive OR on the four edge images to obtain a final edge image.
The invention adopts the edge detection algorithm fusing the Sobel and the K-means to obtain the certificate photo edge image, the method can self-adaptively obtain the optimal threshold value, the threshold value positioning is accurate, the problem of edge information loss caused by improper threshold value selection of the traditional edge detection algorithm is solved, and the method has good performance in the aspects of edge richness, continuity and precision.
Further, the specific process of extracting the outline image of the character target area from the identification photo edge image is as follows:
(2-1): adopting square structural elements to perform morphological expansion operation on the certificate according to the edge image so as to connect edge fracture points which may exist;
(2-2): connecting the outline of the character target in the identification photo, searching two points with the minimum row coordinate in all white contour points of the first column and the last column from the image matrix obtained in the step (2-1), respectively regarding the two points as intersection points of the left shoulder, the right shoulder and the left side and the right side of the image, downwards supplementing the white contour points according to the two points, and setting the last row of the image matrix as a white contour to obtain a closed character target contour;
(2-3): marking each connected component formed by target pixel points in the image under the eight-adjacent structure for the image obtained in the step (2-2), calculating the number of pixel points corresponding to each connected component, and selecting the largest target connected component as the outline of the character target;
(2-4): carrying out image filling on the outline image of the person target obtained in the step (2-3) to obtain a person target area image;
(2-5): and (4) performing edge detection on the image of the character target area obtained in the step (2-4) by adopting a Canny operator to obtain an outline image outside the character target area.
Furthermore, in the step (2-1), morphological dilation operation is performed on the identification photo edge image by adopting a 4 × 4 square structural element.
The invention adopts the square structural elements to carry out morphological dilation operation on the edge image of the certificate photo so as to connect the possible edge fracture points, can effectively replace the background color of the character certificate photo, can completely keep the hair details of the character after the background replacement, and has good character certificate photo background replacement effect.
Further, before calculating the mask value required in the image synthesis by using the global learning-based digital matting algorithm, the method further includes: and extracting a ternary image matrix trimap image from the outline image outside the human target area.
Further, the process of extracting the ternary image matrix trimap image from the outline image outside the human target area comprises the following steps:
and performing multiple morphological expansion operations on the outline image of the character target area by adopting 4 multiplied by 4 square structural elements to obtain a ternary image matrix trimap image, wherein the ternary image matrix trimap image comprises determined character target pixel points, background pixel points and pixel points of a to-be-determined category.
Further, in the process of calculating the mask value required in the image synthesis by adopting the digital matting algorithm based on global learning, the three-value image matrixtaking the trimap image as input, wherein a pixel point set formed by all pixel points in the trimap image of the ternary image matrix is omega, and the omega comprises a determined pixel point set omegalAnd a set of pixel points Ω to be determinedu
Training a global alpha-color model by adopting a weighted ridge regression algorithm, and aiming at a pixel point set omega to be determineduAnd (4) estimating the mask value of the pixel point to be determined by using the linear global alpha-color model.
Further, the method further comprises: and expanding the trained linear alpha-color model to a nonlinear alpha-color model by adopting a kernel rock algorithm, and estimating the mask value of the pixel point set to be determined by utilizing the nonlinear model.
The invention adopts the digital matting algorithm based on global learning to calculate the mask value required in the image synthesis, the algorithm can better adapt to the digital matting based on the trimap image, can be realized only by some simple image matrix operations, can also effectively process the nonlinear local color distribution condition in the image, and the calculation result has high accuracy.
Further, the solid background image includes red, blue, and white. According to different purposes in China, the background colors of the certificate photo are generally divided into three colors of red, blue and white.
Compared with the prior art, the invention has the beneficial effects that:
(1) the invention adopts the digital matting algorithm based on global learning to calculate the mask value required in the image synthesis, the algorithm can better adapt to the digital matting based on the trimap image, and can be realized only by some simple image matrix operations, and can also effectively process the nonlinear local color distribution condition in the image, and the calculation result has high accuracy.
(2) The invention adopts the edge detection algorithm fusing the Sobel and the K-means to obtain the certificate photo edge image, the method can self-adaptively obtain the optimal threshold value, the threshold value positioning is accurate, the problem of edge information loss caused by improper threshold value selection of the traditional edge detection algorithm is solved, and the method has good performance in the aspects of edge richness, continuity and precision.
(3) The method for automatically replacing the background color of the certificate photo can effectively replace the background color of the certificate photo of the character, can completely keep the details of the hair of the character after the background is replaced, has good effect of replacing the background of the certificate photo of the character, can meet the requirement that an applicant can replace the background of the certificate photo by self without going out, can also quickly, efficiently, accurately and automatically acquire an image background area, and achieves good effect of replacing the background of the certificate photo.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this application, illustrate exemplary embodiments of the application and, together with the description, serve to explain the application and are not intended to limit the application.
FIG. 1 is a schematic flow chart of a method for automatically changing the background color of a certificate photo in an embodiment of the invention;
FIG. 2 is a schematic flow chart of edge detection of a certificate image by using an edge detection algorithm fusing Sobel and K-means.
Detailed Description
It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the disclosure. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.
It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of example embodiments in accordance with the present application. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, and it should be understood that when the terms "comprises" and/or "comprising" are used in this specification, they specify the presence of stated features, steps, operations, devices, components, and/or combinations thereof, unless the context clearly indicates otherwise.
As described in the background, there are in the prior art: the method has the advantages that the manual dependence is strong, the time and labor consumption are low, the accuracy of the acquired image background area is low, the edge information of the figure target is seriously lost, and the certificate photo background changing effect is poor.
FIG. 1 is a flow chart illustrating a method for automatically changing a background color of a certificate photo according to an embodiment of the present invention, which employs a server or a processor; the method for automatically changing the background color of the certificate photo in the embodiment as shown in the figure can comprise the following steps:
s101, carrying out edge detection on the certificate photo image to obtain the certificate photo edge image.
In the specific implementation, the edge detection algorithm fusing Sobel and K-means is adopted to carry out edge detection on the certificate photo image so as to obtain the certificate photo edge image.
As shown in fig. 2, the specific process of performing edge detection on the certificate image by using the edge detection algorithm fusing Sobel and K-means includes:
(1-1): on the basis of the original detection convolution templates of the Sobel operator for the edges in the x and y directions, detection convolution templates for the edges at 45 degrees and 135 degrees are added, and the four convolution templates are used for carrying out convolution with the input identification photo image to obtain four gradient images which are G respectivelyx,Gy,G45,G135And four corresponding gradient squaresA drawing;
(1-2): listing the gradient value range [0,1,2, …, L ] in the gradient image G obtained by Sobel operator processing, wherein L is a gradient series, L is a positive integer, and the calculation formula of the total number of gradient points is as follows:
N=N0+N1+N2+…+NL(1)
(1-3): and (4) adopting a K-means algorithm to self-adaptively select a threshold value, and carrying out threshold value segmentation on the gradient image obtained in the step (1-1). According to the distribution characteristics of the gradient histogram obtained in the step (1-1) and the gradient value of each pixel point in the gradient image, dividing all the pixel points into two types: one belongs to the edge, the other belongs to the background, and an initial centroid point mu is selected1、μ2, μ1、μ2∈ {0,1,2, …, L }, set μ1=0,μ2=255;
(1-4): gradient value g for each pixeljClassify it into and cluster the centroid point muiClass c with smaller differenceiThe classification formula is as follows:
gj∈ci,when min||gji||2(2)
wherein each cluster centroid point muiCorresponding to a class ciI ∈ {1,2} is the ith cluster, j represents the number of pixel points in the gradient image, j ∈ {1,2, …, N };
(1-5): for each cluster ciRecalculating the centroid μ of the classiI.e. calculating the mean value of the gradients, centroid mu, of the pixels belonging to this classiThe calculation formula is as follows:
(1-6): repeating the steps (1-4) to (1-5) until the variation amplitude of the mass center is within the range meeting the requirement, wherein the matching formula is as follows:
wherein,for the clustered centroid point for the nth iteration,the cluster centroid point of the (n-1) th iteration is obtained;
(1-7): calculating a gradient threshold th, wherein the optimal gradient threshold should be a maximum value point in the background class or a minimum value point in the edge class, and the calculation formula is as follows:
th=maxgior mingj,gi∈c1,gj∈c2(5)
wherein, c1Represents a background class, giIs the gradient value of pixel points in the background class, c2Denotes edge class, gjGradient values of pixel points in edge classes;
(1-8): evaluating whether the selected gradient threshold is the optimal gradient threshold by adopting an Ostu algorithm, dividing all gradient values in the gradient image into two classes according to the gradient threshold selected in the step (1-7) as th, and calculating the inter-class varianceAnd global varianceThe threshold th at which the ratio η is maximized is the optimal gradient threshold, and the calculation formula of the ratio η is as follows:
wherein, the variance between classesAnd global varianceThe calculation formula of (a) is as follows:
in the above formula, ω0、ω1For the probability of occurrence of each type of gradient value, μ0、μ1Is the class mean of each class, muTMean value of the gradient of the population of gradient images, piRepresenting the probability of occurrence of a gradient value i;
wherein the probability piAnd global gradient mean μTThe calculation formula of (a) is as follows:
in the above formula, i ∈ {1,2, …, L } represents the number of gradient value stages, niRepresenting the number of pixel points with gradient value i, wherein N is the total number of pixel points;
(1-9): and (3) binarizing the gradient image according to the optimal gradient threshold value obtained in the steps (1-7) and (1-8) to obtain an edge image E (i, j), wherein the binarization formula is as follows:
(1-10): respectively taking absolute values of the four gradient images obtained in the step (1-1) to obtain | Gx|、|Gy|、|G45|、|G135And (3) obtaining an edge image by using the steps (1-2) to (1-9) for each absolute value-taken gradient image, and performing exclusive OR on the four edge images to obtain a final edge image, wherein the exclusive OR formula is as follows:
E(i,j)=|Ex(i,j)|xor|Ey(i,j)|xor|E45(i,j)|xor|E135(i,j)| (13)。
the invention adopts the edge detection algorithm fusing the Sobel and the K-means to obtain the certificate photo edge image, the method can self-adaptively obtain the optimal threshold value, the threshold value positioning is accurate, the problem of edge information loss caused by improper threshold value selection of the traditional edge detection algorithm is solved, and the method has good performance in the aspects of edge richness, continuity and precision.
S102, extracting an outer contour image of the character target area from the identification photo edge image.
In the specific implementation, the specific process of extracting the outline image of the figure target area from the identification photo edge image is as follows:
(2-1): performing morphological dilation operation on the obtained edge image by adopting a 4 multiplied by 4 square structural element to connect possible edge fracture points;
(2-2): connecting the outline of the character target in the identification photo, searching two points with the minimum row coordinate in all white contour points of the first column and the last column from the image matrix obtained in the step (2-1), respectively regarding the two points as intersection points of the left shoulder, the right shoulder and the left side and the right side of the image, downwards supplementing the white contour points according to the two points, and setting the last row of the image matrix as a white contour to obtain a closed character target contour;
(2-3): marking each connected component formed by target pixel points (namely white edge points) in the image under the eight-adjacent structure for the image obtained in the step (2-2), calculating the number of pixel points corresponding to each connected component, and selecting the maximum target connected component as the outline of the character target;
(2-4): carrying out image filling on the outline image of the person target obtained in the step (2-3) to obtain a person target area image;
(2-5): and (4) performing edge detection on the image of the character target area obtained in the step (2-4) by adopting a Canny operator to obtain an outline image outside the character target area.
In alternative embodiments, the obtained edge image is subjected to morphological dilation operation by using square structural elements in other matrix forms.
The invention adopts the square structural elements to carry out morphological dilation operation on the edge image of the certificate photo so as to connect the possible edge fracture points, can effectively replace the background color of the character certificate photo, can completely keep the hair details of the character after the background replacement, and has good character certificate photo background replacement effect.
And S103, calculating a mask value required in image synthesis by adopting a digital matting algorithm based on global learning.
Specifically, the method for calculating the mask value alpha required in image synthesis by adopting a digital matting algorithm based on global learning comprises the following steps:
(3-1): extracting a trimap image from the obtained outline image outside the human target area, wherein the specific method comprises the following steps: performing multiple morphological expansion operations on the outline image of the character target area by adopting 4 multiplied by 4 square structural elements to obtain a ternary image matrix trimap image, wherein the ternary image matrix trimap image comprises determined character target pixel points (namely white pixel points), background pixel points (namely black pixel points) and pixel points (namely gray pixel points) of a to-be-determined category;
(3-2): taking the trimap image obtained in the step (3-1) as an input, wherein a pixel point set formed by all pixel points in the trimap image is Ω (Ω ═ {1,2, n }), and Ω includes a determined pixel point set ΩlAnd a set of pixel points Ω to be determineduWherein the determined set of pixel points omegalAnd includes the determined foreground pixel point set omegal f(i.e., the set of human target pixel points, mask value α ═ 1) and the set of background pixel points Ωl b(mask value α ═ 0), two subsets are selected from the determined set of pixelsAndfor any pixel point j in the two subsets, it needs to satisfy:
Dj<Dth(14)
in the above formula, DjFrom a pixel point j to a pixel point set omega to be determined in a regular griduShortest Euclidean distance of pixel points in (D)thIs a distance threshold;
wherein the distance threshold value DthThe calculation formula of (a) is as follows:
in the above formula, γdIs constant, the empirical value is set to 1.2;
(3-3): for a set of pixel points Ω to be determineduEach pixel point i in (2) from Ql fAnd Ql bTwo subsets with the same number of pixel points are selectedAndis at Ql f'And Ql b'In (1) Euclidean distance D from pixel point j to pixel point ijShortest, and calculating Euclidean distance D in linear time by using linear time Euclidean distance conversion algorithmj
(3-4): for Q selected in the step (3-3)l f'And Ql b'Each pixel point j in (1) is set with a weight value omegajBy Ql f'And Ql b'The weight values omega of all the pixel points in the system construct oneDiagonal matrix of dimensionsWeight omegajThe assignment formula of (a) is as follows:
in the above formula, DjThe shortest Euclidean distance, gamma, calculated in the step (3-3)ωIs a constant, generally taken empirical value gammaω=0.25;
(3-5): training a global alpha-color model by adopting a weighted ridge regression algorithm, and aiming at a pixel point set omega to be determineduUsing the linear global alpha-color model to estimate α the mask value of the pixel point to be determinediThe estimation formula is as follows:
in the above formula, xiIs the pixel value of the pixel point to be determinedThe composed data vector, which may be represented as xi′=[xi T1]T(wherein Q)l f'∪Ql b'={τ1,…,τtIs a group of Ql f'∪Ql b'Of the pixel points in (1), λrIs a parameter, usually set to 0.1, I(t)Is an identity matrix with dimension t × t,represents by Ql f'∪Ql b'The vector composed of the mask values of all the pixel points in the image;
(3-6) more generally, extending the linear alpha-color model obtained by training in the step (3-5) to a nonlinear alpha-color model by adopting a kernel trim algorithm, and estimating a mask value α of a pixel point set to be determined by utilizing the nonlinear modeliThe estimation formula is as follows:
in the above formula, the first and second carbon atoms are,is a function of a Gaussian kernel function k (x)i′,xj') instead of the data vector xi' and xjThe vector of the' inner product can be expressed as Is a Gaussian kernel function value k (x)i′,xj') can be represented as
Wherein, the Gaussian kernel function value k (x)i′,xj') the calculation is as follows:
in the above formula, ν is a variance value of a gray-scale image of the person identification image source image.
The invention adopts the digital matting algorithm based on global learning to calculate the mask value required in the image synthesis, the algorithm can better adapt to the digital matting based on the trimap image, can be realized only by some simple image matrix operations, can also effectively process the nonlinear local color distribution condition in the image, and the calculation result has high accuracy.
And S104, according to the calculated mask value, taking the difference between 1 and the mask value as coefficients of a solid background image and a front background image of the certificate photo image respectively, and linearly superposing the solid background image and the front background image of the certificate photo image to finally obtain the synthesized certificate photo image.
The specific method comprises the following steps: inputting a figure certificate photo source image with any background color and three pure color images of red, white and blue (according to different purposes in China, the background color of the certificate photo is generally divided into the three colors), and according to a mask value alpha finally calculated in S103, adopting an image linear mixing equation to realize automatic background changing of the certificate photo, wherein the synthetic formula is as follows:
I=αF+(1-α)B (20)
wherein, I represents the synthesized certificate photo image, F is a foreground image, namely a character certificate photo source image with any background color, B is a background image, namely a red (or white or blue, the background color of the certificate photo is selected according to actual use) pure-color image, and alpha is a mask value which represents the percentage of the foreground color contained in the color value corresponding to the synthesized image I or the opacity degree of the point.
The method for automatically replacing the background color of the certificate photo can effectively replace the background color of the certificate photo of the character, can completely keep the details of the hair of the character after the bottom is replaced, has good effect of replacing the bottom of the certificate photo of the character, can meet the requirement that an applicant can replace the background of the certificate photo by self without going out, can also quickly, efficiently, accurately and automatically acquire an image background area, and achieves good effect of replacing the bottom of the certificate photo.
Although the embodiments of the present invention have been described with reference to the accompanying drawings, it is not intended to limit the scope of the present invention, and it should be understood by those skilled in the art that various modifications and variations can be made without inventive efforts based on the technical solutions of the present invention.

Claims (10)

1. A method for automatically changing the background color of a certificate photo is applied to a server and is characterized by comprising the following steps:
carrying out edge detection on the certificate photo image to obtain a certificate photo edge image;
extracting an outer contour image of a character target area from the edge image of the certificate photo;
calculating a mask value required in image synthesis by adopting a digital matting algorithm based on global learning;
and according to the mask value obtained by calculation, taking the difference between 1 and the mask value as coefficients of a solid background image and a front background image of the certificate photo image respectively, and linearly superposing the solid background image and the front background image of the certificate photo image to finally obtain a synthesized certificate photo image.
2. The method for automatically changing the background color of the certificate photo as claimed in claim 1, wherein the edge detection algorithm fusing Sobel and K-means is adopted to perform edge detection on the certificate photo image to obtain the certificate photo edge image.
3. The method for automatically changing the background color of the certificate photo as claimed in claim 2, wherein the specific process of performing edge detection on the certificate photo image by adopting the edge detection algorithm fusing Sobel and K-means comprises the following steps:
(1-1): carrying out convolution on the four convolution templates and the identification photo image to obtain four gradient images Gx,Gy,G45,G135And four corresponding gradient histograms; the four convolution templates are detection convolution templates of Sobel operators for edges in the x direction, the y direction and 45 degrees and 135 degrees respectively;
(1-2): listing the gradient value ranges of the four gradient images obtained in the step (1-1);
(1-3): adopting a K-means algorithm to self-adaptively select a threshold, respectively carrying out threshold segmentation on the gradient image obtained in the step (1-1), and dividing all pixel points in the gradient image into two types: one belonging to the edge and one belonging to the background;
(1-4): classifying the gradient value of each pixel point in the gradient image;
(1-5): for each cluster, recalculating the centroid of the respective class;
(1-6): repeating the steps (1-4) to (1-5) until the variation amplitude of the mass center is in a range meeting the requirement;
(1-7): calculating a gradient threshold, wherein the optimal gradient threshold is a maximum value point in the background class or a minimum value point in the edge class;
(1-8): evaluating whether the selected gradient threshold is the optimal gradient threshold by adopting an Ostu algorithm, dividing all gradient values in the gradient image into two classes according to the gradient threshold selected in the step (1-7), and calculating the variance between the classes and the global variance to enable the threshold when the ratio of the two classes is the maximum to be the optimal gradient threshold;
(1-9): binarizing the gradient image according to the optimal gradient threshold value obtained in the steps (1-7) and (1-8) to obtain an edge image;
(1-10): respectively taking absolute values of the four gradient images obtained in the step (1-1) to obtain | Gx|、|Gy|、|G45|、|G135And (4) obtaining an edge image by using the steps (1-2) to (1-9) for each absolute value-taken gradient image, and performing exclusive OR on the four edge images to obtain a final edge image.
4. The method for automatically changing the background color of the certificate photo as claimed in claim 1, wherein the specific process of extracting the outline image of the character target area from the edge image of the certificate photo is as follows:
(2-1): adopting square structural elements to perform morphological expansion operation on the certificate image to connect possible edge fracture points;
(2-2): connecting the outline of the character target in the identification photo, searching two points with the minimum row coordinate in all white contour points of the first column and the last column from the image matrix obtained in the step (2-1), respectively regarding the two points as intersection points of the left shoulder, the right shoulder and the left side and the right side of the image, downwards supplementing the white contour points according to the two points, and setting the last row of the image matrix as a white contour to obtain a closed character target contour;
(2-3): marking each connected component formed by target pixel points in the image under the eight-adjacent structure for the image obtained in the step (2-2), calculating the number of pixel points corresponding to each connected component, and selecting the largest target connected component as the outline of the character target;
(2-4): carrying out image filling on the outline image of the person target obtained in the step (2-3) to obtain a person target area image;
(2-5): and (4) performing edge detection on the image of the character target area obtained in the step (2-4) by adopting a Canny operator to obtain an outline image outside the character target area.
5. The method for automatically changing the background color of the identification photo as claimed in claim 4, wherein the morphological dilation operation is performed on the edge image of the identification photo by using 4 x 4 square structural elements in the step (2-1).
6. The method for automatically changing the background color of the certificate photo as claimed in claim 1, wherein before the step of calculating the mask value required in the image synthesis by using the global learning-based digital matting algorithm, further comprising: and extracting a ternary image matrix trimap image from the outline image outside the human target area.
7. The method of claim 6, wherein the process of extracting the ternary image matrix trimap image from the outline image outside the human target area comprises:
and performing multiple morphological expansion operations on the outline image of the character target area by adopting 4 multiplied by 4 square structural elements to obtain a ternary image matrix trimap image, wherein the ternary image matrix trimap image comprises determined character target pixel points, background pixel points and pixel points of a category to be determined.
8. The method of claim 7, wherein in the process of calculating the mask value required in the image synthesis by using the global learning-based digital matting algorithm, the ternary image matrix trimap map is used as an input, the pixel point set composed of all pixel points in the ternary image matrix trimap map is Ω, and Ω includes the determined pixel point set ΩlAnd a set of pixel points Ω to be determinedu
Training a global alpha-color model by adopting a weighted ridge regression algorithm, and aiming at a pixel point set omega to be determineduAny pixel point in (1) is estimated by the linear global alpha-color modelAnd determining the mask value of the pixel point.
9. The method of claim 8, further comprising: and expanding the trained linear alpha-color model to a nonlinear alpha-color model by adopting a kernel rock algorithm, and estimating the mask value of the pixel point set to be determined by utilizing the nonlinear model.
10. The method of claim 1, wherein the solid background image comprises red, blue and white.
CN201710264952.8A 2017-04-21 2017-04-21 A kind of method of automatic replacement photo background color Active CN107123088B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710264952.8A CN107123088B (en) 2017-04-21 2017-04-21 A kind of method of automatic replacement photo background color

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710264952.8A CN107123088B (en) 2017-04-21 2017-04-21 A kind of method of automatic replacement photo background color

Publications (2)

Publication Number Publication Date
CN107123088A true CN107123088A (en) 2017-09-01
CN107123088B CN107123088B (en) 2019-09-13

Family

ID=59724949

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710264952.8A Active CN107123088B (en) 2017-04-21 2017-04-21 A kind of method of automatic replacement photo background color

Country Status (1)

Country Link
CN (1) CN107123088B (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107622504A (en) * 2017-09-30 2018-01-23 北京百度网讯科技有限公司 Method and apparatus for handling picture
CN108154086A (en) * 2017-12-06 2018-06-12 北京奇艺世纪科技有限公司 A kind of image extraction method, device and electronic equipment
CN108171677A (en) * 2017-12-07 2018-06-15 腾讯科技(深圳)有限公司 A kind of image processing method and relevant device
CN108256497A (en) * 2018-02-01 2018-07-06 北京中税网控股股份有限公司 A kind of method of video image processing and device
CN109145922A (en) * 2018-09-10 2019-01-04 成都品果科技有限公司 A kind of automatically stingy drawing system
CN109413330A (en) * 2018-11-07 2019-03-01 深圳市博纳思信息技术有限公司 A kind of certificate photograph intelligently changes background method
CN109660725A (en) * 2018-12-24 2019-04-19 惠州Tcl移动通信有限公司 Image capturing method, computer storage medium and mobile terminal
CN109697722A (en) * 2017-10-23 2019-04-30 北京京东尚科信息技术有限公司 For generating the method and device of three components
CN110008832A (en) * 2019-02-27 2019-07-12 西安电子科技大学 Based on deep learning character image automatic division method, information data processing terminal
WO2020082731A1 (en) * 2018-10-26 2020-04-30 平安科技(深圳)有限公司 Electronic device, credential recognition method and storage medium
CN111191580A (en) * 2019-12-27 2020-05-22 支付宝(杭州)信息技术有限公司 Synthetic rendering method, apparatus, electronic device and medium
CN111402291A (en) * 2020-03-04 2020-07-10 北京百度网讯科技有限公司 Method and apparatus for tracking a target
CN111476146A (en) * 2020-04-03 2020-07-31 北京金沙江科技有限公司 Mobile-terminal-based academic record certification standardized processing method

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102542275A (en) * 2011-12-15 2012-07-04 广州商景网络科技有限公司 Automatic identification method for identification photo background and system thereof
CN102592260A (en) * 2011-12-26 2012-07-18 广州商景网络科技有限公司 Certificate image cutting method and system
CN102750718A (en) * 2012-05-31 2012-10-24 山东神思电子技术股份有限公司 Background masking generating method
CN103473780A (en) * 2013-09-22 2013-12-25 广州市幸福网络技术有限公司 Portrait background cutout method
CN104504745A (en) * 2015-01-16 2015-04-08 成都品果科技有限公司 Identification photo generation method based on image segmentation and image matting

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102542275A (en) * 2011-12-15 2012-07-04 广州商景网络科技有限公司 Automatic identification method for identification photo background and system thereof
CN102592260A (en) * 2011-12-26 2012-07-18 广州商景网络科技有限公司 Certificate image cutting method and system
CN102750718A (en) * 2012-05-31 2012-10-24 山东神思电子技术股份有限公司 Background masking generating method
CN103473780A (en) * 2013-09-22 2013-12-25 广州市幸福网络技术有限公司 Portrait background cutout method
CN104504745A (en) * 2015-01-16 2015-04-08 成都品果科技有限公司 Identification photo generation method based on image segmentation and image matting

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
朱秋煌,黄素娟,王朔中: "证件照片的特征提取与检索", 《模式识别与人工智能》 *
李勤垂,陈若玲,王明楸,李佐勇: "融合边缘与过渡区域提取的人物证件照分割", 《福建电脑》 *
杨昆,张明新,先晓兵,郑金龙,聂盼红: "一种基于Sobel与K-means的边缘检测方法", 《光学技术》 *
王明楸,陈金聪,陈东昇,文龙,李佐勇: "人物证件照的自动换底算法", 《F福建电脑》 *
许华虎,王慧雅等: "身份证件人像自动采集与识别系统", 《上海大学学报(自然科学版)》 *

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107622504A (en) * 2017-09-30 2018-01-23 北京百度网讯科技有限公司 Method and apparatus for handling picture
CN109697722A (en) * 2017-10-23 2019-04-30 北京京东尚科信息技术有限公司 For generating the method and device of three components
CN108154086A (en) * 2017-12-06 2018-06-12 北京奇艺世纪科技有限公司 A kind of image extraction method, device and electronic equipment
CN108171677A (en) * 2017-12-07 2018-06-15 腾讯科技(深圳)有限公司 A kind of image processing method and relevant device
CN108171677B (en) * 2017-12-07 2023-03-24 腾讯科技(深圳)有限公司 Image processing method and related equipment
CN108256497A (en) * 2018-02-01 2018-07-06 北京中税网控股股份有限公司 A kind of method of video image processing and device
CN109145922B (en) * 2018-09-10 2022-03-29 成都品果科技有限公司 Automatic cutout system
CN109145922A (en) * 2018-09-10 2019-01-04 成都品果科技有限公司 A kind of automatically stingy drawing system
WO2020082731A1 (en) * 2018-10-26 2020-04-30 平安科技(深圳)有限公司 Electronic device, credential recognition method and storage medium
CN109413330A (en) * 2018-11-07 2019-03-01 深圳市博纳思信息技术有限公司 A kind of certificate photograph intelligently changes background method
CN109660725A (en) * 2018-12-24 2019-04-19 惠州Tcl移动通信有限公司 Image capturing method, computer storage medium and mobile terminal
CN110008832A (en) * 2019-02-27 2019-07-12 西安电子科技大学 Based on deep learning character image automatic division method, information data processing terminal
CN111191580A (en) * 2019-12-27 2020-05-22 支付宝(杭州)信息技术有限公司 Synthetic rendering method, apparatus, electronic device and medium
CN111402291A (en) * 2020-03-04 2020-07-10 北京百度网讯科技有限公司 Method and apparatus for tracking a target
CN111402291B (en) * 2020-03-04 2023-08-29 阿波罗智联(北京)科技有限公司 Method and apparatus for tracking a target
CN111476146A (en) * 2020-04-03 2020-07-31 北京金沙江科技有限公司 Mobile-terminal-based academic record certification standardized processing method

Also Published As

Publication number Publication date
CN107123088B (en) 2019-09-13

Similar Documents

Publication Publication Date Title
CN107123088B (en) A kind of method of automatic replacement photo background color
CN106778604B (en) Pedestrian re-identification method based on matching convolutional neural network
CN109035172B (en) Non-local mean ultrasonic image denoising method based on deep learning
CN103456013B (en) A kind of method representing similarity between super-pixel and tolerance super-pixel
CN103914699A (en) Automatic lip gloss image enhancement method based on color space
CN103080979B (en) From the system and method for photo synthesis portrait sketch
CN109948625A (en) Definition of text images appraisal procedure and system, computer readable storage medium
CN107122713B (en) Analog property detection method based on deep learning
CN111310768B (en) Saliency target detection method based on robustness background prior and global information
JP2017117019A (en) Image processing device, image processing method, and program
CN110827304A (en) Traditional Chinese medicine tongue image positioning method and system based on deep convolutional network and level set method
CN109242876A (en) A kind of image segmentation algorithm based on markov random file
CN107123130A (en) Kernel correlation filtering target tracking method based on superpixel and hybrid hash
CN105761292A (en) Image rendering method based on color shift and correction
CN117853722A (en) Steel metallographic structure segmentation method integrating superpixel information
CN114494739B (en) Toner mixing effect detection method based on artificial intelligence
CN114187215A (en) Local recoloring algorithm based on image segmentation
WO2020119624A1 (en) Class-sensitive edge detection method based on deep learning
Kuzovkin et al. Descriptor-based image colorization and regularization
CN112070116B (en) Automatic artistic drawing classification system and method based on support vector machine
JP2015094973A (en) Image processor, image processing method, image processing program, and recording medium
CN105701816A (en) Automatic image segmentation method
CN113850748A (en) Point cloud quality evaluation system and method
CN107146215A (en) A kind of conspicuousness detection method based on color histogram and convex closure
CN113223098B (en) Preprocessing optimization method for image color classification

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant