Method and System for Replacing Background of ID Photo

By comprehensively using the transformation of portrait foreground color, new background color, original background color and α value, the problem of inconsistency between portrait and background transition area in background replacement of document photo is solved, achieving a more natural background replacement effect.

CN114092317BActive Publication Date: 2025-07-04CHANGZHOU INST OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111304046.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-05
Publication Date
2025-07-04
Estimated Expiration
2041-11-05

AI Technical Summary

Technical Problem

The existing method of replacing backgrounds of document photos depends on manual operation, which is inefficient and ineffective, and the portrait and background transition areas are inconsistent, and the nature is poor.

Method used

Comprehensively use portrait foreground color, new background color, original background color and α value, and transform the α value to calculate the color value of the synthetic photo to highlight or suppress the details of the transition area.

Benefits of technology

The portrait after the background replacement of the ID photo is clear and complete, and the transition area is natural and coordinated, which improves the effect of background replacement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114092317B_ABST
    Figure CN114092317B_ABST
Patent Text Reader

Abstract

The present invention relates to the application of image processing technology, mainly a method and system for replacing the background of a certificate photo, which can comprehensively calculate the color values of the synthesized photo by using the foreground color of the portrait, the new background color, the original background color and the opacity α value. By transforming the α value, the details of the transition area are highlighted or suppressed to achieve a better photo background replacement effect, including the following steps: Step 1: Input the certificate photo I'; Step 2: Select the new background color B; Step 3: Portrait matting, perform matting processing on the original photo, calculate the opacity of each pixel, and generate an Alpha map; Step 4: α value transformation, transform the α value of each pixel in the Alpha map as needed; Step 5: Calculate the original background color, search for pixels with an opacity α value of 0 in the photo, and calculate the average value of the red, green, and blue color components respectively as the original background color B'; Step 6: Photo synthesis, generate the certificate photo I with the background replaced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the application of image processing technology, mainly a background replacement method and system for ID photos. Background Art

[0002] When people apply for various certificates, the issuing authorities have different requirements for the specifications of certificate photos, especially the background color of certificate photos. In order to make the background color of the photo meet the standard, image processing software is usually used to replace the background of the certificate photo to meet different specifications. However, this method relies on manual operation, is inefficient, and has poor results.

[0003] First, the foreground of the portrait is extracted from the photo using the cutout technology; Chinese patent CN201310432686.7 discloses a method for cutting out the background of a portrait and Chinese patent CN201810085180.6 discloses a method for intelligently replacing the background of a portrait in a second-generation ID card photo. The Alpha map of the foreground of the portrait is calculated based on the Trimap map.

[0004] Then, based on the Alpha map, the portrait foreground is synthesized with a specific background. For example, Chinese patent CN201811032661.7 discloses a method, system and server for automatic background replacement of ID photos. The disclosed ID photo synthesis method decomposes the image into background area, foreground area and unknown area, and uses the formula: I(z) = α(z)F(z) + (1-α(z))B(z) to calculate the synthesized photo to achieve background replacement of the ID photo. Among them, z represents a pixel in the photo, F(z) is the foreground color of the portrait, B(z) is the new background color, and α(z) is the opacity of the corresponding pixel in the Alpha map.

[0005] When synthesizing photos, only the original photo's portrait foreground, new background, and alpha value are considered. However, in actual photos, the portrait foreground will be affected by the original background color, especially in the foreground-background transition area. If only the extracted portrait foreground color and the new background color are used to calculate the pixel color of the synthesized photo, the transition area between the portrait and the background will be inconsistent and unnatural.

[0006] Therefore, it is necessary to comprehensively use the portrait foreground color, new background color, original background color and alpha value to calculate the color value of the composite photo; so that after the background of the ID photo is replaced, the portrait is clear and complete, and the transition area is natural and coordinated. Summary of the invention

[0007] To solve this problem, the present invention provides a method and system for replacing the background of a certificate photo, which can comprehensively calculate the color values of the synthesized photo by using the foreground color of the portrait, the new background color, the original background color, and the opacity α value. By transforming the α value, the details of the transition area are highlighted or suppressed to achieve a better effect of replacing the photo background.

[0008] To solve the above technical problems, the technical solution adopted by the present invention is as follows: A method for replacing the background of a certificate photo, comprising the following steps:

[0009] Step 1: Input the certificate photo I'.

[0010] Step 2: Select the new background color B.

[0011] Step 3: Perform portrait matting. The original photo is processed by matting to extract the portrait foreground of the photo, calculate the opacity corresponding to each photo pixel, and generate an Alpha map.

[0012] Step 4: α value transformation. Transform the α values of the pixels in the Alpha map as needed.

[0013] Step 1: Input the certificate photo I'.

[0014] Step 2: Select the new background color B.

[0015] Step 3: Perform portrait matting. The original photo is processed by matting to calculate the opacity of each pixel and generate an Alpha map.

