Image processing method and device, electronic device and storage medium
By segmenting and filtering the image, adjusting the gradient value and then merging it, the problem of prominent boundary lines in the stylized image is solved and a better stylized effect is achieved.
Patent Information
- Application Number
- CN202110971063.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-23
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-08-23
AI Technical Summary
The boundary lines of stylized images in the existing technology are relatively prominent, making it difficult to meet user needs and lacking effective solutions.
By segmenting the original image, filtering the foreground and background images respectively, and adjusting the gradient values to ensure that the difference in boundary gradient values is less than the threshold, fusion is performed to generate the target image.
The stylized effect of the foreground and background is improved, the problem of prominent boundary lines is avoided, and the stylized effect of the generated image is more realistic.
Smart Images

Figure CN113781292B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computers, and in particular to an image processing method and device, an electronic device, and a storage medium. Background Art
[0002] Among the special effects in mobile terminals, image stylization is widely loved by users. For example, adding corresponding filters to images in applications such as photo editing and short videos can stylize the images.
[0003] In the prior art, image stylization is usually performed uniformly on the entire image. However, there are differences in the brightness values of different pixels in the entire image. For example, if a person is used as the foreground and the rest of the person is used as the background, the brightness of the foreground and the background are different. If the entire image is stylized uniformly, the boundary between the person and the background will be more prominent, and the image stylization effect is difficult to meet the needs of users.
[0004] Therefore, there is currently no effective solution to the problem of prominent boundary lines in stylized images in related technologies.
[0005] Public Content
[0006] The present disclosure provides an image processing method and device, an electronic device and a storage medium to at least solve the problem that the boundary lines in stylized images in the related art are relatively prominent. The technical solution of the present disclosure is as follows:
[0007] According to a first aspect of an embodiment of the present disclosure, there is provided an image processing method, comprising: performing a segmentation operation on an original image to be processed to obtain a foreground image and a background image in the original image; performing a first filter processing on the foreground image to obtain a first filter image, and performing a second filter processing on the background image to obtain a second filter image, wherein the first filter image and the second filter image have the same filter style type; performing a fusion operation on the first filter image and the second filter image to obtain a target image.
[0008] Optionally, performing a fusion operation on the first filter image and the second filter image to obtain a target image includes: adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; performing a fusion operation on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
[0009] Optionally, performing a first filter processing on the foreground image to obtain a first filtered image includes: searching a preset relationship table for converted pixel values corresponding to pixel values of pixel points in the foreground image, wherein the preset relationship table records a plurality of groups of corresponding pre-conversion pixel values and post-conversion pixel values, and the converted pixel values in the preset relationship table are pixel values under the filter style type; replacing the pixel values of each pixel point in the foreground image with the corresponding converted pixel values to obtain the first filtered image.
[0010] Optionally, searching for the converted pixel value corresponding to the pixel value of the pixel point in the foreground image in the preset relationship table includes: determining at least two local areas in the foreground image; determining the pre-conversion pixel value of each local area of the at least two local areas; searching for the converted pixel value corresponding to the pre-conversion pixel value of each local area in the preset relationship table; replacing the pixel value of each pixel point in the foreground image with the corresponding converted pixel value to obtain the first filtered image includes: replacing the pixel value of each pixel point in each local area of the at least two local areas with the corresponding converted pixel value to obtain the first filtered image.
[0011] Optionally, determining the pre-conversion pixel value of each local area of the at least two local areas includes: determining the mean of the pixel values of each pixel point in each local area as the pre-conversion pixel value of each local area; or determining the pixel value of a randomly selected pixel point in each local area as the pre-conversion pixel value of each local area; or determining the mean of the pixel values of multiple randomly selected pixel points in each local area as the pre-conversion pixel value of each local area.
[0012] Optionally, performing a second filter processing on the background image to obtain a second filtered image includes: inputting the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; when the brightness of the adjusted image is within a preset brightness range, determining the adjusted image as the second filtered image; when the brightness of the adjusted image is not within the preset brightness range, performing a brightness correction operation on the adjusted image to obtain the second filtered image.
[0013] Optionally, performing a brightness correction operation on the adjusted image to obtain the second filtered image includes: increasing the brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold; reducing the brightness value of a second pixel in the adjusted image by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold.
[0014] Optionally, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, includes: when a difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes the third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes the fourth filter image.
[0015] Optionally, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image, includes: determining the mean of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; adjusting the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to the average gradient value.
[0016] According to a second aspect of an embodiment of the present disclosure, an image processing device is provided, comprising: an execution unit, configured to perform a segmentation operation on an original image to be processed to obtain a foreground image and a background image in the original image; a processing unit, configured to perform a first filter processing on the foreground image to obtain a first filter image, and perform a second filter processing on the background image to obtain a second filter image, wherein the first filter image and the second filter image have the same filter style type; and a fusion unit, configured to perform a fusion operation on the first filter image and the second filter image to obtain a target image.
[0017] Optionally, the above-mentioned device is also configured to adjust the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjust the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; perform a fusion operation on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
[0018] Optionally, the above-mentioned device is also configured to perform a search in a preset relationship table for a converted pixel value corresponding to the pixel value of a pixel point in the foreground image, wherein the preset relationship table records multiple groups of corresponding pre-conversion pixel values and post-conversion pixel values, and the converted pixel value in the preset relationship table is the pixel value under the filter style type; the pixel value of each pixel point in the foreground image is replaced by the corresponding converted pixel value to obtain the first filtered image.
[0019] Optionally, the above-mentioned device is also configured to determine at least two local areas in the foreground image; determine the pre-conversion pixel value of each of the at least two local areas; search for the post-conversion pixel value corresponding to the pre-conversion pixel value of each local area in the preset relationship table; replace the pixel value of each pixel point in each of the at least two local areas with the corresponding post-conversion pixel value to obtain the first filtered image.
[0020] Optionally, the above-mentioned device is also configured to execute the steps of determining the mean of the pixel values of each pixel point in each local area as the pixel value before conversion of each local area; determining the pixel value of a randomly selected pixel point in each local area as the pixel value before conversion of each local area; and determining the mean of the pixel values of multiple randomly selected pixel points in each local area as the pixel value before conversion of each local area.
[0021] Optionally, the above-mentioned device is also configured to input the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; when the brightness of the adjusted image is within a preset brightness range, the adjusted image is determined as the second filter image; when the brightness of the adjusted image is not within the preset brightness range, a brightness correction operation is performed on the adjusted image to obtain the second filter image.
[0022] Optionally, the above-mentioned device is also configured to increase the brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold value; and reduce the brightness value of a second pixel in the adjusted image by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold value.
[0023] Optionally, the above-mentioned device is also configured to execute, when the difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes the third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes the fourth filter image.
[0024] Optionally, the above-mentioned device is also configured to determine the average of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; and adjust the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to the average gradient value.
[0025] According to a third aspect of an embodiment of the present disclosure, there is provided an image processing electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the image processing method as described above.
[0026] According to another aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned image processing method when running.
[0027] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: by segmenting the foreground and background of an image and stylizing the foreground and background separately, the stylization effect of the foreground and background can be improved; by adjusting the gradient value of the boundary line between the foreground and background, the protruding problem of the boundary line between the foreground and background can be avoided.
[0028] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0030] Figure 1 is a flowchart of an image processing method according to an exemplary embodiment;
[0031] Figure 2 is a schematic diagram of image segmentation according to an exemplary embodiment;
[0032] Figure 3 is a schematic diagram of a CCNet model structure according to an exemplary embodiment;
[0033] Figure 4 is a schematic diagram of an overall process according to an exemplary embodiment;
[0034] Figure 5 is a schematic diagram of a Mask R-CNN framework according to an exemplary embodiment;
[0035] Figure 6 is a block diagram of an image processing device according to an exemplary embodiment;
[0036] Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0037] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0038] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0039] As an optional implementation, Figure 1 is a flowchart of an image processing method according to an exemplary embodiment. Figure 1 As shown, the image processing method includes the following steps.
[0040] In step S11, a segmentation operation is performed on the original image to be processed to obtain a foreground image and a background image in the original image;
[0041] The original image to be processed may be an image captured by a camera of a mobile terminal, or an image captured in an application, such as a video image captured in a short video application. The original image includes a foreground image and a background image, and the first boundary in the foreground image is connected to the second boundary in the background image. For example, when photographing a person, the person can be used as the foreground image, and the image excluding the person part is used as the background image. Figure 2 According to an image segmentation schematic diagram shown in an exemplary embodiment, an image segmentation algorithm can be used to segment the original image to obtain a foreground image and a background image. In the original image, the first boundary of the foreground image and the second boundary of the background image are connected together. In this embodiment, by performing a segmentation operation on the original image, the foreground image and the background image of the original image can be obtained, so that the foreground image and the background image can be stylized respectively, so as to achieve a better stylized image effect and better meet the needs of users.
[0042] In step S12, a first filter process is performed on the foreground image to obtain a first filtered image, and a second filter process is performed on the background image to obtain a second filtered image, wherein the first filtered image and the second filtered image have the same filter style type;
[0043] Among them, filters are added to the foreground image and the background image respectively, and the filter processing methods of the foreground image and the background image can be the same or different, such as using the LUT table lookup method to stylize both the foreground image and the background image, or using the LUT table lookup method to stylize the foreground image and the histogram network method to stylize the background image. The filter styles added to the foreground image and the background image are the same, such as comic-style filters. In this embodiment, the same filter style filter is added to the foreground image and the background image. Since the filter processing is performed on the foreground image and the background image of the original image respectively, the added filter can better fit the foreground image and the background image, and the stylized image is more in line with reality and meets user needs.
[0044] In step S13, a fusion operation is performed on the first filtered image and the second filtered image to obtain a target image.
[0045] The fusion operation may be to fuse the stylized foreground image and background image, that is, to fuse the third filter image and the fourth filter image. Specifically, the first boundary in the third filter image and the second boundary in the fourth filter image may be spliced to obtain the target image after the original image is stylized as a whole. Since the foreground image and the background image of the original image are stylized separately, the filter effect is more in line with the foreground image and the background image, and the stylized effect is better, so that the stylized target image obtained after splicing is more in line with reality and meets user needs.
[0046] Optionally, the gradient value corresponding to the first boundary in the first gradient field of the first filter image is adjusted so that the first filter image becomes a third filter image, and the gradient value corresponding to the second boundary in the second gradient field of the second filter image is adjusted so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; a fusion operation is performed on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
[0047] As an optional implementation, in order to prevent the problem of prominent boundaries between the foreground image and the background image, the gradient value of the boundary between the stylized first filter image and the second filter image can be adjusted. Specifically, the gradient value corresponding to the first boundary in the first filter image and the gradient value corresponding to the second boundary in the second filter image can be calculated. If the difference between the two gradient values is less than a predetermined threshold, no adjustment is required. If the difference is greater than the predetermined threshold, it is necessary to adjust the gradient value corresponding to the first boundary in the first filter image to obtain a third filter image. And adjust the gradient value corresponding to the second boundary in the second filter image to obtain a fourth filter image. The size of the predetermined threshold can be determined according to actual conditions. In this embodiment, by adjusting the boundary values of the stylized foreground image and the background image, the boundary line at the splicing point in the spliced style image can be made to fit the foreground image and the background image more closely, avoiding the problem of prominent boundary lines of the stylized image, and making the stylized image effect better.
[0048] Optionally, performing a first filter processing on the foreground image to obtain a first filtered image includes: searching a preset relationship table for converted pixel values corresponding to pixel values of pixel points in the foreground image, wherein the preset relationship table records a plurality of groups of corresponding pre-conversion pixel values and post-conversion pixel values, and the converted pixel values in the preset relationship table are pixel values under the filter style type; replacing the pixel values of each pixel point in the foreground image with the corresponding converted pixel values to obtain the first filtered image.
[0049] As an optional implementation, a table lookup method can be used to stylize the foreground image. The preset relationship table can be a preset LUT table, which records the correspondence between the pixel value before stylization and the pixel value after stylization under a certain style filter. According to the pixel value of the pixel point in the foreground image, the corresponding stylized pixel value is searched in the LUT table, and the pixel value in the foreground image is replaced with the corresponding stylized pixel value to obtain the first filter image after the foreground image is stylized. In this embodiment, by stylizing the foreground image separately and searching the preset relationship table for the corresponding stylized pixel value of the foreground image, the stylization effect of the foreground image can be improved, and the efficiency of image stylization can be improved.
[0050] Optionally, searching for the converted pixel value corresponding to the pixel value of the pixel point in the foreground image in the preset relationship table includes: determining at least two local areas in the foreground image; determining the pre-conversion pixel value of each local area of the at least two local areas; searching for the converted pixel value corresponding to the pre-conversion pixel value of each local area in the preset relationship table; replacing the pixel value of each pixel point in the foreground image with the corresponding converted pixel value to obtain the first filtered image includes: replacing the pixel value of each pixel point in each local area of the at least two local areas with the corresponding converted pixel value to obtain the first filtered image.
[0051] As an optional implementation, the foreground image can be segmented to obtain multiple local regions. Taking the foreground image as a person image as an example, the person's body can be segmented. Specifically, a neural network model can be used to segment the human body, and the neural network model can be CCNet. A large amount of training data can be used to train the neural network model, and the training data can include various parts of the human body. The trained neural network model can be used to segment the human body into different parts, such as arms, hair, face, legs, etc. Each part of the human body corresponds to each local region. Figure 3 It is a schematic diagram of the CCNet model structure shown according to an exemplary embodiment. The foreground image is input into the neural network model. After the neural network model extracts features and processes data of the foreground image, a segmented image is obtained, and the segmented image includes at least two local areas. According to the image pixel value of each local area, the corresponding stylized pixel value can be found in the LUT table, so that each local area can be stylized, and the pixel values of all local areas are replaced with stylized pixel values, and a first filter image for stylizing the foreground image can be obtained. In this embodiment, by dividing the foreground image into different local areas and stylizing the different local areas respectively, each part of the stylized image is more in line with the original image, more in line with reality, and better in effect.
[0052] Optionally, determining the pre-conversion pixel value of each local area of the at least two local areas includes: determining the mean of the pixel values of each pixel point in each local area as the pre-conversion pixel value of each local area; or determining the pixel value of a randomly selected pixel point in each local area as the pre-conversion pixel value of each local area; or determining the mean of the pixel values of multiple randomly selected pixel points in each local area as the pre-conversion pixel value of each local area.
[0053] As an optional implementation, the pixels in each local area can be stylized as a whole, the average pixel value of each pixel point in each local area is taken, the stylized pixel value corresponding to the average pixel value is searched in the LUT table, and the overall pixel points of each local image are replaced with the stylized pixel value found in the LUT table to obtain a stylized image of the local area. Taking the face of a human body as an example, the average pixel value of each pixel in the face area can be taken, the stylized pixel value corresponding to the average value can be searched in the LUT table, and the stylized pixel value of each pixel in the face area can be replaced with the stylized pixel value to obtain a stylized image of the face area. In this embodiment, by taking the average pixel value of the local area and searching the LUT table for the stylized pixel value corresponding to the average value, the local areas in the image can be uniformly stylized, thereby improving the efficiency of image stylization.
[0054] As an optional implementation, the pixel value of a pixel point can be randomly selected in each local area, and the stylized pixel value corresponding to the pixel value of the random pixel point can be searched in the LUT table, and the overall pixel points of each local image can be replaced with the stylized pixel value to obtain a stylized image of the local area. Taking the local area as a human arm as an example, a pixel point can be randomly selected in the arm area of the foreground image, and the stylized pixel value corresponding to the pixel value of the pixel point can be searched in the LUT table. The pixel values of the arm area can be replaced with the stylized pixel value to obtain a stylized image of the arm area. In this embodiment, by randomly selecting pixel values in the local area and searching the LUT table for the stylized pixel value corresponding to the mean value, the local areas in the image can be uniformly stylized, thereby improving the efficiency of image stylization.
[0055] As an optional implementation, several pixels may be randomly selected in each local area, the pixel values of the selected pixels may be averaged, the stylized pixel value corresponding to the average may be searched in the LUT table, and the overall pixel points of the local image may be replaced with the stylized pixel value to obtain a stylized image of the local area. Taking the local area as the leg of a human body as an example, several pixels may be randomly selected in the leg area of the foreground image, the stylized pixel value corresponding to the average pixel value may be searched in the LUT table, and the pixel values of the leg area may be replaced with the stylized pixel value to obtain a stylized image of the leg area. In this embodiment, each local area in the foreground image may be stylized as a whole, which may improve the stylization efficiency of the foreground image.
[0056] Optionally, performing a second filter processing on the background image to obtain a second filtered image includes: inputting the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; when the brightness of the adjusted image is within a preset brightness range, determining the adjusted image as the second filtered image; when the brightness of the adjusted image is not within the preset brightness range, performing a brightness correction operation on the adjusted image to obtain the second filtered image.
[0057] As an optional implementation, the neural network model can be a network model obtained through machine learning training, and the histogram network can adjust the histogram distribution of the original background image. The background image of the original image is input into the histogram network, and the background image after the adjustment of the histogram network output can be obtained. It can be judged whether the preset condition is met according to the brightness of the adjusted background image output by the histogram network, and the preset condition can be whether the brightness meets the preset condition. In the case where the brightness of the adjusted image output by the histogram network meets the preset condition, the image output by the histogram network is the second filter image that stylizes the background image. In the case where the brightness of the adjusted image output by the histogram network does not meet the preset condition, the brightness of the adjusted image can be adjusted, and the darker pixels can be brightened, and the brighter pixels can be dimmed. In this embodiment, the background image of the original image can be stylized by the histogram network, and in addition, the image output based on the histogram network is adjusted to improve the effect of the stylization of the background image.
[0058] Optionally, performing a brightness correction operation on the adjusted image to obtain the second filtered image includes: increasing the brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold; reducing the brightness value of a second pixel in the adjusted image by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold.
[0059] As an optional implementation, the first threshold and the second threshold can be determined according to actual conditions. The first pixel can be a pixel with lower brightness in the adjusted image output by the network histogram, and the second pixel can be a pixel with higher brightness in the adjusted image output by the network histogram. In this embodiment, the pixels with lower brightness in the adjusted image output by the histogram network can be brightened, and the brightness of the pixels with higher brightness can be reduced. In this embodiment, the histogram of the adjusted image can be divided into five levels (bright, highlight, normal, dark, black), with a bright range of 200-255, a highlight range of 150-199, a normal range of 100-149, a dark range of 50-99, and a black range of 0-49. Pre-capture a picture of a certain filter style, and then fit the histogram curves of the dark and bright parts. Then use it as a criterion for judging the histogram directly output by the evaluation network. Brighten the pixel part with lower brightness, and reduce the brightness of the bright part (overexposed).
[0060] For calculating pixel values in the black range (0-49) in the histogram, the following formula can be used for adjustment:
[0061]
[0062] For the calculation of pixel values in the bright range (200-255) in the histogram, the following formula can be used for adjustment:
[0063]
[0064] Wherein, input is the pixels in the black range (0-49) in the adjusted image, and output is the adjusted pixels. In this embodiment, by adjusting the brightness of the stylized image output by the network histogram, it is possible to prevent the stylized image from being too dark or overexposed, thereby improving the quality of the stylized image.
[0065] Optionally, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, includes: when a difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes the third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes the fourth filter image.
[0066] As an optional implementation, the first filter image and the second filter image obtained by stylizing the foreground image and the background image can be Poisson fused. Since there may be a large difference between the pixels of the boundary of the stylized first filter image and the boundary of the second filter image, if they are directly spliced, the problem of prominent boundaries may occur. The gradient values of the first filter image and the second filter image can be calculated respectively, and the gradient values of the first boundary and the second boundary can be adjusted respectively according to the first boundary gradient value corresponding to the first filter image and the second boundary gradient value corresponding to the second filter image to avoid the problem of prominent boundaries. Specifically, if the difference between the gradient value of the first boundary corresponding to the first filter image and the gradient value of the second boundary of the second filter image is large, the gradient value of the first boundary and the gradient value of the second boundary can be adjusted to reduce the difference between the first boundary gradient value and the second boundary gradient value, so as to obtain the third filter image and the fourth filter image, and the third filter image and the fourth filter image are spliced to obtain the stylized image. In this embodiment, by adjusting the boundary gradient value of the first filter image and the second filter image, the problem of prominent boundaries can be avoided and the stylization effect can be improved.
[0067] Optionally, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image, includes: determining the mean of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; adjusting the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to the average gradient value.
[0068] As an optional implementation, for the gradient value of the first boundary in the stylized first filter image and the gradient value of the second boundary in the stylized second filter image, the average gradient value can be taken. The gradient value of the first boundary of the first filter image and the gradient value of the second boundary of the second filter image are adjusted to the average gradient value. According to the average gradient value, the pixel values of the first boundary and the second boundary can be obtained, thereby obtaining a stylized foreground image, a third filter image, and a stylized background image, a fourth filter image. The third filter image and the fourth filter image are fused to obtain the stylized image of the original image. In this embodiment, by taking the average of the gradient values of the boundaries of the stylized foreground image and the background image, the problem of prominent boundaries in the stylized image can be avoided and the effect of the stylized image can be improved.
[0069] The present application is described below by a specific embodiment. Figure 4 The figure is a schematic diagram of an overall process according to an exemplary embodiment, which includes the following steps:
[0070] Step S41, separate the foreground and background of the original image to separate the foreground image and the background image. Specifically, a neural network model can be used to separate the foreground and background of the original image, and the foreground and background separation can be performed based on Mask R-CNN. Figure 5 The figure is a schematic diagram of the Mask R-CNN framework according to an exemplary embodiment, wherein FPN is a feature pyramid network, RPN is a region proposal network, and Rol is a region of interest. The original image is output to the Mask R-CNN network model, and the Mask R-CNN network model segments the original image to obtain a foreground image and a background image.
[0071] Step S42, foreground stylization. The foreground image can be segmented first, and the foreground image can be divided into different regions. Different regions are stylized separately. Regional segmentation can be performed based on CCNet. Taking human body segmentation as an example, the foreground image human body can be input into CCNet, and the information of each part of the human body (arms, hair, face, upper body, legs) can be distinguished through CCNet. According to the pixel values of different regions, the corresponding stylized pixel values are found in the LUT lookup table, and the pixel values of the foreground image are replaced with the stylized pixel values to obtain a stylized foreground image.
[0072] Step S43, background stylization. The segmented background image is passed through a pre-trained histogram network, and the histogram distribution of the original background image is adjusted to obtain the adjusted background image output by the histogram network. The histogram network is obtained by repeated training with photos of different scenes as training data. The picture corrected by the histogram network is then subjected to histogram inspection or correction. The histogram of the adjusted background image can be divided into five levels (bright, highlight, normal, dark, black), with a bright range of 200-255, a highlight range of 150-199, a normal range of 100-149, a dark range of 50-99, and a black range of 0-49. Pre-capture the picture in the style of Makoto Shinkai, and then fit the histogram curves of the dark and bright parts. Then use it as the judgment criterion for the histogram directly output by the evaluation network. The adjusted part is mainly to brighten the black part and reduce the brightness of the bright part (overexposed).
[0073] Step S54, stylized foreground and background fusion. Calculate the gradient value of the stylized foreground image and the gradient value of the stylized background image. Compare the gradient values of the boundaries of the stylized foreground image and the background image. If the gradient difference between the boundary of the stylized foreground image and the boundary of the background image is large, the gradient mean can be calculated. Replace the boundary gradient values of the stylized foreground image and the background image with the gradient mean, and the pixel value corresponding to the gradient mean can be obtained by the Poisson equation. Thus, the pixel values of the boundaries of the stylized foreground image and the background image are obtained. The stylized foreground image and the background image are spliced to obtain a stylized image of the original image.
[0074] Figure 6 FIG. 1 is a block diagram of an image processing device according to an exemplary embodiment. Figure 6 The device includes an execution unit 61, a processing unit 62, and a fusion unit 63.
[0075] The execution unit 61 is configured to perform a segmentation operation on the original image to be processed to obtain a foreground image and a background image in the original image;
[0076] The processing unit 62 is configured to perform a first filter process on the foreground image to obtain a first filter image, and perform a second filter process on the background image to obtain a second filter image, wherein the first filter image and the second filter image have the same filter style type;
[0077] The fusion unit 63 is configured to perform a fusion operation on the first filtered image and the second filtered image to obtain a target image.
[0078] Optionally, the above-mentioned device is also configured to adjust the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjust the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; perform a fusion operation on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
[0079] Optionally, the above-mentioned device is also configured to perform a search in a preset relationship table for a converted pixel value corresponding to the pixel value of a pixel point in the foreground image, wherein the preset relationship table records multiple groups of corresponding pre-conversion pixel values and post-conversion pixel values, and the converted pixel value in the preset relationship table is the pixel value under the filter style type; the pixel value of each pixel point in the foreground image is replaced by the corresponding converted pixel value to obtain the first filtered image.
[0080] Optionally, the above-mentioned device is also configured to determine at least two local areas in the foreground image; determine the pre-conversion pixel value of each of the at least two local areas; search for the post-conversion pixel value corresponding to the pre-conversion pixel value of each local area in the preset relationship table; replace the pixel value of each pixel point in each of the at least two local areas with the corresponding post-conversion pixel value to obtain the first filtered image.
[0081] Optionally, the above-mentioned device is also configured to execute the steps of determining the mean of the pixel values of each pixel point in each local area as the pixel value before conversion of each local area; determining the pixel value of a randomly selected pixel point in each local area as the pixel value before conversion of each local area; and determining the mean of the pixel values of multiple randomly selected pixel points in each local area as the pixel value before conversion of each local area.
[0082] Optionally, the above-mentioned device is also configured to input the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; when the brightness of the adjusted image is within a preset brightness range, the adjusted image is determined as the second filter image; when the brightness of the adjusted image is not within the preset brightness range, a brightness correction operation is performed on the adjusted image to obtain the second filter image.
[0083] Optionally, the above-mentioned device is also configured to increase the brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold value; and reduce the brightness value of a second pixel in the adjusted image by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold value.
[0084] Optionally, the above-mentioned device is also configured to execute, when the difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes the third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes the fourth filter image.
[0085] Optionally, the above-mentioned device is also configured to determine the average of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; and adjust the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to the average gradient value.
[0086] Figure 7 FIG. 1 is a block diagram of an electronic device for image processing according to an exemplary embodiment. Figure 7 As shown, the electronic device includes a processor 720 and a memory 710 for storing executable instructions of the processor. The processor is configured to execute instructions to implement the image processing method. The electronic device in this embodiment may also include a transmission device 730, a display 740 and a connection bus 750. The transmission device 730 is used to receive or send data via a network. Specific examples of the above network may include a wired network and a wireless network. In one example, the transmission device 730 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 730 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly. The display 740 is used to display the original image and the target image; the connection bus 750 is used to connect the various module components in the above electronic device.
[0087] In an exemplary embodiment, a storage medium including instructions is also provided, such as a memory 710 including instructions, and the instructions can be executed by a processor 720 of an electronic device to complete the above method. Optionally, the storage medium can be a non-transitory computer-readable storage medium, for example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0088] In an exemplary embodiment, a computer program product is also provided, including a computer program / instruction, and the computer program / instruction implements the above-mentioned information transmission method when executed by a processor.
[0089] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0090] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image processing method, characterized in that: include: Perform a segmentation operation on the original image to be processed to obtain a foreground image and a background image in the original image; Performing a first filter process on the foreground image to obtain a first filtered image, and performing a second filter process on the background image to obtain a second filtered image, wherein the first filtered image and the second filtered image have the same filter style type; Performing a fusion operation on the first filter image and the second filter image to obtain a target image, including: adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; performing a fusion operation on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
2. The method according to claim 1, characterized in that: The performing a first filter process on the foreground image to obtain a first filtered image includes: Searching for a converted pixel value corresponding to a pixel value of a pixel point in the foreground image in a preset relationship table, wherein the preset relationship table records a plurality of sets of corresponding pre-conversion pixel values and post-conversion pixel values, and the post-conversion pixel value in the preset relationship table is a pixel value under the filter style type; The pixel value of each pixel point in the foreground image is replaced with the corresponding converted pixel value to obtain the first filtered image.
3. The method according to claim 2, characterized in that The searching in the preset relationship table for the converted pixel value corresponding to the pixel value of the pixel point in the foreground image comprises: determining at least two local areas in the foreground image; determining the pre-conversion pixel value of each local area in the at least two local areas; searching in the preset relationship table for the converted pixel value corresponding to the pre-conversion pixel value of each local area; Replacing the pixel value of each pixel point in the foreground image with the corresponding converted pixel value to obtain the first filtered image includes: replacing the pixel value of each pixel point in each local area of the at least two local areas with the corresponding converted pixel value to obtain the first filtered image.
4. The method according to claim 1, characterized in that The performing a second filter process on the background image to obtain a second filtered image includes: Inputting the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; When the brightness of the adjusted image is within a preset brightness range, determining the adjusted image as the second filter image; When the brightness of the adjusted image is not within the preset brightness range, a brightness correction operation is performed on the adjusted image to obtain the second filtered image.
5. The method according to claim 4, characterized in that The performing a brightness correction operation on the adjusted image to obtain the second filtered image includes: Increasing a brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold; The brightness value of a second pixel in the adjusted image is reduced by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold.
6. The method according to claim 1, characterized in that The step of adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image includes: When the difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, the gradient value corresponding to the first boundary in the first gradient field of the first filter image is adjusted so that the first filter image becomes the third filter image, and the gradient value corresponding to the second boundary in the second gradient field of the second filter image is adjusted so that the second filter image becomes the fourth filter image.
7. The method according to claim 6, characterized in that Adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filtered image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filtered image, comprises: Determine the average of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; The gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary are adjusted to the average gradient value.
8. An image processing device, characterized in that: include: An execution unit is configured to perform a segmentation operation on the original image to be processed to obtain a foreground image and a background image in the original image; a processing unit configured to perform a first filter processing on the foreground image to obtain a first filtered image, and perform a second filter processing on the background image to obtain a second filtered image, wherein the first filtered image and the second filtered image have the same filter style type; A fusion unit is configured to perform a fusion operation on the first filter image and the second filter image to obtain a target image, including: adjusting the gradient value corresponding to the first boundary in the first gradient field of the first filter image so that the first filter image becomes a third filter image, and adjusting the gradient value corresponding to the second boundary in the second gradient field of the second filter image so that the second filter image becomes a fourth filter image, wherein the first boundary in the foreground image is connected to the second boundary in the background image, and the difference between the gradient value corresponding to the first boundary in the gradient field of the third filter image and the gradient value corresponding to the second boundary in the gradient field of the fourth filter image is less than a predetermined threshold; performing a fusion operation on the third filter image and the fourth filter image to obtain the target image, wherein the first boundary in the third filter image is connected to the second boundary in the fourth filter image.
9. The device according to claim 8, characterized in that The fusion unit is further configured to perform: Searching for a converted pixel value corresponding to a pixel value of a pixel point in the foreground image in a preset relationship table, wherein the preset relationship table records a plurality of sets of corresponding pre-conversion pixel values and post-conversion pixel values, and the post-conversion pixel value in the preset relationship table is a pixel value under the filter style type; The pixel value of each pixel point in the foreground image is replaced with the corresponding converted pixel value to obtain the first filtered image.
10. The device according to claim 9, characterized in that The apparatus is also configured to perform: Determining at least two local areas in the foreground image; Determine a pre-conversion pixel value of each of the at least two local areas; search the preset relationship table for a post-conversion pixel value corresponding to the pre-conversion pixel value of each local area; The pixel value of each pixel point in each of the at least two local areas is replaced with the corresponding converted pixel value to obtain the first filtered image.
11. The device according to claim 10, characterized in that The apparatus is also configured to perform: Determine the average of the pixel values of each pixel point in each local area as the pixel value before conversion of each local area; or, Determine the pixel value of a randomly selected pixel point in each local area as the pixel value before conversion of each local area; or, The average value of the pixel values of a plurality of randomly selected pixel points in each local area is determined as the pixel value before conversion of each local area.
12. The device according to claim 8, characterized in that The apparatus is also configured to perform: Inputting the background image into a trained neural network model to obtain an adjusted image, wherein the neural network model is used to adjust the histogram distribution of the background image; When the brightness of the adjusted image is within a preset brightness range, determining the adjusted image as the second filter image; When the brightness of the adjusted image is not within the preset brightness range, a brightness correction operation is performed on the adjusted image to obtain the second filtered image.
13. The device according to claim 12, characterized in that The apparatus is also configured to perform: Increasing a brightness value of a first pixel in the adjusted image by a first adjustment value, wherein the first pixel is a pixel in the adjusted image whose brightness value is less than or equal to a first threshold; The brightness value of a second pixel in the adjusted image is reduced by a second adjustment value, wherein the second pixel is a pixel in the adjusted image whose brightness value is greater than or equal to a second threshold.
14. The device according to claim 8, characterized in that The apparatus is also configured to perform: When the difference between the gradient value corresponding to the first boundary in the first gradient field and the gradient value corresponding to the second boundary in the second gradient field is greater than or equal to the predetermined threshold, the gradient value corresponding to the first boundary in the first gradient field of the first filter image is adjusted so that the first filter image becomes the third filter image, and the gradient value corresponding to the second boundary in the second gradient field of the second filter image is adjusted so that the second filter image becomes the fourth filter image.
15. The device according to claim 14, characterized in that The apparatus is also configured to perform: Determine the average of the gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary to obtain an average gradient value; The gradient value corresponding to the first boundary and the gradient value corresponding to the second boundary are adjusted to the average gradient value.
16. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the image processing method according to any one of claims 1 to 7. 17 . A computer-readable storage medium, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the image processing electronic device is enabled to execute the image processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method and device for implementing interactive image segmentation, and terminal
CN106886999A
Human face and body fusion processing method and system
CN107680071A
Stylized image generation method, device and equipment and storage medium
CN108961349A
Illumination non-uniform image threshold segmentation method based on brightness balance
CN110443807A
Interactive data extension method based on Poisson image fusion and image stylization
CN111199531A
