Image processing method, device, equipment and computer readable storage medium
By acquiring and correcting the alpha channel map, foreground map and background map in the original image in image processing, the image inconsistency problem caused by inaccurate labeling data is solved, and higher image accuracy and authenticity are achieved.
Patent Information
- Application Number
- CN202210631904.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-06
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-06-06
AI Technical Summary
The prior art images generated by the cutout method in image processing have problems of inconsistency and inaccuracy, mainly due to the inaccuracy of manual labeling data.
By obtaining the marked original image, the alpha channel diagram, foreground diagram and background diagram are extracted, and the target image is generated through a series of correction steps, including correction of the background diagram, foreground diagram and channel diagram.
It improves the accuracy and authenticity of the generated image, reduces the impact of manual annotation data on image processing results, and ensures that the image after cutting is free of incongruity.
Smart Images

Figure CN114937057B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to an image processing method, device, equipment and computer-readable storage medium. Background Art
[0002] With the development of computer technology, image processing is becoming more and more common. In the field of image processing, cutout and image synthesis is an important technical direction. Image-based cutout is to extract people or other specified foreground objects in an image through cutout technology. At present, the matting method can be used. When the matting method is used, manual data annotation is required. If the manual annotation data is inaccurate, the subsequent synthesized picture will be "fake", with a sense of disobedience, and it is difficult to meet the requirements, resulting in poor image processing effect. Summary of the invention
[0003] The main purpose of the present invention is to provide an image processing method, device, equipment and computer-readable storage medium, aiming to solve the technical problem of how to improve the accuracy of generated images.
[0004] To achieve the above object, the present invention provides an image processing method, comprising the following steps:
[0005] Obtaining an alpha channel image and a foreground image according to the marked original image, and determining a background image corresponding to the original image;
[0006] Correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image;
[0007] Correcting the foreground image according to the target background image, the original image and the alpha channel image to obtain a target foreground image;
[0008] Correcting the alpha channel image according to the target background image, the original image and the target foreground image to obtain a target channel image;
[0009] A target image is generated according to the target background image, the target channel image and the target foreground image.
[0010] Optionally, the step of correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image includes:
[0011] Determining a conversion relationship between the original image, the alpha channel image, and the foreground image;
[0012] Determine all channel values of the alpha channel map, and convert the alpha channel map according to all channel values to obtain a converted channel map;
[0013] A modified conversion is performed according to the original image, the conversion channel image, the foreground image and the conversion relationship to obtain a conversion background image, and a target background image is determined according to the conversion background image.
[0014] Optionally, the step of converting the alpha channel map according to all the channel values to obtain a converted channel map comprises:
[0015] Determine the maximum channel value and the minimum channel value among all the channel values, and determine the target channel area where the maximum channel value in the alpha channel map is located;
[0016] Convert the single-digit channel values in other channel areas except the target channel area in the alpha channel image into minimum channel values to obtain an alpha channel image after initial conversion;
[0017] The alpha channel map after the initial conversion is normalized to obtain a conversion channel map.
[0018] Optionally, the step of determining the target background image according to the conversion background image includes:
[0019] Determine a pure foreground image region in the conversion background image according to the conversion channel image;
[0020] The pixel values of the pure foreground image area are cleared to obtain a target background image.
[0021] Optionally, the step of correcting the foreground image according to the target background image, the original image and the alpha channel image comprises:
[0022] Determine all conversion channel values in the conversion channel map, and detect whether the conversion channel value is a minimum channel value;
[0023] If the conversion channel value is not the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is corrected according to the target background image, the original image, the conversion channel image and the conversion relationship.
[0024] Optionally, after the step of detecting whether the conversion channel value is the minimum channel value, the method further comprises:
[0025] If the conversion channel value is the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is cleared.
[0026] Optionally, the step of correcting the alpha channel image according to the target background image, the original image and the target foreground image comprises:
[0027] Determine all conversion channel values in the conversion channel map corresponding to the alpha channel map, and detect whether the conversion channel value is a minimum channel value;
[0028] If the conversion channel value is the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel image is kept unchanged;
[0029] If the conversion channel value is not the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel image is corrected according to the target background image, the original image, and the target foreground image.
[0030] In addition, to achieve the above object, the present invention also provides an image processing device, comprising:
[0031] A determination module, used to obtain an alpha channel image and a foreground image according to the marked original image, and determine a background image corresponding to the original image;
[0032] A correction module, used for correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image;
[0033] The correction module is used to correct the foreground image according to the target background image, the original image and the alpha channel image to obtain a target foreground image;
[0034] The correction module is used to correct the alpha channel image according to the target background image, the original image and the target foreground image to obtain a target channel image;
[0035] A generating module is used to generate a target image according to the target background image, the target channel image and the target foreground image.
[0036] In addition, to achieve the above-mentioned purpose, the present invention also provides an image processing device, which includes a memory, a processor, and an image processing program stored in the memory and executable on the processor, and when the image processing program is executed by the processor, the steps of the image processing method as described above are implemented.
[0037] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which an image processing program is stored, and when the image processing program is executed by a processor, the steps of the above-mentioned image processing method are implemented.
[0038] The present invention first determines the original image, channel image, foreground image and background image, and then corrects the background image according to the original image, channel image and foreground image to obtain the target background image, so that the influence of the artificially labeled data on the background can be reduced, and then the foreground image is corrected according to the target background image, the original image and the channel image to obtain the target foreground image, so that the influence of the artificially labeled data on the foreground can be reduced, and then the channel image is corrected according to the target background image, the original image and the target foreground image to obtain the target channel image, so that the influence of the artificially labeled data on the transparency can be reduced, and finally the target image is generated according to the target background image, the target channel image and the target foreground image, that is, the cutout image in the original image is obtained. Thus, the target image obtained after the cutout operation can be realized without a sense of violation, the accuracy of the generated image is improved, and since the background, foreground and transparency are all corrected, the authenticity of the generated target image is also made higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 It is a schematic diagram of the terminal\device structure of the hardware operating environment involved in the embodiment of the present invention;
[0040] Figure 2 It is a flowchart of a first embodiment of an image processing method of the present invention;
[0041] Figure 3 FIG. 4 is a schematic diagram of a device module of an image processing device of the present invention.
[0042] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings in conjunction with the embodiments. DETAILED DESCRIPTION
[0043] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0044] like Figure 1 As shown, Figure 1 It is a schematic diagram of the terminal structure of the hardware operating environment involved in the embodiment of the present invention.
[0045] The terminal in the embodiment of the present invention is an image processing device.
[0046] like Figure 1As shown, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0047] Optionally, the terminal may also include a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. Among them, the sensors include light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display screen according to the brightness of the ambient light, and the proximity sensor may turn off the display screen and / or backlight when the terminal device is moved to the ear. Of course, the terminal device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be repeated here.
[0048] Those skilled in the art will understand that Figure 1 The terminal structure shown in the figure does not constitute a limitation on the terminal, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0049] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an image processing program.
[0050] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and perform data communication with the client; and the processor 1001 can be used to call the image processing program stored in the memory 1005 and perform the following operations:
[0051] Reference Figure 2 The present invention provides an image processing method. In a first embodiment of the image processing method, the image processing method comprises the following steps:
[0052] Step S10, obtaining an alpha channel image and a foreground image according to the marked original image, and determining a background image corresponding to the original image;
[0053] In this embodiment, the original image is I, the alpha image is α, the foreground image is fg, and the background image is B. The alpha image can be a map used to specify transparency for pixels in an image. It is a single channel with a depth of 8, and each element is an integer in the interval [0,255]. 0 represents complete transparency, and 255 represents complete opacity. The person (object) that we need to cut out in the image, including all its details, is called the "foreground". The foreground image needs to contain all the foreground and all the details we need, and the background color that contains both the foreground and background colors (i.e., translucent) needs to be removed.
[0054] Since the current image processing for synthesizing images may cause the generated image to have a sense of disharmony and poor image processing effect, in this embodiment, the background is corrected first, then the foreground is corrected, and finally the transparency is corrected, and then the corrected images are synthesized to obtain a synthesized result image.
[0055] Therefore, this embodiment can be applied to image processing scenarios, and image processing may include but is not limited to image transformation, image coding compression, image enhancement and restoration, image segmentation, image description, cutout, and image classification.
[0056] Therefore, in this embodiment, it is necessary to first obtain the annotated original image, and then obtain the alpha image, fg image and B image corresponding to the original image according to the image tool (such as Photoshop), that is, the alpha channel image, the foreground image and the background image. The foreground image and the background image can be obtained by first obtaining the processed original image, wherein the original image can be read from a camera, a computer, a camera or other image storage device, and the original image can be an image in various formats, such as a bitmap format, a tagged image file format, a graphics interchange format, a joint photo experts group, etc., which is not specifically limited here. After obtaining the original image, the original image is copied to obtain the copied original image, i.e., the copied original image. It is determined whether the copied original image is a single-channel image (i.e., a grayscale image). If the copied original image is a grayscale image, the grayscale value of each pixel in the grayscale image is subjected to high-frequency filtering to obtain a first grayscale image. According to the grayscale image and the first grayscale image, the grayscale value of each pixel in the grayscale image is subjected to Kalman filtering to obtain a template image of the grayscale image. The distance norm of the difference between the grayscale value of each pixel in the template image and the grayscale value of the corresponding pixel in the first grayscale image is calculated. If the distance norm is greater than a preset threshold, the current pixel is defined as a foreground image, otherwise, the current pixel is defined as a background image. The alpha channel image, foreground image, and background image can also be directly obtained through image tools (such as Photoshop).
[0057] Step S20, correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image;
[0058] In this embodiment, since the manually annotated data will inevitably have inaccuracies, that is, the synthesized image cannot be completely consistent with the original image, so the result of the manual annotation needs to be corrected and adjusted. Before the correction and adjustment, the conversion relationship between the four images of the original image, the alpha channel image, the foreground image and the background image is first determined, and the formula corresponding to the conversion relationship is determined, that is, I = α*F+(1-α)*B. Among them, I is the original image, F is the fg image, that is, the foreground image, and α is the alpha image of the channel transparency, that is, the channel image.
[0059] And in this embodiment, when correcting the background image, you can choose to fix the original image, alpha image and foreground image first, and then correct the background image according to the original image, alpha image and foreground image. Specifically, because there may be slight errors when the alpha image is obtained by cutting out the image tool, the accuracy of the obtained alpha image is affected. Therefore, you can first make a simple initial adjustment to the alpha image to obtain a conversion channel image, and then correct the background image according to the original image, the conversion channel image and the foreground image. And it should be noted that in this embodiment, the channel value range of the conversion channel image is [0,1].
[0060] In this embodiment, the formula corresponding to the conversion relationship is adjusted from I=α*F+(1-α)*B to:
[0061] Among them, α′ is the conversion channel map. ε is a minimum value, which is used to ensure that (1-α′) as the denominator is not 0, for example, it is set to 10 to the negative 15th power. And when correcting the background image, all pixel values in the background image can be determined first, and each pixel value can be corrected. When all pixel values are completed, the corrected background image, that is, the target background image, is obtained. Among them, when correcting the pixel values in the background image, the original image, the conversion channel image, and the foreground image can be aligned with the background image in sequence, and the pixel area in the background image where the pixel value to be corrected is determined, and then the original pixel value of the area corresponding to the pixel area in the original image (that is, the pixel value in the original image) is determined, the channel value of the area corresponding to the pixel area in the conversion channel image is determined, and the foreground pixel value of the area corresponding to the pixel area in the foreground image (that is, the pixel value in the foreground image) is determined, and then the adjusted formula is used for calculation to obtain the corrected pixel value.
[0062] Step S30, correcting the foreground image according to the target background image, the original image and the alpha channel image to obtain a target foreground image;
[0063] In this embodiment, after completing the correction of the background image and obtaining the target background image, it is necessary to continue to correct the foreground image to obtain the target foreground image. Specifically, the foreground image can be corrected according to the conversion channel image corresponding to the target background image, the original image, and the alpha channel image. Moreover, when correcting the foreground image, it is necessary to adjust the formula I=α*F+(1-α) corresponding to the conversion relationship between the four images of the original image, the alpha channel image, the foreground image, and the background image, and replace the alpha channel image α with the conversion channel image α′ during the adjustment. And when correcting the foreground image, since the range of the channel value of the conversion channel image α′ is [0,1], there is a case where the channel value of the conversion channel image α′ is 0. When the channel value of the conversion channel image α′ is 0, the above formula cannot be used for correction.
[0064] Therefore, when correcting the foreground image, first align the original image, the conversion channel image, the foreground image and the background image in turn, and determine all the pixel values in the foreground image, and use them as the foreground pixel values. Then determine the area in the foreground image corresponding to the foreground pixel value to be corrected, and use it as the foreground area. At this time, it is necessary to first determine whether the channel value of the channel area corresponding to the foreground area in the conversion channel image is 0. If it is 0, the foreground pixel value to be corrected is directly corrected to 0, that is, the corrected foreground pixel value is 0. If the channel value of the channel area corresponding to the foreground area in the conversion channel image is not 0, then determine the original pixel value of the area corresponding to the foreground area in the original image, determine the background pixel value of the area corresponding to the foreground area in the target background image (that is, the pixel value in the target background image), and then according to the adjusted formula Calculation is performed to obtain the corrected foreground pixel value. After completing the correction of all pixel values in the foreground image, the corrected foreground image, i.e., the target foreground image, can be obtained.
[0065] Step S40, correcting the alpha channel image according to the target background image, the original image and the target foreground image to obtain a target channel image;
[0066] After the background image and the foreground image are adjusted to obtain the target background image and the target foreground image, the channel image needs to be adjusted to obtain the target channel image. Specifically, the alpha channel image can be corrected according to the target background image, the original image and the target foreground image. When correcting the alpha channel image, the formula I=α*F+(1-α) corresponding to the conversion relationship between the four images of the original image, the alpha channel image, the foreground image and the background image needs to be adjusted, and the background image B is replaced with the target background image B during the adjustment. t , replace the foreground image F with the target foreground image F t .get And there is a special case that the pixel values at the same position in the target foreground image and the target background image are equal.
[0067] Therefore, when correcting the alpha channel map, it can be determined based on the conversion channel map. Since when the channel value of a certain position in the conversion channel map is 0, the pixel value of the area corresponding to the position in the target background map will not be 0. Therefore, when correcting the alpha channel map, it can be determined whether the pixel value in the conversion channel map is 0. If it is 0, the channel value in the channel map remains unchanged. If it is not 0, the alpha channel map is corrected according to the target background map, the original map and the target foreground map to obtain the target channel map.
[0068] Step S50, generating a result image according to the target background image, the target channel image and the target foreground image.
[0069] After the background image is corrected and adjusted to obtain the target background image, the foreground image is corrected and adjusted to obtain the target foreground image, and the channel image is corrected and adjusted to obtain the target channel image, the result image obtained by the cutout operation from the original image can be directly generated according to the target background image, the target channel image and the target foreground image.
[0070] In this embodiment, by first determining the original image, channel image, foreground image and background image, and then correcting the background image according to the original image, channel image and foreground image, a target background image is obtained, so that the influence of the artificially labeled data on the background can be reduced, and then the foreground image is corrected according to the target background image, the original image and the channel image to obtain the target foreground image, so that the influence of the artificially labeled data on the foreground can be reduced, and then the channel image is corrected according to the target background image, the original image and the target foreground image to obtain the target channel image, so that the influence of the artificially labeled data on the transparency can be reduced, and finally the target image is generated according to the target background image, the target channel image and the target foreground image, that is, the cutout image in the original image is obtained. Thus, the target image obtained after the cutout operation can be realized without a sense of violation, the accuracy of the generated image is improved, and since the background, foreground and transparency are all corrected, the authenticity of the generated target image is also made higher.
[0071] Further, based on the first embodiment of the present invention, a second embodiment of the image processing method of the present invention is proposed. In this embodiment, the refinement of the step S20 of the above embodiment, in which the background image is corrected according to the original image, the alpha channel image and the foreground image to obtain the target background image, includes:
[0072] Step a, determining a conversion relationship between the original image, the alpha channel image and the foreground image;
[0073] In this embodiment, since the alpha channel map, foreground map and foreground map are all obtained from the original image, there is a corresponding conversion relationship between the alpha channel map, foreground map, foreground map and original image, so as to adjust the alpha channel map, foreground map and foreground map later. That is, before adjusting the background image, it is necessary to first determine the formula corresponding to the conversion relationship between the original image, the alpha channel map and the foreground map, that is: I = α*F+(1-α)*B. Among them, I is the original image, F is the fg map, that is, the foreground map, and α is the alpha channel map of the channel transparency. And in this embodiment, the pixel value conversion in the alpha channel map, foreground map, foreground map and original image can be calculated and converted according to the formula corresponding to this conversion relationship.
[0074] Step b, determining all channel values of the alpha channel map, and converting the alpha channel map according to all channel values to obtain a converted channel map;
[0075] Since the alpha channel map obtained by cutout may have errors, all channel values of the alpha channel map are first converted to channel values in the range of [0, 1] to obtain a conversion channel map. That is, the channel values of all regions in the alpha channel map are determined. It should be noted that the alpha channel map in this embodiment is a single channel with a depth of 8. Each element is an integer in the interval [0, 255]. 0 represents complete transparency and 255 represents complete opacity. Therefore, the channel value of each region in the alpha channel map may be the minimum channel value 0 or the maximum channel value 255. And in order to facilitate the calculation of the subsequent conversion formula and to facilitate the adjustment of the original image, the alpha channel map and the foreground image, it is necessary to adjust the range of the channel value of each region in the alpha channel map from [0, 255] to [0, 1]. The adjustment method can be to divide the channel values of all regions in the alpha channel map by the maximum channel value, that is, 255, to obtain the adjusted channel values of all regions in the alpha channel map, and use it as the conversion channel map.
[0076] Step c, performing a correction conversion according to the original image, the conversion channel image, the foreground image and the conversion relationship to obtain a conversion background image, and determining a target background image according to the conversion background image.
[0077] After determining the conversion channel map, foreground map and original map, the pixel values of each area in the background map can be corrected and converted according to the formula corresponding to the conversion relationship to obtain the conversion background map, and then the area with a channel value of 1 in the conversion channel map of the conversion background map is adjusted to 0 to obtain the target background map. When correcting and adjusting the pixel values of a certain area in the background map, you can first follow Calculation is performed to obtain the pixel value to be adjusted, and the pixel value of the area in the background image is corrected and adjusted to the pixel value to be adjusted.
[0078] In this embodiment, when correcting the background image, the conversion relationship between the original image, the alpha channel image and the foreground image is first determined, and then the alpha channel image is converted into a conversion channel image. Then, the correction conversion is performed according to the conversion channel image, the original image, the foreground image and the conversion relationship to obtain a conversion background image, and the target background image is determined according to the conversion background image, thereby ensuring the accuracy of the acquired target background image.
[0079] Specifically, the step of converting the alpha channel map according to all the channel values to obtain the converted alpha channel map includes:
[0080] Step d, determining the maximum channel value and the minimum channel value among all the channel values, and determining the target channel area where the maximum channel value in the alpha channel map is located;
[0081] In this embodiment, when the alpha channel image is converted, it is necessary to first determine the channel values of all regions in the alpha channel image, and determine the maximum channel value and the minimum channel value. In this embodiment, the maximum channel value of the alpha channel image can be 255. The minimum channel value can be 0. In order to ensure that the channel values of the background part are all 0, the position area where the maximum channel value in the alpha channel image is located can be determined, that is, the target channel area, for example, the position area corresponding to the radius of 10 pixels of the 255 value.
[0082] Step e, converting the single-digit channel values in other channel areas except the target channel area in the alpha channel map into minimum channel values to obtain an alpha channel map after initial conversion;
[0083] After determining the target channel area, determine the other channel areas in the alpha channel map except the target channel area, and convert the single-digit channel values in other channel areas to the minimum channel value. If there is a channel value of 5 in other channel areas, the channel value in this channel area can be adjusted from 5 to 0. For example, the part with a channel value less than 10 outside the radius of 10 pixels of the 255 value is directly set to 0. After converting the single-digit channel value to the minimum channel value, the alpha channel map can be directly used as the alpha channel map after the initial conversion.
[0084] Step f, normalizing the alpha channel map after the initial conversion to obtain a conversion channel map.
[0085] In order to ensure that the range of all channel values in the final conversion channel map is within the range of [0, 1], the alpha channel map after the initial conversion can be normalized, that is, the channel values of all areas in the alpha channel map after the initial conversion are divided by the maximum channel value to obtain its proportional value, and this proportional value is used as the adjustment channel value, and all channel values in all areas of the alpha channel map after the initial conversion are adjusted to their corresponding adjustment channel values, and the adjusted alpha channel map after the initial conversion is used as the conversion channel map.
[0086] In this embodiment, by determining a target channel area in the alpha channel map with the position of the maximum channel value as the center and the preset channel value as the radius, the single-digit channel values in other channel areas outside the target channel area are converted to the minimum channel value to obtain the alpha channel map after the initial conversion, and then normalization processing is performed to obtain the conversion channel map, thereby ensuring the accuracy and effectiveness of the obtained conversion channel map.
[0087] Specifically, the step of determining the target background image according to the conversion background image includes:
[0088] Step g, determining a pure foreground image area in the conversion background image according to the conversion channel image;
[0089] Step h: performing pixel value clearing processing on the pure foreground image area to obtain a target background image.
[0090] In this embodiment, when using the conversion relationship After completing the initial conversion of the background image and obtaining the converted background image, it is also necessary to avoid the interference of the pure foreground image area on the background image, such as the interference of the character foreground determination area. Therefore, it is necessary to determine the pure foreground area in the converted background image, that is, to determine the maximum channel value in the conversion channel image, that is, the area corresponding to the area with a channel value of 1 in the converted background image, and determine the pixel value of this area, and clear the pixel value, that is, adjust the pixel value of this area to 0. After the adjustment is completed, the converted background image after pixel value conversion is used as the target background image. For example, if the size of a picture is 1000*1000, in a small 100*100 area with the middle coordinates [400:500,400:500], its corresponding alpha value is 1, that is, it can be determined that the area is a pure foreground image, so the pixel value of this area in the background image can be set to 0.
[0091] In this embodiment, by determining the pure foreground image area in the conversion background image according to the conversion channel map and clearing the pixel values of the pure foreground image area, interference of the pure foreground image area with the target background image finally generated is avoided, thereby ensuring the accuracy and effectiveness of the acquired target background image.
[0092] Furthermore, the step of correcting the foreground image according to the target background image, the original image and the alpha channel image comprises:
[0093] Step i, determining all conversion channel values in the conversion channel map, and detecting whether the conversion channel value is a minimum channel value;
[0094] Step j: if the conversion channel value is not the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is corrected according to the target background image, the original image, the conversion channel image and the conversion relationship.
[0095] Specifically, after the step of detecting whether the conversion channel value is the minimum channel value, the method further includes:
[0096] Step k: if the converted channel value is the minimum channel value, the pixel value corresponding to the converted channel value in the foreground image is cleared.
[0097] In this embodiment, when correcting the foreground image, it is necessary to first determine all channel values in the conversion channel image and use them as conversion channel values, and then detect in sequence whether the conversion channel values are the minimum channel values. The minimum channel value may be 0. If the conversion channel value is the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is determined, and the pixel value is cleared, that is, the pixel value corresponding to the conversion channel value in the foreground image is adjusted to 0.
[0098] However, if the conversion channel value is not the minimum channel value, the pixel value corresponding to the conversion channel value in the target background image, the pixel value corresponding to the conversion channel value in the original image, and the conversion channel value are input together into the formula corresponding to the adjusted conversion relationship. Calculation is performed in order to obtain a modified foreground pixel value, and the foreground pixel value corresponding to the conversion channel value in the foreground image is converted into the modified foreground pixel value.
[0099] Specifically, the foreground image can be corrected according to the following formula:
[0100]
[0101] Where x and y are pixel coordinates. t is the target background image. txy is the pixel value at pixel coordinates x, y in the target background image. xy is the pixel value in the target foreground image. Converts the channel values of pixel coordinates x and y in the channel map.
[0102] In this embodiment, by determining that the conversion channel value in the conversion channel map is not the minimum channel value, a correction conversion is performed according to the target background map, the original map, the conversion channel map and the conversion relationship, and a zeroing process is performed when the conversion channel value is the minimum channel value to obtain the target foreground map, thereby ensuring the accuracy and effectiveness of the acquired target foreground map.
[0103] Furthermore, the step of correcting the alpha channel image according to the target background image, the original image and the target foreground image comprises:
[0104] Step 1, determining all conversion channel values in the conversion channel map corresponding to the alpha channel map, and detecting whether the conversion channel value is a minimum channel value;
[0105] Step m, if the conversion channel value is the minimum channel value, keeping the channel value corresponding to the conversion channel value in the alpha channel map unchanged;
[0106] Step n: if the conversion channel value is not the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel image is corrected according to the target background image, the original image, and the target foreground image.
[0107] In this embodiment, when the alpha channel image is corrected to obtain the target channel image, the background image and the foreground image need to be corrected first, and after obtaining the target background image and the target foreground image, the alpha channel image is corrected. The correction method of the alpha channel image can be performed according to the following formula.
[0108]
[0109] Where xy is the pixel coordinate, I xy is the pixel value of the pixel coordinate x, y in the original image. txy is the pixel value at pixel coordinates x, y in the target background image. txy is the pixel value of the pixel coordinate x, y in the target foreground image. The channel value of the pixel coordinate x, y in the conversion channel map. xy It is the channel value of the pixel coordinate x, y in the target channel image.
[0110] Specifically, when correcting the foreground image, it is necessary to first determine all channel values in the conversion channel map and use them as conversion channel values, and then detect whether the conversion channel value is the minimum channel value. The minimum channel value can be 0. If the conversion channel value is the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel map is determined to remain unchanged. If the conversion channel value is not the minimum channel value, then according to the formula A calculation is performed to obtain a calculation result, and then the channel value corresponding to the converted channel value in the alpha channel map is converted to be the same as the calculation result, thereby completing the correction of the alpha channel map.
[0111] In this embodiment, when it is determined that the conversion channel value in the conversion channel map is the minimum channel value, the channel value in the alpha channel map is kept unchanged; when the conversion channel value is not the minimum channel value, the channel value in the alpha channel map is corrected according to the target background map, the original map and the target foreground map to obtain the target channel map, thereby ensuring the accuracy and effectiveness of the obtained target channel map.
[0112] In addition, refer to Figure 3 , an embodiment of the present invention further provides an image processing device, comprising:
[0113] A determination module A10 is used to obtain an alpha channel image and a foreground image according to the marked original image, and determine a background image corresponding to the original image;
[0114] A correction module A20, used for correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image;
[0115] The correction module A20 is used to correct the foreground image according to the target background image, the original image and the alpha channel image to obtain a target foreground image;
[0116] The correction module A20 is used to correct the alpha channel image according to the target background image, the original image and the target foreground image to obtain a target channel image;
[0117] The generating module A30 is used to generate a target image according to the target background image, the target channel image and the target foreground image.
[0118] Optionally, the correction module A20 is used to:
[0119] Determining a conversion relationship between the original image, the alpha channel image, and the foreground image;
[0120] Determine all channel values of the alpha channel map, and convert the alpha channel map according to all channel values to obtain a converted channel map;
[0121] A modified conversion is performed according to the original image, the conversion channel image, the foreground image and the conversion relationship to obtain a conversion background image, and a target background image is determined according to the conversion background image.
[0122] Optionally, the correction module A20 is used to:
[0123] Determine the maximum channel value and the minimum channel value among all the channel values, and determine the target channel area where the maximum channel value in the alpha channel map is located;
[0124] Convert the single-digit channel values in other channel areas except the target channel area in the alpha channel image into minimum channel values to obtain an alpha channel image after initial conversion;
[0125] The alpha channel map after the initial conversion is normalized to obtain a conversion channel map.
[0126] Optionally, the correction module A20 is used to:
[0127] Determine the pure foreground image area in the conversion background image according to the conversion channel image;
[0128] The pixel values of the pure foreground image area are cleared to obtain a target background image.
[0129] Optionally, the correction module A20 is used to:
[0130] Determine all conversion channel values in the conversion channel map, and detect whether the conversion channel value is a minimum channel value;
[0131] If the conversion channel value is not the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is corrected according to the target background image, the original image, the conversion channel image and the conversion relationship.
[0132] Optionally, the correction module A20 is used to:
[0133] If the conversion channel value is the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is cleared.
[0134] Optionally, the correction module A20 is used to:
[0135] Determine all conversion channel values in the conversion channel map corresponding to the alpha channel map, and detect whether the conversion channel value is a minimum channel value;
[0136] If the conversion channel value is the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel image is kept unchanged;
[0137] If the conversion channel value is not the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel image is corrected according to the target background image, the original image, and the target foreground image.
[0138] The steps implemented by each functional module of the image processing device may refer to the various embodiments of the image processing method of the present invention, and will not be described in detail here.
[0139] In addition, the present invention also provides an image processing device, which includes: a memory, a processor, and an image processing program stored in the memory; the processor is used to execute the image processing program to implement the steps of each embodiment of the above-mentioned image processing method.
[0140] The present invention also provides a computer-readable storage medium, which stores one or more programs. The one or more programs can also be executed by one or more processors to implement the steps of each embodiment of the above-mentioned image processing method.
[0141] The specific implementation of the computer-readable storage medium of the present invention is basically the same as the above-mentioned embodiments of the image processing method, and will not be described in detail here.
[0142] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0143] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0144] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0145] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. An image processing method, characterized in that: The image processing method comprises the following steps: Obtaining an alpha channel image and a foreground image according to the marked original image, and determining a background image corresponding to the original image; The background image is corrected according to the original image, the alpha channel image and the foreground image to obtain a target background image; wherein the step of correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image comprises: determining a conversion relationship among the original image, the alpha channel image, the foreground image and the background image; determining all channel values of the alpha channel image, converting the alpha channel image according to all channel values to obtain a conversion channel image; performing correction conversion according to the original image, the conversion channel image, the foreground image and the conversion relationship to obtain a conversion background image, and determining a target background image according to the conversion background image; The foreground image is corrected according to the target background image, the original image and the alpha channel image to obtain a target foreground image; wherein the step of correcting the foreground image according to the target background image, the original image and the alpha channel image comprises: determining all conversion channel values in the conversion channel image, and detecting whether the conversion channel value is a minimum channel value; if the conversion channel value is not the minimum channel value, correcting the pixel value corresponding to the conversion channel value in the foreground image according to the target background image, the original image, the conversion channel image and the conversion relationship; The alpha channel image is corrected according to the target background image, the original image and the target foreground image to obtain a target channel image; wherein the step of correcting the alpha channel image according to the target background image, the original image and the target foreground image comprises: determining all conversion channel values in the conversion channel image corresponding to the alpha channel image, and detecting whether the conversion channel value is a minimum channel value; if the conversion channel value is not the minimum channel value, correcting the channel value corresponding to the conversion channel value in the alpha channel image according to the target background image, the original image and the target foreground image; A target image is generated according to the target background image, the target channel image and the target foreground image.
2. The image processing method according to claim 1, characterized in that: The step of converting the alpha channel map according to all the channel values to obtain a converted channel map comprises: Determine the maximum channel value and the minimum channel value among all the channel values, and determine the target channel area where the maximum channel value in the alpha channel map is located; Convert the single-digit channel values in other channel areas except the target channel area in the alpha channel image into minimum channel values to obtain an alpha channel image after initial conversion; The alpha channel map after the initial conversion is normalized to obtain a conversion channel map.
3. The image processing method according to claim 1, characterized in that: The step of determining the target background image according to the conversion background image comprises: Determine the pure foreground image area in the conversion background image according to the conversion channel image; The pixel values of the pure foreground image area are cleared to obtain a target background image.
4. The image processing method according to claim 1, wherein: After the step of determining all conversion channel values in the conversion channel map and detecting whether the conversion channel value is a minimum channel value, the method further comprises: If the conversion channel value is the minimum channel value, the pixel value corresponding to the conversion channel value in the foreground image is cleared.
5. The image processing method according to any one of claims 1 to 4, characterized in that: After the step of determining all conversion channel values in the conversion channel map corresponding to the alpha channel map and detecting whether the conversion channel value is the minimum channel value, the following steps are included: If the conversion channel value is the minimum channel value, the channel value corresponding to the conversion channel value in the alpha channel map is kept unchanged.
6. An image processing device, characterized in that: The image processing device comprises: A determination module, used to obtain an alpha channel image and a foreground image according to the marked original image, and determine a background image corresponding to the original image; A correction module, used for correcting the background image according to the original image, the alpha channel image and the foreground image to obtain a target background image; wherein, the correction of the background image according to the original image, the alpha channel image and the foreground image to obtain the target background image includes: determining a conversion relationship among the original image, the alpha channel image, the foreground image and the background image; determining all channel values of the alpha channel image, converting the alpha channel image according to all channel values to obtain a conversion channel image; performing correction conversion according to the original image, the conversion channel image, the foreground image and the conversion relationship to obtain a conversion background image, and determining the target background image according to the conversion background image; The correction module is used to correct the foreground image according to the target background image, the original image and the alpha channel image to obtain a target foreground image; wherein, the correction of the foreground image according to the target background image, the original image and the alpha channel image comprises: determining all conversion channel values in the conversion channel image, detecting whether the conversion channel value is a minimum channel value; if the conversion channel value is not the minimum channel value, correcting the pixel value corresponding to the conversion channel value in the foreground image according to the target background image, the original image, the conversion channel image and the conversion relationship; The correction module is used to correct the alpha channel image according to the target background image, the original image and the target foreground image to obtain a target channel image; wherein, the correction of the alpha channel image according to the target background image, the original image and the target foreground image comprises: determining all conversion channel values in the conversion channel image corresponding to the alpha channel image, and detecting whether the conversion channel value is a minimum channel value; if the conversion channel value is not the minimum channel value, correcting the channel value corresponding to the conversion channel value in the alpha channel image according to the target background image, the original image and the target foreground image; A generating module is used to generate a target image according to the target background image, the target channel image and the target foreground image.
7. An image processing device, characterized in that: The image processing device comprises: a memory, a processor, and an image processing program stored in the memory and executable on the processor, wherein the image processing program implements the steps of the image processing method according to any one of claims 1 to 5 when executed by the processor.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an image processing program, and when the image processing program is executed by a processor, the steps of the image processing method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Pure-color background image matting synthesis method based on real-time inhibition of background color overflow
CN110969595A
Image processing method and device, electronic equipment and storage medium
CN114399454A