[0016] Step 4: α value transformation. Transform the α values of the pixels in the Alpha map as needed.

[0017] Step 5: Calculate the original background color. Search for the pixels with an opacity α value of 0 in the photo, and calculate the average values of the red, green, and blue color components respectively as the original background color B'.

[0018] Step 6: Photo synthesis. Generate the certificate photo I with the background replaced.

[0019] Preferably, in the step 4, different non-linear transformation functions are selected according to different requirements to transform the α value.

[0020] Preferably, in the step 6, considering the original photo I', the original background B', the new background B, and the Alpha map comprehensively, use the following formula: I(z) = I'(z) + (1 - α(z)) * B(z) - (1 - α(z)) * B'(z) to calculate the color value of each pixel in the synthesized photo I.

[0021] To solve the above technical problems, the technical solution adopted by the present invention is as follows: A background replacement system for ID photos, comprising: a photo input module for inputting ID photos, a new background selection module, a portrait matting module, an α value transformation module, an original background calculation module, and a photo synthesis module; wherein,

[0022] The new background selection module is used to select a new background color for the photo;

[0023] The portrait matting module is used to perform portrait matting processing on the original photo, calculate the opacity corresponding to each photo pixel, and generate an Alpha map of the photo;

[0024] The α value transformation module is used to perform transformation processing on the α values of each pixel in the Alpha map generated by the portrait matting module; different non-linear transformation functions are selected to transform the α values to highlight or suppress the details in the transition area between the portrait foreground and the background;

[0025] The original background calculation module is used to calculate the original background color value B' of the ID photo; search and count the pixels corresponding to the opacity α value of 0 in the photo, and calculate the average value of the red, green, and blue color components respectively as the original background color B';

[0026] The photo synthesis module is used to synthesize a new ID photo I to achieve background replacement of the ID photo; when calculating the color value of each pixel of the synthesized photo, the original photo I', the original background B', the new background B, and the Alpha map are comprehensively considered.

[0027] The background replacement method and system for ID photos of the present invention can achieve the following beneficial effects: When calculating the color value of the synthesized photo, the original photo, the original background, the new background, and the Alpha map are comprehensively considered. By transforming the α value, the details of the portrait foreground are further highlighted. The background replacement photo realized by the present invention has a clearer and more complete portrait foreground, and the transition area between the portrait foreground and the background is more natural and harmonious. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] Figure 1 It is a schematic flow chart of the background replacement method for ID photos;

[0029] Figure 2 It is a curve graph of the α value transformation function in the embodiment of the present invention;

[0030] Figure 3 It is a schematic structural diagram of the background replacement system for ID photos. DETAILED DESCRIPTION OF THE INVENTION

[0031] The present invention will be further described below with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention and should not be used to limit the protection scope of the present invention.

[0032] The method for replacing the background of an ID photo provided in this embodiment is as Figure 1 shown.

[0033] I. Input the ID photo. Represent the input original photo as I'.

[0034] II. Select a new background color. Represent the new photo background as B.

[0035] III. Portrait matting. Use a matting algorithm to perform matting processing on the photo, extract the portrait foreground of the photo, calculate the opacity corresponding to each photo pixel, and generate an Alpha map. The opacity of the pixel is represented as α'. Among them, α' corresponding to the pixels in the portrait area is 1, α' corresponding to the pixels in the background area is 0, and 0 < α' < 1 for the pixels in the foreground-background transition area.

[0036] IV. α value transformation. In order to further highlight the details of the foreground-background transition area of the portrait, transform the α' values corresponding to each pixel in the Alpha map.

