Image processing method and apparatus therefor
By determining coordinates in the YUV color space and adjusting color components using a YUV lookup table, the problem of high computational burden in mobile terminal image processing is solved, achieving efficient color processing.
Patent Information
- Application Number
- CN202311243629.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-22
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2043-09-22
AI Technical Summary
In the process of image processing, mobile terminals such as mobile phones use the YUV color space to encode image data, which requires two color space conversions: RGB to YUV and YUV to RGB, resulting in a large computational burden.
By determining the first coordinates corresponding to the first color component of a pixel in the YUV color space coordinate system and determining the second color component in the YUV lookup table, the color components of the YUV image are directly adjusted, avoiding the use of the RGB lookup table and directly performing color space conversion.
It reduces the computational burden of data processing, lowers memory usage, and improves the efficiency of color processing.
Smart Images

Figure CN117274382B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image processing, and specifically relates to an image processing method, an image processing apparatus, an electronic device, and a readable storage medium. Background Technology
[0002] When viewing and editing images, people often want to see multiple different color styles of the same image. Users can change the color style of an image by switching filters, beauty effects, etc.
[0003] Current color switching schemes require using an RGB (red-green-blue) lookup table to find the RGB color component corresponding to the target color, and then replacing the color component in the image with this component to change the image's color style. Since mobile devices such as smartphones use the YUV (luminance-chrominance) color space to encode image data during photography and video recording, this necessitates two color space conversions during color processing, resulting in significant computational overhead. Summary of the Invention
[0004] The purpose of this application is to provide an image processing method that can solve the problem of high computational pressure during image processing.
[0005] In a first aspect, embodiments of this application provide an image processing method, the method comprising:
[0006] Obtain the first color component of a pixel in a YUV image;
[0007] In the YUV color space coordinate system, a first coordinate corresponding to the first color component is determined; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image.
[0008] Based on the first coordinates, the second color component corresponding to the pixel is determined in the YUV lookup table corresponding to the first color; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color.
[0009] Based on the second color component, the first color component of the pixels in the YUV image is adjusted to obtain a YUV image that includes the first color.
[0010] Secondly, embodiments of this application provide an image processing apparatus, the apparatus comprising:
[0011] The first color component module is used to obtain the first color component of the pixel in the YUV image;
[0012] The first coordinate module is used to determine the first coordinate corresponding to the first color component in the YUV color space coordinate system; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image.
[0013] The second color component module is used to determine the second color component corresponding to the pixel in a YUV lookup table corresponding to the first color based on the first coordinates; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color.
[0014] A color component adjustment module is used to adjust the first color component of pixels in the YUV image based on the second color component, to obtain a YUV image including the first color. In a third aspect, embodiments of this application provide an electronic device including a processor and a memory, the memory storing programs or instructions executable on the processor, the programs or instructions, when executed by the processor, implementing the steps of the method described in the first aspect.
[0015] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0016] 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.
[0017] 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.
[0018] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.
[0019] In this embodiment, by determining the first coordinates corresponding to the first color component of a pixel in the YUV color space coordinate system, and then determining the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinates, the first color component is adjusted using the second color component to complete the image color processing. This ensures successful color application without requiring the use of the RGB lookup table; instead, the color components are adjusted directly based on the YUV lookup table. This eliminates the need for two color space conversions, ultimately reducing the computational burden of data processing, lowering memory usage, and improving color processing efficiency. Attached Figure Description
[0020] Figure 1 This is a flowchart of the steps of an image processing method provided in an embodiment of the present invention;
[0021] Figure 2 This is a schematic diagram of the YUV color space coordinate system and the transformed coordinate system provided in the embodiments of the present invention;
[0022] Figure 3 This is a simplified schematic diagram of the overall process of an image processing method provided in an embodiment of the present invention;
[0023] Figure 4 This is a block diagram of an image processing device provided in an embodiment of the present invention;
[0024] Figure 5 This is a block diagram of an electronic device provided in an embodiment of the present invention;
[0025] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0026] 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.
[0027] The terms "first," "second," etc., used in the specification and claims of this application 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 and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "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.
[0028] 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. For example... Figure 1 As shown, the image processing method includes the following steps:
[0029] S1. Obtain the first color component of the pixel in the YUV image.
[0030] It's important to understand that a color space is a mathematical model used to describe and represent color. It's a color encoding method that maps three-dimensional color information to two- or three-dimensional space. Common color spaces include RGB, YUV, and HSV (Hue-Saturation-Lightness). The RGB color space (Red-Green-Blue color space) decomposes color into three color components: Red, Green, and Blue. By adjusting the brightness and proportions of these three color components, different colors can be obtained. The YUV color space decomposes color into two components: Lightness (Y) and Chroma (U, V). Lightness (Y) represents the brightness of an image, typically ranging from 0 to 255; a higher value indicates a brighter color. U and V represent Chroma, with U referring to blue chroma and V to red chroma.
[0031] Currently, mobile smart terminals such as smartphones typically use the YUV color space, such as the YCbCr color space, to encode image data during the process of taking photos and videos to obtain YUV images. Compared with the RGB color space, the YUV color space has a smaller data volume and separates grayscale and color independently, which facilitates image processing.
[0032] YUV images can be images acquired by users' mobile terminal devices through methods such as shooting and downloading. A YUV image is composed of several pixels. The color information of each pixel is represented by three components: Y, U, and V. The first color component of a pixel is the current Y, U, and V color components to be processed. The three color components of Y, U, and V are used as a set of color components to describe the color of the pixel.
[0033] The process of acquiring the first color component of a pixel in a YUV image can be initiated in response to a user's image processing operation, such as when the user selects one or more images from their phone's photo album and applies a filter to the image.
[0034] Obtaining the first color component of a pixel in a YUV image can be done by obtaining the color component of every pixel in the entire image, or by obtaining pixels from a portion of an image. For example, it can be done by recognizing the image and obtaining the region of a person in the image, and then obtaining the pixels of that region; or it can be done by obtaining the region of a landscape in the image, and then obtaining the pixels of that landscape region. This embodiment of the present disclosure does not limit how the pixels in the YUV image are obtained.
[0035] To obtain the color components of a pixel, its position needs to be determined: based on the image's width, height, and the byte offset between pixels, the target pixel's position in the image data is calculated. The Y component represents the pixel's brightness value and is typically stored at the beginning of the image data. Based on the calculated pixel position, the corresponding bytes or byte sequence are read to obtain the Y component. The U and V components are usually stored after the Y component. Based on the pixel position and the number of bytes occupied by the Y component, the positions of the U and V components in the image data are calculated, and then the corresponding bytes or byte sequence are read to obtain the pixel's first color component.
[0036] It's important to note that there are two main types of YUV formats: planar and packed. In planar YUV format, the Y color components of all pixels are stored consecutively first, then the U color components, and finally the V color components. In packed YUV format, the Y, U, and V components of each pixel are stored consecutively and interleaved. The specific storage method for YUV images can vary; common formats include YUV420, YUV422, and YUV444. Different formats affect the arrangement and byte length of the Y, U, and V components in memory. Therefore, different processing methods are needed depending on the specific YUV image format to obtain the first color component.
[0037] S2. In the YUV color space coordinate system, determine the first coordinate corresponding to the first color component.
[0038] The YUV color space uses a right-handed orthogonal coordinate system with V, U, and Y axes. The values for each dimension range from 0 to 255. The first color component of a pixel includes Y, U, and V, each of which can range from 0 to 255. Based on the first color components of a pixel, such as v, u, and y, a point (v, u, y) in the YUV color space coordinate system is obtained. The coordinates of this point can be used as the second coordinate, which is the coordinate within the YUV color space coordinate system. The first coordinate is then determined based on the second coordinate.
[0039] Optionally, step S2 may specifically include sub-steps S21-S22:
[0040] Sub-step S21: Determine the second coordinates in the YUV color space coordinate system based on the first color component; the YUV color space coordinate system includes a transformation coordinate system, which is obtained by mapping the RGB color space to the YUV color space.
[0041] Sub-step S22: Map the second coordinates to the transformed coordinate system to obtain the first coordinates.
[0042] In this embodiment of the invention, for sub-steps S21-S22, the YUV lookup table can be obtained by converting the RGB lookup table or other types of lookup tables. When the RGB color space coordinate system is converted to the YUV color space, there will be a coordinate system in the YUV color space coordinate system that is converted from the RGB color space coordinate system. This coordinate system is the coordinate system corresponding to the YUV lookup table.
[0043] Since the coordinate system corresponding to the YUV lookup table is not directly equivalent to the YUV color space coordinate system (the YUV color space coordinate system can be understood as an absolute coordinate system, while the coordinate system corresponding to the YUV lookup table is a transformed coordinate system located within the absolute coordinate system), the second coordinate cannot be directly applied to the YUV lookup table. It is necessary to transform the second coordinate in the YUV color space coordinate system to the transformed coordinate system, or to calculate the first coordinate in the transformed coordinate system corresponding to the YUV lookup table based on the second coordinate in the YUV color space coordinate system.
[0044] Optionally, the method may also include step A1, which may specifically include sub-steps A11-A12:
[0045] Sub-step A11: Convert the RGB color space to the YUV color space to obtain a parallelepiped located in the YUV color space;
[0046] Sub-step A12: Based on the three edges of the parallelepiped that have a common starting point, construct the transformation coordinate system; the common starting point is an origin of the RGB color space mapped to a corresponding point in the YUV color space.
[0047] In this embodiment, since the RGB table corresponds to the RGB color space, within the RGB color space, the RGB lookup table can represent a cube. By determining a coordinate within the RGB color space, the RGB color component data at that position within the cube can be obtained using the coordinate indicating that position. For example, when the size of the RGB lookup table is 255×255×255, the corresponding cube is an 8-bit RGB color space. The size of the RGB lookup table can be other sizes, and the corresponding RGB color space size can also be different; no limitation is imposed here.
[0048] The RGB lookup table is converted to a YUV lookup table. The cube in the RGB color space corresponding to the RGB lookup table is then converted into a polyhedron, such as a parallelepiped, in the YUV color space. A transformed coordinate system is constructed using the three edges of the parallelepiped that share a common origin as coordinate axes. This common origin is the origin of the transformed coordinate system, which is the point mapped from the origin of the RGB color space to the corresponding point in the YUV color space.
[0049] like Figure 2 As shown, the absolute coordinate system formed by the three coordinate axes Y, U, and V corresponds to the YUV color space. The YUV color space coordinate system includes a parallelepiped obtained by converting the RGB color space to the YUV color space.
[0050] By implementing embodiments of this disclosure, the first coordinates that can be directly input into the YUV lookup table can be obtained by mapping the coordinates in the absolute coordinate system of the YUV color space to the transformed coordinate system corresponding to the YUV lookup table, thereby improving the efficiency of the first color processing.
[0051] Optionally, sub-step S22 may specifically include sub-steps S221-S222:
[0052] Sub-step S221: Calculate the normalized coordinates of the second coordinate based on the parallelepiped;
[0053] Sub-step S222: Based on the maximum value of the normalized coordinates and the size of the YUV lookup table, calculate the first coordinate in the transformed coordinate system.
[0054] Normalization refers to converting coordinates of different sizes and ranges into standardized coordinate values. The normalized coordinate values range from 0 to 1, which facilitates image processing.
[0055] By normalizing the coordinates and adjusting them based on the size of the YUV lookup table, the influence of coordinates belonging to different scales can be avoided, allowing the obtained first coordinates to be directly applied to the corresponding YUV lookup table, thus improving the accuracy and efficiency of image processing.
[0056] Optionally, sub-step S221 may specifically include sub-steps S2211-S2213:
[0057] Sub-step S2211: Calculate the unit normal vector of the face associated with the coordinate axes of the transformed coordinate system in the parallelepiped;
[0058] Sub-step S2212: Based on the unit normal vector and the sides of the parallelepiped, calculate the shortest distance between the position indicated by the second coordinate and the first face, as well as the perpendicular distance between the first face and the second face. The second face is a face parallel to the first face.
[0059] Sub-step S2213: Calculate the normalized coordinates of the second coordinate in the YUV color space based on the shortest distance and the vertical distance.
[0060] In this embodiment of the disclosure, the faces associated with the coordinate axes of the transformed coordinate system refer to three faces of a parallelepiped, which are faces with two edges located on the coordinate axes of the transformed coordinate system. (Continue to refer to...) Figure 2 As shown, these three surfaces are the OAED surface, the ODFD surface, and the OBCA surface, respectively. The unit normal vectors of these surfaces can be calculated using the following formulas (1)-(3):
[0061] N OAED =norm[product(OA,OD)]; (1)
[0062] N ODFB =norm[product(OD,OB)]; (2)
[0063] N OBCA =norm[product(OB,OA)]; (3)
[0064] In the above formula, norm represents normalization calculation, product represents vector outer product, and OA, OB, and OD are vectors.
[0065] The second coordinate corresponds to the first color component. The second coordinate can be P(v, u, y), and the normalized coordinate of the second coordinate can be expressed as P. R (Nx, Ny, Nz).
[0066] Nx can be calculated using the following formulas (4)-(6):
[0067] Nx = L P-OAED / LOAED-BCGF (4)
[0068] L P-OAED =dot{N OAED ,OP}; (5)
[0069] L OAED-BCGF =dot{N OAED ,OB}; (6)
[0070] Among them, L OAED-BCGF L is the perpendicular distance between the OAED plane and the BCGF plane. P-OAED Let P be the shortest distance between point P and the OAED surface, dot represent the vector dot product, and OB and OP be vectors. Based on the above formula, the normalized coordinates P can be obtained. R Nx.
[0071] It is understandable that when calculating Nx, the first and second faces selected are two faces parallel to each other in the OB direction; when calculating Ny, two faces parallel to each other in the OD direction are selected, i.e. Figure 2 OBCA and DFGE; when calculating Nz, select two planes parallel to each other in the OA direction, i.e. Figure 2 OBFD and ACGE in the above. Based on the same method, Ny and Nz are calculated, and the normalized coordinates of the second coordinate can be obtained.
[0072] The first coordinate in the transformed coordinate system is calculated based on the maximum value of the normalized coordinates and the size of the YUV lookup table. Since the normalized coordinates are calculated in the transformed coordinate system, to obtain the first coordinates (xr, yr, zr) that can be used in the YUV lookup table, the normalized coordinates need to be processed according to the size of the YUV lookup table. For example, when the size of the YUV lookup table is 255×255×255, it can be calculated using the following formulas (7)-(9):
[0073] xr = Nx × 255; (7)
[0074] yr = Ny × 255; (8)
[0075] zr = Nz × 255; (9)
[0076] The normalized coordinates can be multiplied by the size of the YUV lookup table to obtain the index coordinates, or first coordinates, that can be directly used in the YUV lookup table.
[0077] S3. Based on the first coordinates, determine the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color.
[0078] In this embodiment, a YUV lookup table can correspond to a first color, and different YUV lookup tables for different first colors store different color component data. The YUV lookup table records several sets of color components, each set consisting of Y, U, and V color components. Each set of color components is located at a different position in the YUV lookup table, and these positions can be represented by coordinates. When the first coordinate is input into the YUV lookup table, and the values of the first coordinate in the Y, U, and V directions are all integers, the target color component at the corresponding position can be directly found based on the first coordinate; this is the second color component.
[0079] Optionally, step S3 may specifically include sub-steps S31-S32:
[0080] Sub-step S31: If the first coordinate is an integer point, then based on the first coordinate, determine the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color; or
[0081] Sub-step S32: If the first coordinate is not an integer point, then the color component of the vertex closest to the position indicated by the first coordinate is weighted and averaged to obtain the second color component; the color component of the closest vertex is obtained by looking up the coordinates of the closest vertex in the preset YUV lookup table.
[0082] It is understandable that each color component is located at a different position in the YUV lookup table, and these different positions can be represented by coordinates. However, when the values of the first coordinate in the Y, U, and V directions are not all integers, the corresponding position in the YUV lookup table cannot be found accurately.
[0083] A YUV lookup table corresponds to a parallelepiped. Based on the positions corresponding to the color component data stored in the YUV lookup table, a grid can be formed within the parallelepiped. Each grid consists of eight vertices. The position indicated by the first coordinate may be located inside the grid consisting of eight vertices. For example, if the first coordinate A is (0.5, 0.5, 0.5), the position indicated by the first coordinate A is located in the grid consisting of vertices (0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0), (0, 1, 1), (0, 1, 1), (1, 0, 1), and (1, 1, 1). The first coordinate B can be (1, 0.5, 1), in which case the position indicated by the first coordinate B is located at the edge of the grid. However, it is still possible to obtain the eight vertices closest to the position indicated by the first coordinate B. This embodiment of the present disclosure does not limit the specific position of the first coordinate when it is not an integer point.
[0084] Based on the actual first coordinates, the eight vertices closest to the first coordinates are determined. The coordinates of these eight vertices are used as index coordinates in the YUB lookup table to obtain eight sets of YUV color components. A weighted average of these eight sets of YUV color components is then performed to obtain the second color component. Alternatively, the Y color component can be extracted from the eight sets of YUV color components, multiplied by different weights, summed, and then divided by eight to obtain the Y color component in the second color component. The U and V color components are obtained using the same calculation method. The weights can be determined based on the distance between the first coordinates and each vertex. The greater the distance between the first coordinates and each vertex, the smaller the weight coefficient is used when calculating the weight of the color component based on that vertex; the closer the first coordinates are to each vertex, the larger the weight coefficient is used. This disclosure does not limit how the weight coefficients for different vertices are determined.
[0085] Before determining the second color component corresponding to the pixel point based on the first coordinates and in the YUV lookup table corresponding to the first color, an RGB lookup table corresponding to the first color can be obtained, and the RGB lookup table can be converted to obtain the YUV lookup table to be used.
[0086] Most current lookup tables are RGB lookup tables, which use three 1DLUTs (R, G, B) to form a 3DLUT. Inputting the RGB color values involves mapping them to the three lookup tables of the 3DLUT to obtain the converted color. However, due to the advantages of the YUV color encoding method, mobile terminals such as smartphones use the YUV color space to encode image data during photography and video recording. Therefore, continuing to use RGB lookup tables would require YUV to RGB format conversion and then RGB back to YUV format conversion during the first color processing step, resulting in redundancy in memory usage and performance overhead. This is especially true when there are multiple color mapping operations in the path, where computational power consumption increases exponentially. Therefore, it is necessary to convert the RGB lookup table to a YUV lookup table.
[0087] For example, if the image is a uint8 (8-bit unsigned integer) data type with dimensions W×H, then the temporary memory usage for the two RGB images before and after a 3DLut lookup is 2×W×H×channel (Byte), where W is the width, H is the height, and channel is the number of image channels (3 for RGB). Furthermore, the 3DLut lookup requires two color space conversions for each pixel in the image: from YUV to RGB and from RGB to YUV, resulting in significant computational overhead.
[0088] In this embodiment, by converting the RGB lookup table to a YUV lookup table, the first coordinates of the YUV color components can be directly input into the YUV lookup table to obtain the color components required for the first color, thus improving image processing efficiency in the application of the first color. Furthermore, since the input is directly using YUV coordinates, and the input is also directly the YUV color components, no format conversion is required, reducing computational performance consumption and computational pressure.
[0089] A YUV lookup table stores YUV color components at several different positions, and an RGB lookup table stores RGB color components at several different positions. When converting between RGB lookup tables, the following steps can be taken:
[0090] Based on the coordinates in the RGB color space coordinate system and the preset conversion formula, obtain the coordinates in the YUV color space coordinate system.
[0091] Based on the color components in the RGB lookup table and the preset conversion formula, obtain the color components in the YUV lookup table;
[0092] The converted YUV lookup table is obtained based on the coordinates in the YUV color space coordinate system and the color components in the YUV lookup table.
[0093] In this embodiment of the disclosure, the RGB lookup table stores several different locations, which are located in the coordinate system of the RGB color space. Therefore, it is necessary to map the coordinates of these locations to the YUV color space coordinate system. Furthermore, it is necessary to convert the RGB color components of the different locations stored in the RGB lookup table.
[0094] It's important to understand that different positions in the RGB lookup table can be understood as index coordinates. These index coordinates correspond to a set of RGB color components as input, that is, the color components of a pixel. For example, if the color components of pixel A are (r, g, b), then the index coordinates input into the RGB lookup table are (r, g, b). After inputting these index coordinates, the color component at the position indicated by the index coordinates (r', g', b') can be found.
[0095] The conversion process can be as follows: multiply each color component in the RGB lookup table by a first set of preset parameters and add them together to obtain the first component Y of the YUV lookup table; multiply each color component in the RGB lookup table by a second set of preset parameters and add them together with a preset offset parameter to obtain the second component U of the YUV lookup table; multiply each color component in the RGB lookup table by a third set of preset parameters and add them together with a preset offset parameter to obtain the third component V of the YUV lookup table; and obtain the color components in the YUV lookup table based on the first component, the second component, and the third component.
[0096] The process involves several steps: First, the first component Y of the YUV lookup table is obtained by multiplying each color component in the RGB lookup table by a first set of preset parameters and then summing the results. The first component Y is obtained by multiplying each RGB color component at a given position in the RGB lookup table by its corresponding parameter in the same set of preset parameters, and then summing the results of these multiplications. Second, the second component U of the YUV lookup table is obtained by multiplying each color component in the RGB lookup table by a second set of preset parameters, which also includes three parameters corresponding to the R, G, and B color components. The third component U is obtained by multiplying each color component by its corresponding parameter and then summing the results of these multiplications with a preset offset parameter. Finally, the third component V of the YUV lookup table is obtained by multiplying each color component in the third set of preset parameters by its corresponding parameter and then summing the results of these multiplications with a preset offset parameter. The above process can be performed by calculating the Y, U, and V color components of a set of color components at a position in the RGB lookup table. In other words, a set of color components at a position in the RGB lookup table is used to convert and obtain a set of color components at a position in the YUV lookup table.
[0097] It should be noted that the preset parameter values in the first, second, and third groups can be different, and can be positive or negative. Additionally, when the U and V components have a negative value range, a preset offset parameter is added when calculating the UV components to adjust the UV component value range to positive.
[0098] For example, the following parameters can be used to perform the conversion using formulas (10)-(12):
[0099] Y=0.299×R+0.587×G+0.114×B; (10)
[0100] U=-0.1687×R-0.3313×G+0.5×B+128; (11)
[0101] V=0.5×R-0.4187×G-0.0813×B+128; (12)
[0102] In this embodiment, 0.299, 0.587, and 0.114 are the first set of preset parameters. A set of three RGB color components at a position in the RGB lookup table is input into formula 1 to obtain the second component Y at a position in the YUV lookup table. -0.1687, -0.3313, and 0.5 are the second set of preset parameters, and 128 is the preset offset parameter. A set of the same RGB color components at the same position in the RGB lookup table is input into formula 2 to obtain the second component U at the same position in the YUV lookup table. 0.5, -0.4187, and -0.0813 are the third set of preset parameters. A set of the same RGB color components at the same position in the RGB lookup table is input into formula 3 to obtain the third component at the same position in the YUV lookup table. This embodiment does not limit the content of the preset parameters in the first, second, and third sets, nor the preset offset parameter.
[0103] Convert all index coordinates corresponding to their positions in the RGB lookup table to their corresponding index coordinates in the YUV lookup table using the formula described above. Similarly, convert the RGB color components corresponding to all index coordinates in the RGB lookup table to YUV color components using the same formula. Based on the coordinates in the YUV color space coordinate system and the corresponding color components in the YUV lookup table, obtain the converted YUV lookup table.
[0104] S4. Based on the second color component, adjust the first color component of the pixels in the YUV image to obtain a YUV image including the first color.
[0105] In the embodiments of this disclosure, the adjustment method for the first color component of a pixel in a YUV image based on the second color component can be varied. It can be replacing the first color component of the pixel with the second color component; it can be adding the second color component to the first color component of the pixel; or it can be subtracting the second color component from the first color component of the pixel. This disclosure does not limit how the first color component of a pixel in a YUV image is adjusted based on the second color component.
[0106] For example, if the first color component of pixel A is (10, 10, 10), and the second color component found in the YUV lookup table is (20, 20, 20), then after adjusting the first color component of the pixel in the YUV image based on the second color component, the first color component will be (20, 20, 20).
[0107] In this embodiment, by determining the first coordinates corresponding to the first color component of a pixel in the YUV color space coordinate system, and then determining the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinates, the first color component is adjusted using the second color component to complete the image color processing. This ensures successful color application without requiring the use of the RGB lookup table; instead, the color components are adjusted directly based on the YUV lookup table. This eliminates the need for two color space conversions, ultimately reducing the computational burden of data processing, lowering memory usage, and improving color processing efficiency.
[0108] Based on the above, such as Figure 3 As shown, the solution of this application mainly includes two parts. The first part is to convert the RGB lookup table into a YUV lookup table. The second part is to directly input the second coordinates corresponding to the first color component of the pixel in the YUV image into the YUV lookup table, and use the second coordinates as index coordinates to locate in the YUV lookup table in order to find the second color component.
[0109] The image processing method provided in this application embodiment can be executed by an image processing entity. Device In this application embodiment, image processing is used. Device Taking the execution of an image processing method as an example, the image processing apparatus provided in the embodiments of this application will be described. Figure 4 As shown, the image processing apparatus 40 includes:
[0110] The first color component module 401 is used to obtain the first color component of the pixel in the YUV image;
[0111] The first coordinate module 402 is used to determine the first coordinate corresponding to the first color component in the YUV color space coordinate system; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image.
[0112] The second color component module 403 is used to determine the second color component corresponding to the pixel in a YUV lookup table corresponding to the first color based on the first coordinates; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color.
[0113] Color component adjustment module 404 is used to adjust the first color component of the pixels in the YUV image based on the second color component to obtain a YUV image including the first color.
[0114] Optionally, the device further includes:
[0115] The lookup table conversion module is used to obtain an RGB lookup table corresponding to the first color and convert the RGB table to obtain a YUV lookup table before determining the second color component corresponding to the pixel point in the YUV lookup table corresponding to the first color based on the first coordinate.
[0116] Optionally, the RGB lookup table records the correspondence between coordinates and color components in the RGB color space coordinate system; the lookup table conversion module includes:
[0117] The coordinate transformation submodule is used to obtain the coordinates in the YUV color space coordinate system based on the coordinates in the RGB color space coordinate system and the preset transformation formula;
[0118] The component conversion submodule is used to obtain the color components in the YUV lookup table based on the color components in the RGB lookup table and the preset conversion formula.
[0119] The coordinate component submodule is used to obtain the converted YUV lookup table based on the coordinates in the YUV color space coordinate system and the color components in the YUV lookup table.
[0120] Optionally, the lookup table conversion module includes:
[0121] The first component submodule is used to multiply each color component in the RGB lookup table by a first set of preset parameters and then add them together to obtain the first component of the YUV lookup table.
[0122] The first component submodule multiplies each color component in the RGB lookup table by a second set of preset parameters and adds the result to a preset offset parameter to obtain the second component of the YUV lookup table.
[0123] The first component submodule multiplies each color component in the RGB lookup table by a third set of preset parameters and adds the result to the preset offset parameters to obtain the third component of the YUV lookup table.
[0124] The component determination submodule is used to obtain the color components in the YUV lookup table based on the first component, the second component, and the third component.
[0125] Optionally, the first coordinate module includes:
[0126] The second coordinate submodule is used to determine the second coordinates in the YUV color space coordinate system based on the first color component; the YUV color space coordinate system includes a transformation coordinate system, which is obtained by mapping the RGB color space to the YUV color space;
[0127] The coordinate mapping submodule maps the second coordinates to the transformed coordinate system to obtain the first coordinates;
[0128] Optionally, the device further includes:
[0129] A color space conversion module is used to convert the RGB color space to the YUV color space to obtain a parallelepiped located in the YUV color space.
[0130] The coordinate system transformation module is used to construct the coordinate system based on the three edges of the parallelepiped that have a common starting point; the common starting point is an origin of the RGB color space mapped to a corresponding point in the YUV color space.
[0131] Optionally, the coordinate mapping submodule includes:
[0132] The normalization calculation unit is used to calculate the normalized coordinates of the second coordinate based on the parallelepiped.
[0133] The lookup table size unit is used to calculate the first coordinate in the transformed coordinate system based on the maximum value of the normalized coordinates and the size of the YUV lookup table.
[0134] Optionally, the normalization calculation unit includes:
[0135] A unit normal vector sub-unit is used to calculate the unit normal vector of the face associated with the coordinate axes of the transformed coordinate system in the parallelepiped.
[0136] The distance calculation subunit is used to calculate the shortest distance between the position indicated by the second coordinate and the first face, and the perpendicular distance between the first face and the second face, based on the unit normal vector and the sides of the parallelepiped, wherein the second face is a face parallel to the first face;
[0137] The normalized coordinate subunit is used to calculate the normalized coordinates of the second coordinate in the YUV color space based on the shortest distance and the vertical distance.
[0138] Optionally, the second color component module includes:
[0139] The integer point submodule is used to determine the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinate when the first coordinate is an integer point.
[0140] The non-integer point submodule is used to perform a weighted average of the color components of the vertex closest to the position indicated by the first coordinate when the first coordinate is not an integer point to obtain a second color component; the color component of the closest vertex is obtained by looking up the coordinates of the closest vertex in the preset YUV lookup table.
[0141] Optionally, the color component adjustment module is used to replace the first color component of the pixels in the YUV image with the second color component.
[0142] In this embodiment, by determining the first coordinates corresponding to the first color component of a pixel in the YUV color space coordinate system, and then determining the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinates, the first color component is adjusted using the second color component to complete the image color processing. This ensures successful color application without requiring the use of the RGB lookup table; instead, the color components are adjusted directly based on the YUV lookup table. This eliminates the need for two color space conversions, ultimately reducing the computational burden of data processing, lowering memory usage, and improving the efficiency of the first color processing.
[0143] 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.
[0144] The image processing device in this application embodiment can be a device with an operating system. The operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system.
[0145] The image processing apparatus provided in this application embodiment can achieve... Figure 1 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0146] Optionally, such as Figure 5 As shown, this application embodiment also provides an electronic device 500, including a processor 501 and a memory 502. The memory 502 stores a program or instructions that can run on the processor 501. When the program or instructions are executed by the processor 501, 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.
[0147] 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.
[0148] Figure 6 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0149] The electronic device 1000 includes, but is not limited to, components such as: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, and processor 1010.
[0150] Those skilled in the art will understand that the electronic device 1000 may also include a power supply (such as a battery) for supplying power to various components. The power supply can be logically connected to the processor 1010 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. 5 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.
[0151] The processor 1010 is used to obtain the first color component of the pixel in the YUV image;
[0152] In the YUV color space coordinate system, a first coordinate corresponding to the first color component is determined; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image.
[0153] Based on the first coordinates, the second color component corresponding to the pixel is determined in the YUV lookup table corresponding to the first color; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color.
[0154] Based on the second color component, the first color component of the pixels in the YUV image is adjusted to obtain a YUV image that includes the first color.
[0155] Optionally, the processor 1010 is also used for:
[0156] Before determining the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinates, the RGB lookup table corresponding to the first color is obtained, and the RGB lookup table is converted to obtain the YUV lookup table.
[0157] Optionally, the processor 1010 is also used for:
[0158] Based on the coordinates in the RGB color space coordinate system and the preset conversion formula, obtain the coordinates in the YUV color space coordinate system;
[0159] Based on the color components in the RGB lookup table and the preset conversion formula, obtain the color components in the YUV lookup table;
[0160] The converted YUV lookup table is obtained based on the coordinates in the YUV color space coordinate system and the color components in the YUV lookup table.
[0161] In this embodiment, by converting the RGB lookup table to a YUV lookup table, the first coordinates of the YUV color components can be directly input into the YUV lookup table to obtain the color components required for the first color, thus improving image processing efficiency in the application of the first color. Furthermore, since the input is directly using YUV coordinates, and the input is also directly the YUV color components, no format conversion is required, reducing computational performance consumption and computational pressure.
[0162] Optionally, the processor 1010 is also used for:
[0163] The first component of the YUV lookup table is obtained by multiplying each color component in the RGB lookup table by the first set of preset parameters and then adding them together.
[0164] The second component of the YUV lookup table is obtained by multiplying each color component in the RGB lookup table by the second set of preset parameters and then adding the result to the preset offset parameters.
[0165] The third component of the YUV lookup table is obtained by multiplying each color component in the RGB lookup table by the third set of preset parameters and then adding the result to the preset offset parameters.
[0166] The color components in the YUV lookup table are obtained based on the first component, the second component, and the third component.
[0167] Optionally, the processor 1010 is also used for:
[0168] Based on the first color component, a second coordinate is determined in the YUV color space coordinate system; the YUV color space coordinate system includes a transformation coordinate system, which is obtained by mapping the RGB color space to the YUV color space.
[0169] The second coordinate is mapped to the transformed coordinate system to obtain the first coordinate.
[0170] By implementing embodiments of this disclosure, the first coordinates that can be directly input into the YUV lookup table can be obtained by mapping the coordinates in the absolute coordinate system of the YUV color space to the transformed coordinate system corresponding to the YUV lookup table, thereby improving the efficiency of the first color processing.
[0171] Optionally, the processor 1010 is also used for:
[0172] Convert the RGB color space to the YUV color space to obtain a parallelepiped located in the YUV color space;
[0173] The transformation coordinate system is constructed based on the three edges of the parallelepiped that share a common starting point; the common starting point is an origin of the RGB color space mapped to a corresponding point in the YUV color space.
[0174] Optionally, the processor 1010 is also used for:
[0175] Based on the parallelepiped, calculate the normalized coordinates of the second coordinate.
[0176] The first coordinate in the transformed coordinate system is calculated based on the maximum value of the normalized coordinates and the size of the YUV lookup table.
[0177] By normalizing the coordinates and adjusting them based on the size of the YUV lookup table, the influence of coordinates belonging to different scales can be avoided, allowing the obtained first coordinates to be directly applied to the corresponding YUV lookup table, thus improving the accuracy and efficiency of image processing.
[0178] Optionally, the processor 1010 is also used for:
[0179] Calculate the unit normal vector of the face associated with the coordinate axes of the transformed coordinate system in the parallelepiped;
[0180] Based on the unit normal vector and the sides of the parallelepiped, calculate the shortest distance between the position indicated by the second coordinate and the first face, as well as the perpendicular distance between the first face and the second face, where the second face is a face parallel to the first face;
[0181] Based on the shortest distance and the vertical distance, the normalized coordinates of the second coordinate in the YUV color space are calculated.
[0182] Optionally, the processor 1010 is also used for:
[0183] If the first coordinate is an integer point, then based on the first coordinate, the second color component corresponding to the pixel is determined in the YUV lookup table corresponding to the first color; or
[0184] If the first coordinate is not an integer point, then the color component of the vertex closest to the position indicated by the first coordinate is weighted and averaged to obtain the second color component; the color component of the closest vertex is obtained by looking up the coordinates of the closest vertex in the preset YUV lookup table.
[0185] Optionally, the processor 1010 is also used for:
[0186] The first color component of the pixels in the YUV image is replaced with the second color component.
[0187] It should be understood that, in this embodiment, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042. The GPU 10041 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 1006 may include a display panel 10061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include a touch detection device and a touch controller. Other input devices 10072 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.
[0188] The memory 1009 can be used to store software programs and various data. The memory 1009 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 1009 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 linked dynamic random access memory (Synchlink DRAM, 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.
[0189] The processor 1010 may include one or more processing units; optionally, the processor 1010 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 the processor 1010.
[0190] 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-described image processing method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0191] 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.
[0192] 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-described image processing method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0193] 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.
[0194] This application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the above-described image processing method embodiments, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0195] 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.
[0196] 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.
[0197] 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: Obtain the first color component of a pixel in a YUV image; In the YUV color space coordinate system, a first coordinate corresponding to the first color component is determined; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image. Based on the first coordinates, the second color component corresponding to the pixel is determined in the YUV lookup table corresponding to the first color; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color. Based on the second color component, the first color component of the pixels in the YUV image is adjusted to obtain a YUV image including the first color; The step of determining the first coordinate corresponding to the first color component in the YUV color space coordinate system includes: Based on the first color component, a second coordinate is determined in the YUV color space coordinate system; the YUV color space coordinate system includes a transformation coordinate system, which is obtained by mapping the RGB color space to the YUV color space. Map the second coordinates to the transformed coordinate system to obtain the first coordinates; The method further includes, before determining the second color component corresponding to the pixel in the YUV lookup table corresponding to the first color based on the first coordinates: Obtain the RGB lookup table corresponding to the first color, and convert the RGB lookup table to obtain the YUV lookup table.
2. The method according to claim 1, characterized in that, The method further includes: Convert the RGB color space to the YUV color space to obtain a parallelepiped located in the YUV color space; The transformation coordinate system is constructed based on the three edges of the parallelepiped that share a common starting point; the common starting point is an origin of the RGB color space mapped to a corresponding point in the YUV color space.
3. The method according to claim 2, characterized in that, The step of mapping the second coordinates to the transformed coordinate system to obtain the first coordinates includes: Based on the parallelepiped, calculate the normalized coordinates of the second coordinate. The first coordinate in the transformed coordinate system is calculated based on the maximum value of the normalized coordinates and the size of the YUV lookup table.
4. The method according to claim 3, characterized in that, The step of calculating the normalized coordinates of the second coordinate based on the parallelepiped includes: Calculate the unit normal vector of the face associated with the coordinate axes of the transformed coordinate system in the parallelepiped; Based on the unit normal vector and the sides of the parallelepiped, calculate the shortest distance between the position indicated by the second coordinate and the first face, as well as the perpendicular distance between the first face and the second face, where the second face is a face parallel to the first face; Based on the shortest distance and the vertical distance, the normalized coordinates of the second coordinate in the YUV color space are calculated.
5. An image processing apparatus, characterized in that, The device includes: The first color component module is used to obtain the first color component of the pixel in the YUV image; The first coordinate module is used to determine the first coordinate corresponding to the first color component in the YUV color space coordinate system; the YUV color space coordinate system is a coordinate system constructed using the coordinate axes corresponding to each color component of the YUV image. The second color component module is used to determine the second color component corresponding to the pixel in a YUV lookup table corresponding to the first color based on the first coordinates; the YUV lookup table includes the correspondence between the coordinates in the YUV color space coordinate system and the color components associated with the first color. The color component adjustment module is used to adjust the first color component of the pixels in the YUV image based on the second color component, so as to obtain a YUV image including the first color. The first coordinate module includes: The second coordinate submodule is used to determine the second coordinates in the YUV color space coordinate system based on the first color component; the YUV color space coordinate system includes a transformation coordinate system, which is obtained by mapping the RGB color space to the YUV color space; The coordinate mapping submodule is used to map the second coordinates to the transformed coordinate system to obtain the first coordinates; The device is also used for: Obtain the RGB lookup table corresponding to the first color, and convert the RGB lookup table to obtain the YUV lookup table.
6. The apparatus according to claim 5, characterized in that, The device further includes: A color space conversion module is used to convert the RGB color space to the YUV color space to obtain a parallelepiped located in the YUV color space. The coordinate system transformation module is used to construct the coordinate system based on the three edges of the parallelepiped that have a common starting point; the common starting point is an origin of the RGB color space mapped to a corresponding point in the YUV color space.
7. The apparatus according to claim 6, characterized in that, The coordinate mapping submodule includes: The normalization calculation unit is used to calculate the normalized coordinates of the second coordinate based on the parallelepiped. The lookup table size unit is used to calculate the first coordinate in the transformed coordinate system based on the maximum value of the normalized coordinates and the size of the YUV lookup table.
8. The apparatus according to claim 7, characterized in that, The normalization calculation unit includes: A unit normal vector sub-unit is used to calculate the unit normal vector of the face associated with the coordinate axes of the transformed coordinate system in the parallelepiped. The distance calculation subunit is used to calculate the shortest distance between the position indicated by the second coordinate and the first face, and the perpendicular distance between the first face and the second face, based on the unit normal vector and the sides of the parallelepiped, wherein the second face is a face parallel to the first face; The normalized coordinate subunit is used to calculate the normalized coordinates of the second coordinate in the YUV color space based on the shortest distance and the vertical distance.
Citation Information
Patent Citations
Color correction method, field programmable gate array, chip and display device
CN115486060A