Image processing method and device and electronic equipment
By segmenting and adjusting the lighting and shadows of portrait images, the shortcomings of existing technologies in comprehensively addressing various problems of portrait images are overcome, thereby improving the lighting and shadow display effects and quality of the images.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- VIVO MOBILE COMM CO LTD
- Filing Date
- 2026-01-20
- Publication Date
- 2026-05-05
AI Technical Summary
Existing technologies cannot comprehensively and systematically solve various problems in portrait images, such as noise interference, color deviation, uneven lighting, and lack of detail, resulting in poor quality of processed portrait images.
By segmenting the portrait image into regions, adjusting the brightness based on the feature information of each region, and adjusting the light and shadow based on the light and shadow mapping information, a new light and shadow effect is generated.
It improves the lighting and shadow display effects and image quality of portrait images, enhancing the sense of three-dimensionality and artistry.
Smart Images

Figure CN121981933A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image processing technology, specifically relating to an image processing method, apparatus, and electronic device. Background Technology
[0002] In today's digital age, image applications are becoming increasingly widespread, and users have higher and higher requirements for the quality of portrait images. However, in actual shooting processes, due to the influence of various factors such as ambient light, camera equipment, and shooting techniques, portrait images often suffer from various problems, such as noise interference, color deviation, uneven lighting, and loss of detail. These problems seriously affect the visual effect of the image. Therefore, users can adjust the problems in the image one by one according to their needs through image processing applications.
[0003] However, the methods described above usually cannot comprehensively and systematically solve the various problems existing in portrait images, which will result in the processed portrait images having an unsatisfactory display effect and poor image quality. Summary of the Invention
[0004] The purpose of this application is to provide an image processing method, apparatus, electronic device, storage medium, and program product that can improve the light and shadow display effect and image quality of the processed portrait image.
[0005] In a first aspect, embodiments of this application provide an image processing method, which includes: performing region segmentation processing on a first portrait image to obtain N image regions, where N is a positive integer; performing a corresponding first brightness adjustment processing on each image region based on the feature information of each image region to obtain a second portrait image; and performing light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain a third portrait image, wherein the light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
[0006] Secondly, embodiments of this application provide an image processing apparatus, which includes: a processing module; the processing module is configured to perform region segmentation processing on a first portrait image to obtain N image regions, where N is a positive integer; the processing module is further configured to perform corresponding first brightness adjustment processing on each image region according to the feature information of each image region to obtain a second portrait image; the processing module is further configured to perform light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain a third portrait image, wherein the light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
[0007] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0010] In a sixth aspect, embodiments of this application provide a computer program / program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.
[0011] In this embodiment, the electronic device first divides the first portrait image into N image regions. Then, based on the feature information of each of the N image regions, the electronic device performs a corresponding first brightness adjustment on each image region. This means that each image region can undergo a different degree of first brightness adjustment, allowing for more accurate processing and improved image quality. Next, the electronic device performs lighting and shadow adjustment on the second portrait image based on at least one of the lighting and shadow mapping information of the original portrait image (i.e., the lighting and shadow distribution information and lighting and shadow change information of the first portrait image). This results in a third portrait image with new lighting and shadow effects, enhancing its three-dimensionality and artistic appeal. Thus, the lighting and shadow display effect and image quality of the processed portrait image are improved. Attached Figure Description
[0012] Figure 1 This is one of the flowcharts of an image processing method provided in the embodiments of this application;
[0013] Figure 2 This is a second flowchart of an image processing method provided in an embodiment of this application;
[0014] Figure 3 This is the third flowchart of an image processing method provided in the embodiments of this application;
[0015] Figure 4 This is the fourth flowchart of an image processing method provided in the embodiments of this application;
[0016] Figure 5 This is the fifth flowchart of an image processing method provided in the embodiments of this application;
[0017] Figure 6 This is the sixth flowchart of an image processing method provided in the embodiments of this application;
[0018] Figure 7 This is the seventh flowchart of an image processing method provided in the embodiments of this application;
[0019] Figure 8 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application;
[0020] Figure 9 This is one of the hardware structure diagrams of an electronic device provided in the embodiments of this application;
[0021] Figure 10 This is a second schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0023] The terms "first," "second," etc., used in this application's specification are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class, without limiting the number of objects. For example, a first object can be one or more, where "more" means at least two. Furthermore, in the specification, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0024] The terms "at least one," "at least one," etc., used in this application's specification refer to any one, any two, or a combination of two or more of the included objects. For example, "at least one of a, b, and c" can mean: "a," "b," "c," "a and b," "a and c," "b and c," and "a, b, and c," where a, b, and c can be single or multiple, and multiple means at least two. Similarly, "at least two" refers to two or more, and its meaning is similar to that of "at least one."
[0025] The terminology used in the implementation section of this application is only for explaining specific embodiments of this application and is not intended to limit this application. The terminology involved in the embodiments of this application is explained below.
[0026] The RGB color space is an additive color model that generates other colors by superimposing three primary colors: red (R), green (G), and blue (B). Each color channel typically has a value ranging from 0 to 255. It is device-dependent, meaning that different electronic devices, such as monitors and cameras, may display RGB differently.
[0027] The LAB color space, also known as CIELAB or Lab*, is a uniform color space based on human visual perception. It divides color information into two parts: lightness (L) and chromaticity (A / B). It was established based on the international standard for color measurement developed by the International Commission on Illumination (CIE) in 1931. It is a device-independent color system and also a physiologically based color system, aiming to make the numerical variations in the color space consistent with the color differences perceived by the human eye. This means that it uses a digital method to describe human visual perception. In the Lab color space, the lightness channel represents the brightness of a pixel, with values ranging from [0, 100], representing pure black to pure white; the a channel represents the range from red to green, with values ranging from [127, -128]; and the b channel represents the range from yellow to blue, with values ranging from [127, -128].
[0028] Local Binary Pattern (LBP) is a classic algorithm for texture feature extraction. It describes local texture features by comparing the grayscale values of a pixel with those of its neighbors to generate a binary code. LBP offers advantages such as computational simplicity, rotation invariance, and grayscale invariance, and is widely used in face recognition, image classification, and object detection. The core idea of LBP is to use the center pixel as a reference and compare its grayscale values with those of its neighboring pixels to generate a binary code. This code reflects the distribution pattern of the local texture, such as edges, spots, and corners, and is insensitive to changes in illumination.
[0029] Segmentation masks are a key tool in image processing and computer vision used to accurately identify the boundaries and categories of different objects or regions in an image. They divide an image into multiple meaningful regions, such as foreground, background, or different objects, by assigning a category label or value to each pixel.
[0030] In today's digital age, image applications are becoming increasingly widespread, and users have higher and higher requirements for the quality of portrait images. However, in actual shooting processes, due to the influence of various factors such as ambient light, camera equipment, and shooting techniques, portrait images often suffer from various problems, such as noise interference, color deviation, uneven lighting, and loss of detail. These problems seriously affect the visual effect of the image. Therefore, users can adjust the problems in the image one by one according to their needs through image processing applications.
[0031] Typically, most image processing methods in related technologies can only address single problems, such as noise reduction or color correction, or they simply stack image processing methods in a pipeline manner, failing to comprehensively and systematically solve the multiple problems existing in portrait images. Furthermore, these methods often lack targeted processing for different regions of the image, failing to perform refined optimization based on the characteristics of the portrait and the features of different regions, resulting in less than ideal image quality after processing.
[0032] Specifically, the main problems in the relevant technologies are reflected in the following three aspects:
[0033] (1) “Island-style” processing lacking overall planning: In related technologies, noise reduction, color correction, contrast enhancement and other steps are usually regarded as independent and isolated tasks. Each step is based on the original image or the output of the previous step, but the needs of subsequent steps or the impact of the previous step are not considered.
[0034] For example, destructive processing: During image processing of portrait images, a strong noise reduction algorithm may erase the subtle textures of the skin and hair, resulting in a loss of image details. Subsequently, no matter how precise the color correction is, it is impossible to recover these lost texture details, resulting in a face with accurate colors but a heavy "plastic" look; conflicting goals: Color correction may attempt to increase the saturation of a certain area, but if that area happens to be a color spot or artifact left after noise reduction, then the correction will actually amplify these defects.
[0035] (2) "One-size-fits-all" parameters lack regional specificity: A portrait image usually includes different regions such as skin, hair, eyes, lips, clothing, and background. The characteristics and optimization goals of these regions are completely different.
[0036] For example, taking noise reduction as an example, users typically want strong noise reduction for skin areas to smooth them out, but weak noise reduction, or even no noise reduction at all, is needed for areas such as eyes, eyebrows, and hair to preserve their key details. However, image processing methods in related technologies struggle to intelligently achieve this kind of regional optimization; taking color correction as an example, the goal of color correction for portraits is usually to make skin tone rosy and healthy, lip color natural, and eye whites pure, rather than "correcting" the colors of the background and clothing to a distorted degree as well.
[0037] (3) Neglecting the connection and transition between regions: A portrait is an organic whole, and the treatment of the boundaries between different regions is crucial, such as the boundary between the cheek and the hair. In related technologies, simple serial processing can easily produce harsh boundaries, halos or color bleeding in these places, making the processed portrait image look unnatural.
[0038] The image processing method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0039] The image processing method provided in this application can be applied to scenarios involving image processing of portrait images. For example, when a user needs to process an image containing a person, such as a first portrait image, the electronic device can perform region segmentation processing on the first portrait image to obtain N image regions corresponding to the first portrait image. Then, the electronic device can perform a corresponding first brightness adjustment processing on each image region based on the feature information of each of the N image regions to obtain a second portrait image, that is, a portrait image obtained from the processed N image regions. Then, the electronic device can perform light and shadow adjustment processing on the second portrait image based on at least one of the light and shadow mapping information, light and shadow distribution information, and light and shadow change information of the first portrait image to obtain a third portrait image, that is, the final processed portrait image.
[0040] It should be noted that the above exemplary examples illustrate one possible application scenario of the embodiments of this application. In actual implementation, the embodiments of this application can also be applied to any possible scenario, such as comprehensive and systematic optimization processing of images containing any objects or image elements such as people, animals, plants, and buildings. The embodiments of this application are not limited here.
[0041] Based on the scenarios described above in the embodiments of this application, the image processing method provided in this application allows the electronic device to first divide a first portrait image into N image regions. Then, the electronic device can perform a corresponding first brightness adjustment process on each of the N image regions of the first portrait image based on the feature information of each region. This means that each image region can undergo a different degree of first brightness adjustment, allowing the electronic device to perform more accurate processing on each region, thereby improving image quality. Next, the electronic device can perform light and shadow adjustment processing on a second portrait image based on at least one of the light and shadow mapping information of the original portrait image, namely, the light and shadow distribution information and light and shadow change information of the first portrait image. This results in a processed third portrait image with new light and shadow effects, enhancing the image's three-dimensionality and artistic appeal. Thus, the light and shadow display effect and image quality of the processed portrait image are improved.
[0042] The image processing method provided in this application is executed by an image processing device, which can be an electronic device, or a functional module or entity within an electronic device. This application does not limit the specific implementation of this method. The following will use an electronic device as an example to illustrate the image processing method provided in this application.
[0043] This application provides an image processing method. Figure 1 A flowchart illustrating an image processing method provided in an embodiment of this application is shown. Figure 1 As shown, the image processing method provided in this application embodiment may include the following steps 201 to 203.
[0044] Step 201: The electronic device performs region segmentation processing on the first portrait image to obtain N image regions.
[0045] Where N is a positive integer.
[0046] In some embodiments of this application, the first portrait image described above can be any portrait image to be processed stored in the electronic device.
[0047] In some embodiments of this application, the electronic device can read the portrait image to be processed, namely the first portrait image mentioned above, from the local storage device through a professional image reading function, so as to ensure that the electronic device can accurately obtain the original image data of the first portrait image.
[0048] For example, the image reading function described above can be the cv2.imread() function using the OpenCV library in Python.
[0049] In some embodiments of this application, combined with Figure 1 ,like Figure 2 As shown, step 201 above can be implemented through step 201a below.
[0050] Step 201a: The electronic device performs region segmentation processing on the first portrait image based on the image feature information of the first portrait image to obtain N image regions.
[0051] In some embodiments of this application, the above-mentioned image feature information may include at least one of the following: color feature information, texture feature information, and shape feature information.
[0052] In some embodiments of this application, the above-mentioned color feature information can be represented by a color histogram.
[0053] It should be noted that the above color histogram can reflect the distribution of different colors in the first portrait image.
[0054] In some embodiments of this application, the texture feature information described above may include, but is not limited to, at least one of the following: skin texture, hair texture, and object texture.
[0055] In some embodiments of this application, the aforementioned objects may include, but are not limited to, at least one of the following: clothing worn by a person in a portrait image; objects included in the background, such as plants, buildings, etc.
[0056] In some embodiments of this application, the object texture may include at least one of the object's material and pattern.
[0057] In some embodiments of this application, the method for extracting the texture feature information described above may include, but is not limited to, any of the following: gray-level co-occurrence matrix, local binary pattern (LBP).
[0058] It should be noted that the gray-level co-occurrence matrix described above can describe the spatial distribution relationship of gray levels in an image, and the local binary pattern described above can effectively describe the local texture information of an image.
[0059] For example, electronic devices can improve algorithms based on LBP, such as using uniform LBP to reduce feature dimensionality and improve robustness. Using rotation-invariant LBP avoids the impact of texture orientation changes, and further combining LBP with data from the luminance channel in the LAB color space allows for the extraction of texture feature information from the first portrait image while considering the intensity of patterns and local grayscale differences. This can solve potential color interference problems during image segmentation in the RGB color space, such as misidentifying shadows as color spots. The algorithmic improvements to LBP make texture feature descriptions more accurate and stable, thus providing higher-quality input for subsequent region segmentation.
[0060] In some embodiments of this application, the aforementioned shape feature information may include, but is not limited to, the shape feature information corresponding to the person and the shape feature information of the objects included in the background.
[0061] In some embodiments of this application, the shape feature information corresponding to the aforementioned person may include, but is not limited to, at least one of the following: the shape of the facial contour; the shape of facial organs, such as the shape of the eyes, the shape of the eyebrows, and the shape of the lips; and the shape of the person's clothing.
[0062] In some embodiments of this application, the method for obtaining the above-mentioned shape feature information may include, but is not limited to, any of the following: edge detection and contour extraction.
[0063] It should be noted that the edge detection described above can identify regions in an image with drastic grayscale changes to determine the shape of objects or features contained in the image; the contour extraction described above can extract the boundaries of objects or features from the image to determine the shape of those objects or features.
[0064] In some embodiments of this application, the image content corresponding to the above N image regions may include, but is not limited to, at least one of the following: skin, hair, eyes, lips, clothing, and background.
[0065] In some embodiments of this application, step 201 can be specifically implemented by the following steps 201b1 and 201b2.
[0066] Step 201b1: The electronic device divides the first portrait image into M image regions.
[0067] Where M is an integer greater than N.
[0068] In this embodiment, the electronic device can perform region segmentation processing on the first portrait image based on the image feature information of the first portrait image to obtain M image regions. That is, each image region can correspond to a type of image, so the electronic device can perform different forms and degrees of image adjustment processing on each image region. In other words, the electronic device can perform more accurate processing on each image region, thereby improving the display effect and image quality of the processed portrait image.
[0069] In some embodiments of this application, the segmentation method used by the electronic device to segment the first portrait image may include, but is not limited to, any of the following: threshold segmentation, cluster analysis, and graph-based segmentation methods.
[0070] It should be noted that the threshold segmentation described above can divide pixels in an image into different categories by setting one or more thresholds, thereby performing region segmentation based on categories;
[0071] The clustering analysis described above is an unsupervised learning method that segments an image into multiple regions by grouping similar pixels into a single class. For example, commonly used clustering algorithms include the K-Means clustering algorithm, which iteratively assigns pixels to different cluster centers until the cluster centers no longer change.
[0072] The graph-based segmentation methods described above can treat an image as a graph, where each pixel is a node and the connections between pixels are edges. Image segmentation is achieved by segmenting the graph. For example, the watershed algorithm is a graph-based segmentation method that treats an image as a terrain surface and segments the image by simulating the flow of water.
[0073] Step 201b2: Based on the feature information of M image regions, the electronic device merges the image regions whose feature information matches in the M image regions to obtain N image regions.
[0074] In some embodiments of this application, the aforementioned feature information may include, but is not limited to, at least one of the following: color information, texture information, and spatial distance information.
[0075] In some embodiments of this application, the electronic device may merge M image regions into N image regions based on morphological operations and connected component analysis.
[0076] In some embodiments of this application, the morphological operations described above may include at least one of dilation and erosion operations; wherein, dilation can expand the boundaries of objects in an image outward to fill small holes and voids inside the objects; erosion can shrink the boundaries of objects inward to remove noise and small connected regions around the objects. That is, noise is removed by opening operations, and holes are filled by closing operations.
[0077] In some embodiments of this application, the above-described connected component analysis can identify interconnected pixel regions in an image, and mark and analyze them to remove small discontinuous regions and merge adjacent small regions, making the segmentation results more accurate and continuous.
[0078] Understandably, after image segmentation, there are usually some small isolated points, i.e. noise, as well as holes inside the region or irregular spikes at the region boundary. Therefore, electronic devices can use morphological operations and connected component analysis to improve the image segmentation quality after segmentation through "secondary optimization" or "post-processing".
[0079] In some embodiments of this application, the aforementioned N image regions can be meaningful, complete regions, such as an entire face or a patch of hair.
[0080] In this embodiment, the electronic device can perform region merging processing on the regions after image segmentation based on the feature information of the image region, so as to intelligently merge the over-segmented small regions obtained by one segmentation into meaningful complete regions, thereby ensuring the accuracy and continuity of image segmentation processing, and facilitating the subsequent execution of corresponding image processing for each image region by the electronic device.
[0081] Step 202: The electronic device performs a first brightness adjustment process on each image region based on the feature information of each image region to obtain a second portrait image.
[0082] In some embodiments of this application, the first brightness adjustment process described above can be a local fine-tuning of the first portrait image, with the focus on enhancing the sense of depth and detail.
[0083] In some embodiments of this application, the electronic device can achieve the first brightness adjustment process described above by adjusting different frequency layers of the image.
[0084] In some embodiments of this application, combined with Figure 1 ,like Figure 3 As shown, step 202 above can be implemented through step 202a below.
[0085] Step 202a: The electronic device performs a first brightness adjustment process on the highlight and shadow areas according to the feature information of the highlight and shadow areas in the N image areas to obtain the second portrait image.
[0086] In some embodiments of this application, the aforementioned highlight area can be the brightest part of the portrait image; the aforementioned shadow area can be the darkest part of the portrait image.
[0087] In some embodiments of this application, the electronic device determines the highlight and shadow regions in N image regions of the first portrait image through histogram analysis, and uses a curve adjustment tool to finely adjust portions of the highlight and shadow regions. Specifically, the curve adjustment tool can change the brightness and contrast of the image by drawing curves.
[0088] For example, for highlight areas, the electronic device can appropriately reduce the brightness to restore the details of the highlight areas; for shadow areas, the electronic device can appropriately increase the brightness to make the details of the shadow areas clearer.
[0089] It should be noted that during the first brightness adjustment process described above, the electronic device can perform fine-tuning on the second portrait image according to the specific situation of the image, so as to avoid over-adjustment that would result in an unnatural effect.
[0090] In this embodiment, the electronic device can adjust the brightness of highlight and shadow areas.
[0091] Understandably, during shooting, less-than-ideal lighting conditions or limited camera dynamic range often result in overexposed highlights that appear pure white, or underexposed shadows that appear completely black. These areas may lose significant texture and detail. Electronic devices can adjust the brightness of these areas to "recover" this lost detail. For example, overexposed highlights can reveal the texture of skin and clothing, while underexposed shadows can reveal the layers of hair and background. Thus, in the adjusted portrait image, the facial contours are more defined. The highlights on the bridge of the nose and cheekbones, along with the shadows in the eye sockets and under the nose, collectively create the three-dimensional structure of the face. Adjusting these areas enhances the three-dimensionality of the face, resulting in a more textured portrait image.
[0092] At the same time, for an ideal portrait image, its brightness distribution should be balanced. If the highlights are too "glaring" or the shadows are too "heavy," it will cause visual discomfort to the user. Therefore, electronic devices can adjust the overall tone of the image to a more harmonious and aesthetically pleasing state by adjusting the highlights and shadows separately, allowing the viewer's eye to move comfortably through the image.
[0093] In this way, electronic devices can adjust the highlight and shadow areas to restore the true details of portrait images and enhance the visual three-dimensionality, thereby improving the stereoscopic display effect and image quality of the processed portrait images.
[0094] Step 203: The electronic device performs light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain the third portrait image.
[0095] In some embodiments of this application, the above-mentioned light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
[0096] In some embodiments of this application, the above-mentioned light and shadow mapping information can be represented in the form of an image, which can essentially be a new and independent data layer.
[0097] For example, the above light and shadow mapping information can be represented in the form of a grayscale image, where the bright part represents the area that is desired to be brighter in the final portrait image, and the dark part represents the area that is desired to be darker.
[0098] It should be noted that the grayscale image mentioned above can be generated by analyzing the original image using an algorithm, or it can be drawn manually or selected from a resource library. Its purpose is to add or reshape the lighting effects of portrait images.
[0099] In some embodiments of this application, an electronic device can decompose a second portrait image into a base layer and a detail layer by guided filtering. The base layer can be an image portion containing large-scale light and shadow and color, while the detail layer can be an image portion containing fine textures and edges.
[0100] In some embodiments of this application, for the aforementioned base layer, the electronic device can retain its corresponding overall tone through guided filtering.
[0101] In some embodiments of this application, for the above-mentioned detail layers, the electronic device can use a region segmentation mask for weighted superposition to avoid the loss of high-frequency information, for example, to avoid the loss of hair strands during the processing of portrait images.
[0102] In some embodiments of this application, the aforementioned region segmentation mask can be the result output by an electronic device during the process of dividing an image region. The region segmentation mask can be a map that identifies which image region each pixel belongs to.
[0103] In some embodiments of this application, the aforementioned region segmentation mask can instruct an electronic device to determine how to process different layers.
[0104] For example, when overlaying a detail layer, a greater weight can be assigned to the hair image area and a smaller weight to the skin image area, in order to selectively enhance hair details while avoiding enlarging skin pores.
[0105] In some embodiments of this application, combined with Figure 1 ,like Figure 4 As shown, before step 203 above, the image processing method provided in this application embodiment may further include the following steps 501 and 502.
[0106] Step 501: The electronic device performs image blurring on the first portrait image to obtain the blurred first portrait image.
[0107] Step 502: The electronic device performs gradient calculation on the blurred first portrait image to obtain the light and shadow mapping information of the first portrait image.
[0108] In some embodiments of this application, the above-described image blurring process can be Gaussian blurring.
[0109] In some embodiments of this application, the above-mentioned light and shadow mapping information can be used to represent the distribution and changes of light and shadow in the first portrait image.
[0110] In this embodiment, the electronic device can smooth the details in the first portrait image through image blurring, making the lighting and shadow effects corresponding to the generated lighting and shadow mapping information more natural. Furthermore, it can make the effects of subsequent lighting and shadow adjustment processing more natural, thereby improving the lighting and shadow display effect and image quality of the processed portrait image.
[0111] In some embodiments of this application, combined with Figure 1 ,like Figure 5 As shown, step 203 above can be implemented through step 203a below.
[0112] Step 203a: The electronic device performs weighted fusion of the light and shadow mapping information of the first portrait image and the second portrait image based on the assigned weight value corresponding to each pixel of the second portrait image to obtain the third portrait image.
[0113] In some embodiments of this application, the weight value assigned to each pixel can be determined based on the grayscale value of the corresponding pixel in the light and shadow mapping information.
[0114] In some embodiments of this application, if the grayscale value of a certain image region is high, it can indicate that the light and shadow effect of that region is strong. The weight of that region can be increased during fusion, so that the light and shadow effect of the second portrait image in that region is more obvious.
[0115] In some embodiments of this application, if the grayscale value of a certain image region is low, the weight of that region can be reduced to maintain the original effect of the second portrait image.
[0116] In some embodiments of this application, the above-mentioned weighted fusion can be understood as treating the grayscale image indicated by the light and shadow mapping information and the second portrait image as two images to perform layer fusion, such as the transparency and blending mode of the upper image, so as to naturally superimpose the light and shadow mapping information onto the second portrait, thereby creating a new light and shadow effect.
[0117] In this embodiment of the application, the electronic device can use weighted fusion to give the fused third-person portrait image a new lighting effect, thereby enhancing the three-dimensionality and artistic feel of the image.
[0118] In some embodiments of this application, the above-mentioned "obtaining a third portrait image" can be understood as: the electronic device can display the third portrait image on the screen and store the third portrait image based on the user's input on the displayed third portrait image.
[0119] In some embodiments of this application, during the process of storing the aforementioned third-person portrait image on an electronic device, the electronic device may, according to user requirements, store the third-person portrait image in a specified image format and set corresponding image quality parameters.
[0120] In the image processing method provided in this application embodiment, the electronic device first divides the first portrait image into N image regions. Then, based on the feature information of each of the N image regions of the first portrait image, the electronic device performs a corresponding first brightness adjustment process on each image region. That is, each image region can undergo a first brightness adjustment process of varying degrees, allowing the electronic device to perform more accurate processing on each image region, thereby improving image quality. Then, based on the light and shadow mapping information of the original portrait image, namely at least one of the light and shadow distribution information and light and shadow change information of the first portrait image, the electronic device performs light and shadow adjustment processing on the second portrait image. This allows the processed third portrait image to have new light and shadow effects, thereby enhancing the image's three-dimensionality and artistic appeal. Thus, the light and shadow display effect and image quality of the processed portrait image are improved.
[0121] In some embodiments of this application, combined with Figure 1 ,like Figure 6 As shown, before step 201 above, the image processing method provided in this application embodiment may further include the following steps 301 and 302, and step 202 above can be specifically implemented by the following step 202b.
[0122] Step 301: The electronic device converts the RGB color space of the first portrait image to the LAB color space.
[0123] Step 302: The electronic device acquires the luminance channel data of the first portrait image in the LAB color space.
[0124] Understandably, the RGB color space has certain limitations in color adjustment and analysis, while the LAB color space is more in line with human color perception and can divide color information into two parts: brightness and chromaticity, making it easier to adjust the brightness and color of an image independently.
[0125] It should be noted that for the specific implementation of how the electronic device converts the RGB color space of the first portrait image to the LAB color space, please refer to the conversion methods in related technologies. The embodiments of this application will not be described in detail here.
[0126] In some embodiments of this application, after the electronic device converts the color space of the first portrait image from RGB color space to LAB color space, the electronic device can perform noise reduction processing on the L channel in the LAB color space to provide clean and operable image data for subsequent image processing methods.
[0127] It should be noted that during the process of the electronic device performing noise reduction processing on the L channel in the LAB color space of the first portrait image, the chroma channel of the first portrait image will not be affected, thus preserving the color details of the chroma channel.
[0128] In some embodiments of this application, when the first image processing includes luminance noise reduction processing, the noise reduction processing method performed by the electronic device may include, but is not limited to, any one of the following: mean filtering, median filtering, and Gaussian filtering.
[0129] It should be noted that the mean filtering method described above is a simple linear filtering method. It can replace the center pixel value by calculating the average value of the pixels in the neighborhood, which can effectively remove Gaussian noise. However, noise reduction through mean filtering may blur the edges of the image.
[0130] The median filtering method described above is a non-linear filtering method that replaces the center pixel value by sorting the pixel values in the neighborhood and taking the median value. It has a good effect on removing salt-and-pepper noise and can also preserve image edges well.
[0131] The Gaussian filtering method described above is a linear smoothing filtering method that can perform a weighted average of pixels in the neighborhood based on a Gaussian function. It can effectively remove Gaussian noise while having a relatively small degree of blurring on the image.
[0132] It is understandable that during the image acquisition process, noise may exist in the image due to factors such as camera sensor noise and environmental interference, which affects the image clarity and quality. Therefore, electronic devices can select appropriate noise reduction methods to preprocess the image based on the type and characteristics of the noise.
[0133] It should be noted that the filtering method and parameters used for each image region can be determined according to the specific needs of each image region, and this application embodiment does not limit them here.
[0134] In some embodiments of this application, the electronic device may use a small kernel Gaussian filter to perform noise reduction on smooth areas, such as the skin of the person in the first portrait image described above.
[0135] It should be noted that the smooth areas mentioned above can be areas with simple textures and gentle changes in color and brightness, such as large areas of skin, sky, or solid-color walls.
[0136] Understandably, the smoothed regions mentioned above are usually more sensitive to noise, and even small noises are easily detected. Therefore, smoothing filters such as Gaussian filters are suitable for creating a sense of smoothness.
[0137] In some embodiments of this application, the electronic device may employ a non-local means filter (NLM) for high-frequency regions to protect textures, such as the hair strands of a person in a first portrait image.
[0138] It should be noted that the aforementioned high-frequency areas can be areas with complex textures, rich details, and dense edges, such as hair strands, eyelashes, fabric textures, and leaves.
[0139] Understandably, the aforementioned high-frequency regions inherently contain a significant amount of high-frequency information that requires special protection. Therefore, electronic devices can utilize algorithms such as NLM to better distinguish between noise and real texture, thus preserving details while performing noise reduction on the image.
[0140] In some embodiments of this application, the electronic device can adjust the filter kernel parameters used for denoising an image region based on the noise level of that region. For example, for images with low noise, the electronic device can select a smaller filter kernel size; for images with high noise, the filter kernel size can be appropriately increased.
[0141] It's important to note that each filter type has its own corresponding filter kernel, which can be sized in various ways. The filter kernel size is an independent parameter, such as 3×3, 5×5, or 7×7. The choice of filter type depends on the processing target, while the filter kernel size can be fine-tuned within the filter based on the noise level of the region and the desired level of detail to be preserved.
[0142] Step 202b: The electronic device performs a first brightness adjustment process on the brightness channel data of each image region in the LAB color space according to the feature information of each image region, and obtains the second portrait image.
[0143] It is understandable that since the electronic device converts the RGB color space of the first portrait image to the LAB color space, the electronic device can adjust the data of the L channel in the LAB color space during the brightness adjustment process of the image area to achieve brightness adjustment processing of the image area.
[0144] In this embodiment, the electronic device can convert the RGB color space of the first portrait image to the LAB color space, so that the brightness and chromaticity are completely decoupled. This allows the brightness of the first portrait image to be adjusted without affecting the chromaticity information of the first portrait image, avoiding the color distortion such as skin tone shift that occurs in the portrait image due to brightness adjustment in related technologies. This improves the accuracy of image processing performed by the electronic device and can improve the color display effect and image quality of the processed portrait image.
[0145] In some embodiments of this application, after step 201 above, the image processing method provided in the embodiments of this application may further include the following step 401.
[0146] Step 401: The electronic device performs first image processing on N image regions based on the texture feature information of each image region.
[0147] It is understandable that the texture feature information of each image region can reflect the surface characteristics of that image region, such as its smoothness or roughness. Electronic devices can analyze the texture feature information of different image regions to determine the tone optimization strategy corresponding to each image region, i.e., the image processing method corresponding to the first image processing described above.
[0148] For example, users typically want the skin area to have a smoother texture and more delicate tones; while for the hair area, users may want to highlight its texture details and enhance the sense of tonal gradation. Therefore, electronic devices can use texture analysis algorithms, such as local binary mode, to calculate texture feature values for different areas and determine the direction and degree of tonal optimization based on the calculated texture feature values.
[0149] In some embodiments of this application, the first image processing described above may include at least one of the following: first brightness adjustment processing, color correction processing, and contrast enhancement processing.
[0150] In some embodiments of this application, when the first image processing includes a second brightness adjustment process, the brightness adjustment method performed by the electronic device may include, but is not limited to, any one of the following: linear transformation, nonlinear transformation.
[0151] It should be noted that the above linear transformation can change the brightness of an image by linearly mapping the pixel values of the image, thereby stretching or compressing the range of pixel values; the above nonlinear transformation can change the brightness of an image by non-uniformly adjusting the pixel values through a nonlinear function, thereby emphasizing or suppressing the details of specific brightness areas.
[0152] In some embodiments of this application, the aforementioned nonlinear transformation can be gamma correction, that is, changing the brightness and contrast of an image by adjusting the gamma value.
[0153] Specifically, for darker image areas, electronic devices can increase the gamma value of that image area to improve brightness; for brighter image areas, electronic devices can decrease the gamma value to reduce brightness.
[0154] It should be noted that when an electronic device adjusts the brightness of N image regions, it needs to perform targeted processing based on the characteristics of different image regions to avoid over-adjustment that could lead to image distortion.
[0155] For example, for the image regions corresponding to the skin of the person in the above N image regions, the electronic device can use low-intensity gamma correction to avoid overexposure of the processed image regions, and to make the light and dark transitions of the skin image regions more natural and the sense of layering stronger.
[0156] It should be noted that the above-mentioned second brightness adjustment process can be a global or regional tone adjustment, which focuses on improving the overall brightness and contrast distribution of the image area. In contrast, the first brightness adjustment process involved in step 202 and its related steps can be a local fine adjustment, which focuses on enhancing the sense of three-dimensionality and detail, and can usually be achieved by processing different frequency layers of the image.
[0157] In some embodiments of this application, when the first image processing includes color correction processing, the color correction method performed by the electronic device may include, but is not limited to, at least one of the following: color balance and histogram equalization.
[0158] It should be noted that the color balance mentioned above can make the colors of the processed image more accurate and natural by adjusting the proportions of the three primary colors of red, green and blue in the image; the histogram equalization mentioned above is a method that transforms the histogram of an image to make the gray-level distribution of the image more uniform, which can enhance the contrast and color saturation of the image.
[0159] It is understandable that the colors of the first portrait image may be deviated due to factors such as shooting environment and camera settings. Therefore, electronic devices need to correct the acquired first portrait image to ensure the accuracy of the colors in the final processed image.
[0160] It should be noted that during the color correction process, electronic devices need to refer to standard color spaces or sample images to ensure that the corrected colors conform to human visual perception.
[0161] In some embodiments of this application, the electronic device can determine the color correction method used by the electronic device to perform color correction processing on each image region based on the texture feature information and color statistical feature information of the image region, such as color cast and saturation.
[0162] For example, for skin image areas, electronic devices can preferentially use "color balance" based on skin color models to correct color casts, so that the color of the processed skin image area tends to be a healthy skin color; for background image areas such as blue sky or grass, electronic devices can use methods to enhance the saturation of specific color channels to ensure that the color of the background image area tends to be the color seen by the human eye.
[0163] In some embodiments of this application, the above-mentioned contrast enhancement processing refers to image processing that improves the clarity and visual effect of an image by enhancing the degree of difference between bright and dark areas in the image.
[0164] In some embodiments of this application, when the first image processing includes contrast enhancement processing, the contrast enhancement method performed by the electronic device may include, but is not limited to, at least one of the following: linear contrast stretching, histogram equalization, and adaptive histogram equalization.
[0165] It should be noted that the above-mentioned linear contrast stretching can enhance the contrast of an image by linearly stretching the range of pixel values to the entire grayscale range; the above-mentioned histogram equalization can make the grayscale distribution of the image more uniform and enhance the overall contrast; the above-mentioned adaptive histogram equalization can perform histogram equalization in local image regions to preserve the image's detail information and avoid over-enhancement or loss of detail during global equalization.
[0166] In some embodiments of this application, the electronic device can determine the image adjustment parameters corresponding to each image region based on aesthetic models such as ideal brightness, contrast, and color gamut for different image regions.
[0167] In some embodiments of this application, the electronic device can determine the image adjustment parameters corresponding to each image region based on the current state of each image region, such as average brightness, contrast value and other parameters.
[0168] In some embodiments of this application, the electronic device can automatically calculate the adjustment direction and adjustment range corresponding to the image region by comparing the "current state" and the "ideal model", i.e., the image adjustment parameters.
[0169] For example, if the current brightness of a skin area is 20% darker than the ideal model, the electronic device can automatically deduce that the gamma value needs to be increased by a specific amount to adjust the brightness value of that skin area.
[0170] In some embodiments of this application, when the electronic device performs corresponding first image processing on N image regions, the electronic device can use a bilateral filtering weight map to perform edge smoothing processing on the boundary of adjacent image regions. That is, through the boundary protection mechanism, the problem of unnatural brightness or color transitions that may occur at the boundary of different image regions can be avoided.
[0171] In this embodiment, the electronic device can determine the tone optimization strategy corresponding to each image region based on the texture features of each image region in N image regions. Through operations such as brightness adjustment, color correction, and contrast enhancement, the tone of the processed image region is made richer, the color is more accurate, and the contrast is more appropriate, thereby enhancing the sense of layering and visual effect of the image.
[0172] In some embodiments of this application, before “obtaining the third portrait image” in step 203 above, the image processing method provided in this application embodiment may further include the following step 601, and the above “obtaining the third portrait image” can be specifically implemented through the following step 602.
[0173] Step 601: The electronic device performs at least one of the following on the portrait image after light and shadow adjustment: color correction and sharpening.
[0174] Step 602: The electronic device uses the processed portrait image as a third-party portrait image.
[0175] It is understood that after the preliminary steps in the embodiments of this application, the color of the portrait image may undergo some slight changes, so color correction is required again to ensure the accuracy and consistency of the color.
[0176] In some embodiments of this application, the method by which an electronic device performs color correction processing may include, but is not limited to, any of the following: a correction method using a color management system, or a correction method based on a reference color chart.
[0177] It should be noted that the above-mentioned color management system calibration method can be an ICC profile-based calibration method. Specifically, an ICC profile is an international standard color description file that defines the color space and color conversion relationship of a device. By using an ICC profile, the colors of an image can be accurately converted to the color space of the target device. The reference color chart-based calibration method involves taking a picture of a reference color chart containing standard colors and performing color correction on the image according to the color information on the color chart, making the colors of the image more accurate and realistic.
[0178] In some embodiments of this application, the method by which an electronic device performs sharpening processing may include, but is not limited to, any of the following: Laplacian sharpening, high-pass filtering, and Unsharp Mask (USM) algorithm.
[0179] It should be noted that the Laplacian sharpening described above is a sharpening method based on the second derivative, which can enhance the edges and details of an image by performing Laplacian operator convolution on the image.
[0180] The high-pass filtering described above can enhance the edges and details of an image by removing low-frequency components while retaining high-frequency components.
[0181] The Unsharp Mask algorithm described above is a commonly used sharpening algorithm. It obtains high-frequency detail information of the image by subtracting the original image from the blurred image, and then adds the high-frequency detail information back to the original image to enhance the image sharpness. When performing sharpening processing, it is necessary to pay attention to controlling the degree of sharpening to avoid over-sharpening, which can lead to jagged edges and noise in the image.
[0182] In this embodiment, the electronic device can perform color correction on the processed image again to ensure color accuracy and consistency, and enhance the edges and details of the image through sharpening processing; thus, the image quality of the final image output by the electronic device can be improved.
[0183] This application provides an image processing method. Figure 7 A flowchart of an image processing method provided by an embodiment of this application is shown. The image processing method provided by this application will be described exemplarily below. Figure 7 As shown, the image processing method provided in this application embodiment may include the following steps 701 to 711.
[0184] Step 701: The electronic device acquires the portrait image to be processed;
[0185] Step 702: The electronic device converts the color space of the portrait image from RGB color space to LAB color space;
[0186] Step 703: The electronic device performs noise reduction processing based on the L channel in the LAB color space of the portrait image;
[0187] Step 704: The electronic device acquires the image feature information of the portrait image, performs region segmentation processing on the first portrait image, and obtains M image regions;
[0188] Step 705: Based on the feature information of M image regions, the electronic device merges the image regions whose feature information matches in the M image regions to obtain N image regions;
[0189] Step 706: Based on the texture feature information of each of the N image regions, the electronic device performs at least one of the following image processing operations on the N image regions: brightness adjustment processing, color correction processing, and contrast enhancement processing.
[0190] Step 707: The electronic device adjusts the highlight and shadow areas in the processed portrait image;
[0191] Step 708: The electronic device performs Gaussian blur processing on the original portrait image to be processed, and performs gradient calculation on the processed image to obtain the light and shadow mapping image corresponding to the original portrait image.
[0192] Step 709: The electronic device performs a weighted fusion of the light and shadow mapping image and the portrait image after highlight and shadow processing to obtain the portrait image after light and shadow adjustment;
[0193] Step 710: The electronic device performs at least one of the following processes on the portrait image after light and shadow adjustment: color correction and sharpening, to obtain the final processed portrait image;
[0194] Step 711: The electronic device saves and outputs the final processed portrait image.
[0195] It should be noted that the above-described method embodiments, or the various possible implementations of the method embodiments, can be executed individually, or, provided there are no contradictions, they can be combined with each other. The specific implementation can be determined according to actual usage requirements, and this application embodiment does not impose any restrictions on this.
[0196] It should be noted that the image processing method provided in this application embodiment can be executed by an image processing device. This application embodiment uses an image processing device executing the image processing method as an example to illustrate the image processing device provided in this application embodiment.
[0197] Figure 8 A schematic diagram of a possible structure of the image processing apparatus involved in an embodiment of this application is shown. For example... Figure 8As shown, the image processing device 80 may include: a processing module 81;
[0198] The processing module 81 is used to perform region segmentation processing on the first portrait image to obtain N image regions, where N is a positive integer;
[0199] The processing module 81 is also used to perform a first brightness adjustment process on each image region according to the feature information of each image region to obtain a second portrait image;
[0200] The processing module 81 is also used to perform light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain a third portrait image. The light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
[0201] In one possible implementation, the image processing apparatus 80 provided in this application embodiment may further include: an acquisition module; the processing module 81 is further configured to convert the RGB color space of the first portrait image to the LAB color space before performing region segmentation processing on the first portrait image to obtain N image regions; the acquisition module is configured to acquire the luminance channel data of the first portrait image in the LAB color space; the processing module 81 is specifically configured to perform corresponding first luminance adjustment processing on the luminance channel data of each image region in the LAB color space according to the feature information of each image region to obtain the second portrait image.
[0202] In one possible implementation, the processing module 81 is specifically used to perform region segmentation processing on the first portrait image based on the image feature information of the first portrait image to obtain N image regions. The image feature information includes at least one of the following: color feature information, texture feature information, and shape feature information.
[0203] In one possible implementation, the processing module 81 is specifically used to segment the first portrait image into M image regions, where M is an integer greater than N; and based on the feature information of the M image regions, to merge the image regions in the M image regions whose feature information matches, to obtain N image regions.
[0204] In one possible implementation, the processing module 81 is further configured to perform a first image processing on the N image regions based on the texture feature information of each image region after performing region segmentation processing on the first portrait image. The first image processing includes at least one of the following: a first brightness adjustment processing, a color correction processing, and a contrast enhancement processing.
[0205] In one possible implementation, the processing module 81 is specifically used to perform a first brightness adjustment process on the highlight areas and shadow areas according to the feature information of the highlight areas and shadow areas in N image areas, so as to obtain a second portrait image.
[0206] In one possible implementation, the processing module 81 is further configured to perform image blurring on the first portrait image before performing light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain the third portrait image, thereby obtaining the blurred first portrait image; and to perform gradient calculation on the blurred first portrait image to obtain the light and shadow mapping information of the first portrait image.
[0207] In one possible implementation, the aforementioned processing module 81 is specifically used to perform weighted fusion of the light and shadow mapping information of the first portrait image and the second portrait image based on the assigned weight value corresponding to each pixel of the second portrait image to obtain a third portrait image. The assigned weight value of each pixel is determined based on the gray value of the corresponding pixel in the light and shadow mapping information.
[0208] In the image processing apparatus provided in this application embodiment, the image processing apparatus first performs region division processing on the first portrait image to obtain N image regions. Then, based on the feature information of each image region in the N image regions of the first portrait image, the image processing apparatus performs corresponding first brightness adjustment processing on each image region. That is, each image region can undergo first brightness adjustment processing of different degrees, meaning the image processing apparatus can perform more accurate processing on each image region to improve image quality. Then, the electronic device can perform light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the original portrait image, namely, at least one of the light and shadow distribution information and light and shadow change information of the first portrait image. This allows the processed third portrait image to have new light and shadow effects, thereby enhancing the image's three-dimensionality and artistic feel. Thus, the light and shadow display effect and image quality of the processed portrait image are improved.
[0209] The image processing device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.
[0210] The image processing device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0211] The image processing apparatus provided in this application embodiment can implement the various processes implemented in the above method embodiments, and will not be described again here to avoid repetition.
[0212] Optionally, such as Figure 9 As shown, this application embodiment also provides an electronic device 90, including a processor 91 and a memory 92. The memory 92 stores a program or instructions that can run on the processor 91. When the program or instructions are executed by the processor 91, they implement the various steps of the above-described image processing method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0213] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0214] Figure 10 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0215] The electronic device 100 includes, but is not limited to, components such as: radio frequency unit 101, network module 102, audio output unit 103, input unit 104, sensor 105, display unit 106, user input unit 107, interface unit 108, memory 109, and processor 110.
[0216] Those skilled in the art will understand that the electronic device 100 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 110 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 10 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0217] The processor 110 is used to perform region segmentation processing on the first portrait image to obtain N image regions, where N is a positive integer; and to perform corresponding first brightness adjustment processing on each image region according to the feature information of each image region to obtain a second portrait image; and to perform light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain a third portrait image, wherein the light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
[0218] Optionally, the processor 110 is further configured to convert the RGB color space of the first portrait image to the LAB color space before performing region segmentation processing on the first portrait image to obtain N image regions; and to obtain the luminance channel data of the first portrait image in the LAB color space; specifically, the processor 110 is configured to perform corresponding first luminance adjustment processing on the luminance channel data of each image region in the LAB color space according to the feature information of each image region to obtain the second portrait image.
[0219] Optionally, the processor 110 is specifically used to perform region segmentation processing on the first portrait image based on the image feature information of the first portrait image to obtain N image regions. The image feature information includes at least one of the following: color feature information, texture feature information, and shape feature information.
[0220] Optionally, the processor 110 is specifically used to segment the first portrait image into M image regions, where M is an integer greater than N; and based on the feature information of the M image regions, to merge the image regions in the M image regions whose feature information matches, to obtain N image regions.
[0221] Optionally, the processor 110 is further configured to perform a first image processing on the N image regions based on the texture feature information of each image region after performing region segmentation processing on the first portrait image to obtain N image regions. The first image processing includes at least one of the following: a first brightness adjustment processing, a color correction processing, and a contrast enhancement processing.
[0222] Optionally, the processor 110 is specifically used to perform a first brightness adjustment process on the highlight areas and shadow areas according to the feature information of the highlight areas and shadow areas in N image areas to obtain a second portrait image.
[0223] Optionally, the processor 110 is further configured to perform image blurring on the first portrait image before performing light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain the third portrait image, thereby obtaining a blurred first portrait image; and to perform gradient calculation on the blurred first portrait image to obtain the light and shadow mapping information of the first portrait image.
[0224] Optionally, the processor 110 is specifically used to perform weighted fusion of the light and shadow mapping information of the first portrait image and the second portrait image based on the weight value assigned to each pixel of the second portrait image to obtain a third portrait image, wherein the weight value assigned to each pixel is determined based on the gray value of the corresponding pixel in the light and shadow mapping information.
[0225] In the electronic device provided in this application embodiment, the electronic device first performs region division processing on the first portrait image to obtain N image regions. Then, based on the feature information of each image region in the N image regions of the first portrait image, the electronic device performs corresponding first brightness adjustment processing on each image region. That is, each image region can undergo first brightness adjustment processing of different degrees, meaning the electronic device can perform more accurate processing on each image region to improve image quality. Then, based on the light and shadow mapping information of the original portrait image, namely at least one of the light and shadow distribution information and light and shadow change information of the first portrait image, the electronic device performs light and shadow adjustment processing on the second portrait image, thereby giving the processed third portrait image a new light and shadow effect, thus enhancing the image's three-dimensionality and artistic feel. In this way, the light and shadow display effect and image quality of the processed portrait image are improved.
[0226] The electronic device provided in this application embodiment can implement the various processes implemented in the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0227] For details on the beneficial effects of the various implementation methods in this embodiment, please refer to the beneficial effects of the corresponding implementation methods in the above method embodiments. To avoid repetition, these will not be repeated here.
[0228] It should be understood that, in this embodiment, the input unit 104 may include a graphics processing unit (GPU) 1041 and a microphone 1042. The GPU 1041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 106 may include a display panel 1061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 107 includes at least one of a touch panel 1071 and other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0229] The memory 109 can be used to store software programs and various data. The memory 109 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 109 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 109 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.
[0230] Processor 110 may include one or more processing units; optionally, processor 110 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 110.
[0231] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0232] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0233] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0234] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0235] This application provides a program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0236] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0237] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0238] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. An image processing method, characterized in that, The method includes: The first portrait image is segmented into N image regions, where N is a positive integer. Based on the feature information of each image region, a corresponding first brightness adjustment process is performed on each image region to obtain a second portrait image; Based on the light and shadow mapping information of the first portrait image, the second portrait image is subjected to light and shadow adjustment processing to obtain a third portrait image. The light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
2. The method according to claim 1, characterized in that, Before performing region segmentation processing on the first portrait image to obtain N image regions, the method further includes: Convert the RGB color space of the first portrait image to the LAB color space; Acquire the luminance channel data of the first portrait image in the LAB color space; The step of performing a first brightness adjustment process on each image region based on the feature information of each image region to obtain a second portrait image includes: Based on the feature information of each image region, the data of the brightness channel of each image region in the LAB color space is subjected to a corresponding first brightness adjustment process to obtain the second portrait image.
3. The method according to claim 1 or 2, characterized in that, The first portrait image is segmented into N image regions, including: Based on the image feature information of the first portrait image, the first portrait image is segmented to obtain the N image regions. The image feature information includes at least one of the following: color feature information, texture feature information, and shape feature information.
4. The method according to claim 1 or 2, characterized in that, The first portrait image is segmented into N image regions, including: The first portrait image is divided into M image regions, where M is an integer greater than N; Based on the feature information of the M image regions, the image regions with matching feature information in the M image regions are merged to obtain the N image regions.
5. The method according to claim 1, characterized in that, After performing region segmentation processing on the first portrait image to obtain N image regions, the method further includes: Based on the texture feature information of each of the image regions, a first image processing is performed on the N image regions. The first image processing includes at least one of the following: a second brightness adjustment processing, a color correction processing, and a contrast enhancement processing.
6. The method according to claim 1, characterized in that, The step of performing a first brightness adjustment process on each image region based on the feature information of each image region to obtain a second portrait image includes: Based on the feature information of the highlight and shadow regions in the N image regions, the highlight and shadow regions are subjected to the corresponding first brightness adjustment processing to obtain the second portrait image.
7. The method according to claim 1 or 6, characterized in that, Before performing light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain the third portrait image, the method further includes: The first portrait image is blurred to obtain the blurred first portrait image; Gradient calculation is performed on the blurred first portrait image to obtain the light and shadow mapping information of the first portrait image.
8. The method according to claim 1, characterized in that, The step of adjusting the lighting and shadow of the second portrait image based on the lighting and shadow mapping information of the first portrait image to obtain the third portrait image includes: Based on the assigned weight value corresponding to each pixel of the second portrait image, the light and shadow mapping information of the first portrait image and the second portrait image are weighted and fused to obtain the third portrait image. The assigned weight value of each pixel is determined based on the gray value of the corresponding pixel in the light and shadow mapping information.
9. An image processing apparatus, characterized in that, The image processing device includes: a processing module; The processing module is used to perform region segmentation processing on the first portrait image to obtain N image regions, where N is a positive integer; The processing module is further configured to perform a first brightness adjustment process on each of the image regions according to the feature information of each image region to obtain a second portrait image; The processing module is further configured to perform light and shadow adjustment processing on the second portrait image based on the light and shadow mapping information of the first portrait image to obtain a third portrait image. The light and shadow mapping information includes at least one of the following: light and shadow distribution information and light and shadow change information.
10. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the image processing method as described in any one of claims 1 to 8.