[0037] Select the non-linear transformation function as Figure 2 shown: f(x) = 1 - (x - 1) 2 , and transform the Alpha value α = f(α'). After the transformation, α corresponding to the pixels in the portrait area is 1, α corresponding to the pixels in the background area is 0, and 0 < α < 1 for the pixels in the foreground-background transition area.

[0038] V. Calculate the original background color. Based on the Alpha map, search and count the pixels corresponding to the opacity α value of 0 in the photo, and calculate the average value of the red, green, and blue color components respectively as the original background color B';

[0039] VI. Photo synthesis. Calculate the color value of each pixel in the synthesized photo to achieve background replacement of the photo. When calculating the color value of the synthesized photo, comprehensively consider the original photo I', the original background B', the new background B, and the Alpha map, and use the following formula: I(z) = I'(z) + (1 - α(z)) * B(z) - (1 - α(z)) * B'(z) to calculate the color value of each pixel in the synthesized photo I.

[0040] This embodiment also provides a system for replacing the background of an ID photo, as Figure 3 shown. The system for replacing the background of an ID photo includes: a photo input module, a new background selection module, a portrait matting module, an α value transformation module, an original background calculation module, and a photo synthesis module.

[0041] Among them,

[0042] I. The photo input module is used to input the original photo;

[0043] II. Background selection module, which is used to select a new photo background color;

[0044] III. Portrait matting module, which is used to perform portrait matting processing on the original photo, calculate the opacity corresponding to each photo pixel, and generate an Alpha map of the photo.

[0045] IV. Alpha value transformation module, which is used to perform transformation processing on the Alpha value in the Alpha map generated by the portrait matting module.

[0046] V. Original background calculation module, which is used to calculate the background color value B' of the original photo. Search and count the pixels corresponding to the opacity Alpha value of 0 in the photo, and calculate the average value of the red, green, and blue color components respectively as the original background color B'.

[0047] VI. Photo synthesis module, which is used to calculate the color value of each pixel, synthesize a new ID photo I, and realize the background replacement of the photo.

[0048] When calculating the color value of each pixel in the synthesized photo I, the original photo I', the original background B', the new background B, and the Alpha map are comprehensively considered.

[0049] The above is only the preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the technical principle of the present invention, several improvements and deformations can be made, and these improvements and deformations should also be regarded as the protection scope of the present invention.

Claims

1. Method for replacing the background of a certificate photo, characterized in that: Including the following steps: Step 1: Input the ID photo I'. Step 2: Select the new background color B. Step 3: Portrait matting, perform matting processing on the original photo, calculate the opacity of each pixel, and generate an Alpha map. Step 4: Alpha value transformation, transform the Alpha values of the pixels in the Alpha map as needed. To highlight the details of the transition region between the portrait foreground and the background, a non-linear function is selected: f(x) = 1 - (x - 1) 2 Perform a transformation on the α' values corresponding to each pixel in the Alpha map: α = f(α'); after the transformation, for the pixels in the portrait area, α = 1, for the pixels in the background area, α = 0, and for the pixels in the foreground-background transition area, 0 < α < 1; Step 5: Calculate the original background color, search for pixels with an opacity Alpha value of 0 in the photo, and calculate the average values of the red, green, and blue color components respectively as the original background color B'. Step 6: Photo synthesis, generate the ID photo I with the background replaced. Comprehensively considering the original photo I', the original background B', the new background B, and the Alpha map, use the following formula: I(z) = I'(z) + (1 - α(z)) * B(z) - (1 - α(z)) * B'(z) to calculate the color value of each pixel in the synthesized photo I; where z represents each pixel point in the photo image, I(z) represents the color value of the pixel point z after replacement, I'(z) represents the color value of the pixel point z before replacement, B(z) represents the new background color selected in Step 2, B'(z) represents the original background color calculated in Step 5; α(z) represents the opacity value corresponding to the pixel point z.

2. A background replacement system for ID photos, characterized in that: Including: A photo input module for inputting ID photos, a new background selection module, a portrait matting module, an Alpha value transformation module, an original background calculation module, and a photo synthesis module; where The new background selection module is used to select a new photo background color. The portrait matting module is used to perform portrait matting processing on the original photo, calculate the opacity corresponding to each photo pixel, and generate an Alpha map of the photo. The Alpha value transformation module is used to perform transformation processing on the Alpha values of the pixels in the Alpha map generated by the portrait matting module; select a non-linear transformation function to transform the Alpha values to highlight the details of the transition area between the portrait foreground and the background. The original background calculation module is used to calculate the original background color value B' of the ID photo; search and count the pixels corresponding to an opacity Alpha value of 0 in the photo, and calculate the average values of the red, green, and blue color components respectively as the original background color B'. The photo synthesis module is used to synthesize a new ID photo I to achieve background replacement of the ID photo; when calculating the color value of each pixel in the synthesized photo, comprehensively consider the original photo I', the original background B', the new background B, and the Alpha map. Select a non-linear function: f(x) = 1 - (x - 1) 2 Perform a transformation on the α' values corresponding to each pixel in the Alpha map: α = f(α'); after the transformation, for pixels in the human figure area, α = 1, for pixels in the background area, α = 0, and for pixels in the foreground-background transition area, 0 < α < 1; Considering the original photo I’, the original background B’, the new background B and the Alpha map comprehensively, use the following formula: I(z) = I’(z) + (1 - α(z)) * B(z) - (1 - α(z)) * B’(z) to calculate the color value of each pixel in the synthesized photo I; where z represents each pixel point in the photo image, I(z) represents the color value of the pixel point z after replacement, I’(z) represents the color value of the pixel point z before replacement, B(z) represents the selected new background color, B’(z) represents the calculated original background color; α(z) represents the opacity value corresponding to the pixel point z.

Citation Information

Patent Citations

  • A method for background cutout of portrait images

    CN103473780B

  • A method for intelligent and fully automatic replacement of portrait background in second-generation ID card photos

    CN108320294B

  • A method, system, and server for automatic background replacement of ID photos.

    CN109344724B

  • Automatic background replacement method, system and server for certificate photo

    CN109344724A