Image processing method and device
By calculating the color difference value ratio of the initial and target color information in the image processing request and adjusting the color of the area to be processed in the image, the problems of inaccurate color distinction and unnatural replacement in the prior art are solved, and a more accurate and natural color replacement effect is achieved.
Patent Information
- Application Number
- CN202111544614.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2041-12-16
AI Technical Summary
In the process of image cutout and color replacement, the color cannot be accurately distinguished, resulting in inaccurate selection of areas and unnatural color replacement.
By receiving the image processing request for the image to be processed, the initial color information and target color information are determined, the pixel color difference value of each target pixel point in the to be processed area and the initial color information is calculated, and the color information is adjusted according to the color difference value ratio to achieve more accurate and natural color replacement.
It realizes more accurately selecting the processing area that meets the user's expectations, and color replacement is completed by adjusting the ratio of pixel color difference value to color difference value, so that the initial color and the target color can be accurately replaced when the difference is not obvious, achieving a better customized effect.
Smart Images

Figure CN114219733B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method. The present application also relates to an image processing device, a computing device, and a computer-readable storage medium. Background Art
[0002] With the development of video-related technologies, there are more and more ways to process images and videos. For example, image clipping, color replacement of parts of an image, etc. In the clipping process, it is necessary to first select parts of the image and then perform subsequent processing on the parts. At present, most of them use RGB color space for clipping, but because the RGB color space cannot reflect the color perception ability of the human eye, the selected area is inaccurate and does not meet the user's expectations. In addition, in the process of replacing colors, if the colors in the image are directly replaced, the content will be abrupt and unrealistic. Therefore, it is necessary to select appropriate colors to replace the colors of parts of the original image to ensure that the colors in the replaced image change evenly.
[0003] Therefore, how to accurately select the area that meets the requirements and replace the color of the selected area naturally is a problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, an embodiment of the present application provides an image processing method. The present application also relates to an image processing device, a computing device, and a computer-readable storage medium to solve the problems of inaccurate image color distinction and unnatural color replacement in the prior art.
[0005] According to a first aspect of an embodiment of the present application, there is provided an image processing method, comprising:
[0006] receiving an image processing request for an image to be processed, and determining initial color information and target color information according to the image processing request;
[0007] Determine a to-be-processed area in the to-be-processed image according to the initial color information;
[0008] Calculating the pixel color difference between the color information of each target pixel in the to-be-processed area and the initial color information, and determining the color difference value ratio according to the initial color information and the target color information;
[0009] The color information of each target pixel in the to-be-processed area is adjusted according to the pixel color difference value of each target pixel and the color difference value ratio.
[0010] According to a second aspect of an embodiment of the present application, there is provided an image processing apparatus, including:
[0011] A receiving module is configured to receive an image processing request of an image to be processed, and determine initial color information and target color information according to the image processing request;
[0012] A determination module, configured to determine a to-be-processed area in the to-be-processed image according to the initial color information;
[0013] A calculation module is configured to calculate a pixel color difference value between the color information of each target pixel point in the to-be-processed area and the initial color information, and determine a color difference value ratio according to the initial color information and the target color information;
[0014] The adjustment module is configured to adjust the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio.
[0015] According to a third aspect of an embodiment of the present application, a computing device is provided, comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein the processor implements the steps of the image processing method when executing the computer instructions.
[0016] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, and when the computer instructions are executed by a processor, the steps of the image processing method are implemented.
[0017] The image processing method provided by the present application includes: receiving an image processing request for an image to be processed, determining initial color information and target color information according to the image processing request; determining a to-be-processed area in the image to be processed according to the initial color information; calculating a pixel color difference value between the color information of each target pixel point in the to-be-processed area and the initial color information, and determining a color difference value ratio according to the initial color information and the target color information; and adjusting the color information of each target pixel point in the to-be-processed area according to the pixel color difference value of each target pixel point and the color difference value ratio.
[0018] An embodiment of the present application realizes the selection of the area to be processed by the pixel color difference value of the color information of each target pixel and the initial color information, which can better reflect the human eye's recognition of color, thereby selecting a processing area that better meets the user's expectations, and adjusting the color information of the processing area by the pixel color difference value and the color difference value ratio, so that the initial color information and the target color information can be accurately replaced when the difference is not obvious. The image processing method provided by the present application can perform more natural color replacement processing on the image, achieving a better customized effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1is a flow chart of an image processing method provided by an embodiment of the present application;
[0020] Figure 2 is a comparison chart of the processing results of the image processing method provided by an embodiment of the present application and the existing method;
[0021] Figure 3 is a schematic diagram of a region to be processed through connected domain detection in one embodiment of the present application;
[0022] Figure 4 is a processing flow chart of an image processing method for replacing sky color provided by an embodiment of the present application;
[0023] Figure 5 is a structural schematic diagram of an image processing device provided by an embodiment of the present application;
[0024] Figure 6 It is a structural block diagram of a computing device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0025] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0026] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms of "a", "said" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0027] It should be understood that, although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0028] First, the terms involved in one or more embodiments of the present application are explained.
[0029] RGB color space: RGB color space is based on the three basic colors of R (Red), G (Green), and B (Blue), which are superimposed to varying degrees to produce rich and wide colors, so it is commonly known as the three-primary color mode. Most televisions, monitors, and projectors generate different colors by mixing red, green, and blue light of varying intensities. This is the additive color method of the RGB three primary colors.
[0030] HSV color space: HSV (Hue, Saturation, Value) is a color space created by AR Smith in 1978 based on the intuitive characteristics of color, also known as the Hexcone Model. The color parameters in this model are: hue (H), saturation (S), and value (V).
[0031] Cutting out: Cutting out is one of the most common operations in image processing. It is to separate a part of a picture or image from the original picture or image into a separate layer. Its main function is to prepare for later synthesis.
[0032] Currently, if a partial area of an image needs to be adjusted, it is first necessary to cut out the partial area in the image, and then perform subsequent adjustment operations on the partial area after the partial area is selected.
[0033] The current mainstream cutout techniques are divided into the following three types:
[0034] 1. Cutting technology based on prior information: This method requires artificially setting the foreground and background areas of an image before cutting out. In practical applications, the labor cost is very high. For example, when cutting out a video, it is necessary to distinguish the foreground and background of each frame of the video separately before cutting out. Therefore, this cutting technology is not suitable for scenes that process a large number of images.
[0035] 2. Cutout technology based on deep learning: This method uses a pre-learned method to calculate the foreground and background, and segment the foreground and background to achieve the effect of cutout. However, the disadvantage of this method is that it first requires a large amount of data learning, and after the learning is completed, it can only segment objects of a specific category. For example, if the learned data is to segment people from images, it can only process related images. In addition, the requirements for equipment performance are also very high, and the cost of cutout is high.
[0036] 3. Cutout technology based on color space: This method is one of the most widely used cutout technologies. The most common application scenario is green screen cutout when shooting movies. The specific method of this method is to initially select a specified color, and then separate the parts with similar colors from other parts by comparing the difference between each pixel in the picture and the specified color. This method does not require a lot of manual operation, and has good performance. It can complete the cutout task quickly, and there is no problem of only being able to recognize specific objects. However, this method has high requirements for how to judge whether the colors are similar. If there is no good judgment standard, a good cutout effect cannot be obtained.
[0037] The original color space-based cutout technology selected the color Euclidean distance in the RGB space as the judgment standard, and its distance color difference formula is shown in Formula 1:
[0038]
[0039] Among them, D(X,Y) is the distance between color X and color Y in the RGB color space, that is, the color difference between the two colors, and R, G, and B represent the RGB three-channel components of the color respectively. By comparing the color difference between the two colors with the preset color difference threshold, it is possible to distinguish whether the colors are close, and the similar area can be increased or decreased by modifying the color difference threshold. However, the RGB color space in the above method cannot well reflect the human eye's ability to distinguish colors. Therefore, the distance color difference calculation based on HSV color space, HSL color space, Lab color space, etc. is subsequently used to simulate the human eye's perception of color.
[0040] In the HSV color space, the color difference calculated by the color Euclidean distance formula can better reflect the color perception ability of the human eye, but the traditional color Euclidean distance cannot well reflect the distance in the HSV space. Because the HSV space is a cone, compared with the three independent components in the RGB color space, there are multiple components in the HSV color space. In such a color space, choosing the color Euclidean distance to judge the similarity of colors does not conform to the space definition, and the color distinction in the low saturation area in the HSV space is not obvious, which may cause the problem of close distance between black and white.
[0041] In the Lab color space, since brightness and color are separated in the Lab color space, the L channel has no color, and the a channel and the b channel only have color. In contrast to the RGB color space, each channel contains both brightness and color, so colors can be better distinguished. In addition, since the Lab color space is a sphere, the above-mentioned problems in the HSV color space do not exist.
[0042] After cutting out the image, you can replace the color of the selected area. If you directly adjust the color in the selected area to the target color, it will inevitably cause abrupt and abnormal colors.
[0043] Based on this, in order to solve the above-mentioned problems such as the inability to accurately distinguish colors, the distinguished colors not conforming to the visual characteristics of the human eye, and the unnatural replacement colors, an image processing method is provided in the present application. The present application also involves an image processing device, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.
[0044] Figure 1 A flowchart of an image processing method provided according to an embodiment of the present application is shown, which specifically includes the following steps:
[0045] Step 102: receiving an image processing request for an image to be processed, and determining initial color information and target color information according to the image processing request.
[0046] The image processing request may be understood as a purpose request for processing an image issued by a user. For example, in a natural landscape image, the image processing request may be: changing the green color of leaves in the image to red. The initial color information may be understood as the original color in the image to be processed, for example, the green color of leaves in the image to be processed. The target color information may be understood as the color that the user wishes to replace, for example, red.
[0047] In practical applications, since most current devices use the RGB color standard to display colors, the initial color information and the target color information can be specific values based on the three channels of the RGB color space. For example, green: 55, 150, 60 (R, G, B); red: 255, 0, 0 (R, G, B). The expression of the initial color information and the target color information can be selected according to actual conditions, and this application does not impose specific restrictions on this, as long as a unique color can be expressed.
[0048] In a specific embodiment of the present application, a photo of a person is received as an image to be processed, and the image processing request of the photo is: change the black hair of the person to yellow hair. According to the image processing request, the color of the person's hair is absorbed in the image to be processed: black: 0, 0, 0. Since the specific value of yellow is not specified in the image processing request, a yellow color can be automatically selected: 200, 180, 70.
[0049] In another specific embodiment of the present application, a portrait photo of a person is received as an image to be processed, and the image processing request of the portrait photo is: replace the black color: 0, 0, 0 in the picture with yellow color: 200, 180, 70, then the initial color information is determined to be black: 0, 0, 0, and the target color information is determined to be yellow: 200, 180, 70.
[0050] Step 104: Determine the area to be processed in the image to be processed according to the initial color information.
[0051] The area to be processed can be understood as an area where the user wants to replace the color. For example, if the user wants to replace the green in the image with red, the area to be processed is all the green areas in the image.
[0052] In practical applications, the human eye does not distinguish colors very clearly. Therefore, the image to be processed may include multiple similar colors. In order to make the determined area to be processed more consistent with the human eye's perception of color, the color information, initial color information and target color information of the image can be converted based on the Lab space to meet the purpose of meeting the visual characteristics of the human eye. Therefore, it is necessary to convert the RGB color space into the Lab color space. Converting the color value in the RGB color space to the Lab space can be completed by step S1042:
[0053] S1042: Convert the RGB color space to the XYZ color space.
[0054] Among them, the XYZ color space is a color space composed of ideal three primary colors. Since the RGB color space cannot be directly converted to the Lab color space, it is chosen to convert the RGB space to the XYZ color space first, and then convert the XYZ color space to the Lab color space.
[0055] Specifically, the conversion matrix between the RGB color space and the XYZ color space is shown in Formula 2 and Formula 3:
[0056]
[0057]
[0058] Among them, x, y, z are the three stimulus values in the XYZ color space, r, g, b are the three stimulus values in the RGB color space, and the three stimulus values of any color P in the RGB color space are (R P , F P , B P ), the tristimulus value in the XYZ color space is (X P , Y P , Z P ).
[0059] The RGB color space can be converted into the XYZ color space through the above conversion matrix. After that, the XYZ color space needs to be converted into the Lab color space. Specifically, the conversion formulas of the XYZ color space and the Lab color space are shown in Formula 4 and Formula 5:
[0060]
[0061]
[0062]
[0063]
[0064] Among them, L * Represents the brightness of the color, a * represents the position between red / magenta and green, b * Represents the position between yellow and blue, X n , Y n , Z n The three color channels in the XYZ color space are converted into the three color values in the LAB color space, and the color values in the RGB color space can be converted into the Lab color space.
[0065] In a specific embodiment of the present application, following the above example, "0, 0, 0" and "200, 180, 70" in the RGN color space are converted into colors in the Lab color space, and the conversion results of the two colors are: 0, 0, 0 (L, a, b), 73.5, -1.9, 56.7 (L, a, b).
[0066] After conversion to the Lab color space, the area to be processed in the image can be determined based on the initial color information.
[0067] Specifically, determining the area to be processed in the image to be processed according to the initial color information includes:
[0068] Calculating an initial color difference value between the color information of each initial pixel in the image to be processed and the initial color information;
[0069] The to-be-processed area in the to-be-processed image is determined according to the initial color difference value of each initial pixel and a preset color difference value threshold.
[0070] The initial color difference value can be understood as the distance color difference value between the color of the pixel point in the image and the initial color. For example, the color of the pixel point is 42, 0, 0 (L, a, b); the initial color is 28, 23, 10 (L, a, b); the color difference value between the two is △E2000=21.9.
[0071] In practical applications, there are many ways to calculate color difference. The main color difference formulas are: FCM color difference formula, LABHNU color difference formula, CIE94 color difference formula, CIEDE2000 color difference formula, etc.
[0072] Preferably, the CIEDE2000 color difference formula is used in the present application to calculate the color difference. The CIEDE2000 color difference formula is shown in formula (6):
[0073]
[0074] Among them, ΔE 00 Indicates the color difference value, K L , K C , K H They are custom values. Parameter factor K L , K C , K H are correction factors related to usage conditions, which are factors that affect the perception of color difference. Under given standard gloss conditions, K L =K C =K H =1, when the condition is not met, the value is determined according to the industrial color difference evaluation conditions.
[0075] The remaining variables are calculated as follows:
[0076] Calculating L in CIELAB formula * 、a * , b * ,
[0077]
[0078] in, Indicates the chroma of a color.
[0079] Calculate L′, a′, b′, h ab '
[0080] L′=L *
[0081] a′=(1+G)×a *
[0082] b′=b *
[0083]
[0084] h ab ′=arcsin(b′ / a′)
[0085]
[0086] Where G represents the adjustment factor of the axis of the Lab color space, which is a function of chroma. To calculate C′ of two colors ab L' is the reflectance (brightness), a' and b' are the red and green components and the yellow and blue components after adjustment factor correction, h ab ′ indicates the relative relationship of different components.
[0087] Calculate ΔL and ΔC′ ab , ΔH′ ab .
[0088] Among them, ΔL represents the brightness difference, ΔC′ ab Indicates chroma difference, ΔH′ ab Indicates hue difference.
[0089] ΔL=L′ 1 -L′ 2
[0090] ΔC′ ab =C′ ab,1 -C′ ab,2
[0091]
[0092] The subscripts 1 and 2 respectively represent a standard color and a sample color in a pair of colors for calculating color difference.
[0093] Calculate S L , S C , S H , T and R T (By R C calculated).
[0094]
[0095]
[0096]
[0097]
[0098] R T = -sin(2Δθ)R C
[0099]
[0100]
[0101] Among them, S L , S C , S H It is called the weight function. T and R r is the artificially set regularization parameter, Δθ is the hue rotation angle, R C Repeat for color saturation changes.
[0102] The color difference value calculated through the above steps can well reflect the color recognition of the human eye.
[0103] In a specific embodiment of the present application, the above example is used to calculate the color difference between the color of each pixel in the image to be processed and black, the preset color difference value threshold is 10, and all pixels whose color difference values are less than the preset color difference value threshold are selected to determine the area to be processed in the image to be processed.
[0104] Specifically, determining the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold includes:
[0105] Determine the current initial pixel point;
[0106] Determine whether the initial color difference value of the current initial pixel exceeds a preset color difference value threshold;
[0107] If the color difference does not exceed the preset color difference value threshold, determining the current initial pixel point as the target pixel point;
[0108] The area to be processed is determined according to each target pixel.
[0109] Among them, the initial pixel point can be understood as a pixel point in the image to be processed, and the target pixel point can be understood as a pixel point in the area to be processed in the image to be processed; the preset color difference value threshold can be understood as a threshold of acceptable error set by the user. For example, the preset color difference value threshold is 20. When the color difference value between the color information of the initial pixel point and the initial color information is 10, the current initial pixel point is determined to be the target pixel point in the area to be processed.
[0110] In a specific embodiment of the present application, following the above example, an initial pixel point is selected in the image to be processed, and the color information of the pixel point is: 2, -3.8, 2.8 (L, a, b), and the initial color difference value is calculated to be △E2000=5.7. The preset color difference value threshold is 10, and the current initial pixel point can be determined as the target pixel point in the area to be processed. The same processing is performed on each target pixel point in the area to be processed, so that the target pixel point in the area to be processed can be selected.
[0111] By performing the same operation as above for each initial pixel in the image to be processed, all target pixels in the area to be processed can be selected, thus determining the area to be processed. Figure 2 , Figure 2 The image processing method provided by an embodiment of the present application is compared with the processing results of the existing method. In the original image, the black frame area is intended to be used as the area to be processed. After the area to be processed is calculated using the Euclidean distance color difference calculation formula, it can be seen that part of the exhibition stand under the vase is not selected; the method of the present application can better select the area to be processed to meet the user's expected effect.
[0112] In actual situations, through the above method, due to various factors, the target pixel may be missed or the initial pixel may be misjudged as the target pixel. Therefore, the area to be processed can be optimized to obtain a more accurate area to be processed.
[0113] Specifically, determining the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold includes:
[0114] Determine an initial area to be processed in the image to be processed according to an initial color difference value of each initial pixel and a preset color difference value threshold;
[0115] Optimization information for the initial area to be processed is obtained, and the initial area to be processed is optimized based on the optimization information to generate an area to be processed.
[0116] The initial area to be processed can be understood as the area determined by comparing with the preset color difference value threshold. The optimization information can be understood as various optimization methods, which can be the default optimization method set by the user in advance, or obtained from the image processing request; the optimization method can include but is not limited to connected domain detection, opening and closing operations, feathering, etc., and the selected area can be further accurately selected through the optimization method, so as to determine an area that better meets the user's expectations.
[0117] In practical applications, one or more optimization methods can be selected to optimize the initial area to be processed, and the optimization method can also be determined according to the needs of the user. This application does not make specific restrictions here, and the actual situation shall prevail. Preferably, the optimization method selected in this application is feathering and connected domain detection.
[0118] In a specific embodiment of the present application, the initial area to be processed is optimized by feathering, and the calculation formula of feathering is shown in formula (11):
[0119] color=smoothstep(tolerance*(1.0-softness), tolerance, dist) (Formula 11)
[0120] Among them, tolerance is the strength of the cutout, softness is the feathering strength, and dist is the initial color difference value of the current pixel. By optimizing the initial area to be processed by feathering, the effect of smoothing the boundary of the initial area to be processed can be achieved.
[0121] In practical applications, the initial area to be processed is optimized through connected domain detection: a target pixel point in the initial area to be processed is determined, and the color difference value of the target pixel point and the four pixels above, below, left and right of it are compared. If the color difference value is less than the preset connected color difference value threshold, it is considered to be the same area. When the color difference value of a certain point and the previous point is greater than the preset connected color difference value threshold, it is considered to be the boundary point of the area. Similarly, the entire connected area can be obtained.
[0122] In a specific embodiment of the present application, it is determined that the initial area to be processed includes the black hair area of the character and the black eye area of the task. By selecting a pixel point in the black hair, the entire black hair area can be determined, and the black eye area is excluded. Through the connected domain detection, the area that the user wants to be processed can be obtained, thereby improving the accuracy of the cutout.
[0123] See also Figure 3 , Figure 3 A schematic diagram of the area to be processed after connected domain detection in an embodiment of the present application is shown. If the water in the right cup is desired, the color of the water in the right cup is currently selected as a whole, and then the area with the same color in the entire image is selected. However, after connected domain detection, only the area of the water in the right cup can be selected.
[0124] Step 106: Calculate the pixel color difference between the color information of each target pixel in the area to be processed and the initial color information, and determine the color difference value ratio according to the initial color information and the target color information.
[0125] The pixel color difference value can be understood as the pixel color difference value between the color information of the target pixel in the area to be processed and the initial color information. In practical applications, when the color in the area to be processed is to be replaced after the area to be processed is determined, since the color information of each pixel in the area to be processed is different, it is necessary to determine the replacement color corresponding to each pixel. This can be determined by the pixel color difference value of each target pixel and the color difference value ratio.
[0126] Specifically, determining the color difference value ratio according to the initial color information and the target color information includes:
[0127] Calculate a mixed color difference value and a standard color difference value according to the initial color information and the target color information;
[0128] The color difference value ratio is determined according to the mixed color difference value and the standard color difference value.
[0129] The color difference value ratio can be understood as the ratio of the color difference values between the initial color information and the target color information calculated by two different calculation methods. The color difference value ratio can be used to better calculate the ratio between the color of the target pixel and the replacement color, thereby achieving a more accurate color replacement effect.
[0130] The mixed color difference value can be understood as the color difference value calculated by combining the traditional Euclidean distance color difference formula with the CIEDE2000 color difference formula. The standard color difference value can be understood as the color difference value calculated using CIEDE2000.
[0131] In practical applications, the color difference value ratio calculated by mixing the color difference value and the standard color difference value facilitates the subsequent more accurate calculation of the color change information of each target pixel, thereby enabling more accurate color replacement of each pixel.
[0132] In a specific embodiment of the present application, a mixed color difference value C1 and a standard color difference value C2 are calculated according to the initial color information A and the target color information B, and a color difference value ratio C1 / C2 is calculated according to the mixed color difference value C1 and the standard color difference value C2.
[0133] Specifically, calculating the mixed color difference value and the standard color difference value according to the initial color information and the target color information includes:
[0134] Calculate the mixed color difference value of the initial color information and the target color information by using the target color difference formula and the calibration color difference formula;
[0135] The standard color difference value between the initial color information and the target color information is calculated by a target color difference formula.
[0136] The target color difference formula can be understood as a formula for calculating the standard color difference value. In this application, the target color difference formula uses the CIEDE2000 color difference formula. The calibration color difference formula can be understood as a formula for calculating the mixed color difference value. In this application, the CIEDE2000 color difference formula is combined with the Euclidean distance color difference formula to generate the calibration color difference formula.
[0137] In practical applications, the calculation formula for the color difference correction formula can be shown as formula 12:
[0138]
[0139] Among them, Dis can be understood as the color difference value between the color information of the target pixel and the target color information, and the color change degree of the target pixel can be obtained according to the color difference value. CIEDE It can be understood as the color difference between the initial color information and the target color information calculated by the target color difference formula, D Eular It can be understood as the color difference value between the initial color information and the target color information calculated by the color difference calibration formula.
[0140] In a specific embodiment of the present application, a standard color difference value C1 between the initial color information A and the target color information B is calculated. If the calculated C1 is greater than 0.5, the mixed color difference value C2 calculated by the color difference calibration formula is the same as the standard color difference value C1.
[0141] In another specific embodiment of the present application, the standard color difference value C1 of the initial color information A and the target color information B is calculated. If the calculated C1 is less than 0.5, the mixed color difference value C2 calculated by the color difference calibration formula is different from the standard color difference value C1.
[0142] Step 108: adjusting the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio.
[0143] After the pixel color difference value and the color difference value ratio of each target pixel are calculated, the color information of each target pixel can be adjusted according to the pixel color difference value and the color difference value ratio of each target pixel.
[0144] Specifically, adjusting the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio includes:
[0145] Determine the current target pixel;
[0146] The color information of the current target pixel is adjusted according to the pixel color difference value of the current target pixel and the color difference value ratio.
[0147] In practical applications, there are many target pixels in the area to be processed. First, one of the target pixels is determined and the target pixel is adjusted, and the color replacement of the area to be processed is completed in this way.
[0148] In a specific embodiment of the present application, following the above example, when the standard color difference value C1 and the mixed color difference value C2 are the same, the color difference value ratio is 1, the pixel color difference value X of the target pixel is calculated by the standard calculation formula, and the color information of the current target pixel is adjusted according to the pixel color difference value X of the current target pixel.
[0149] In another specific embodiment of the present application, following the above example, when the standard color difference value A and the mixed color difference value B are different, the color difference value ratio is C1 / C2, the pixel color difference value X of the target pixel is calculated by the standard calculation formula, and the color information of the current target pixel is adjusted according to the pixel color difference value X of the current target pixel.
[0150] Specifically, adjusting the color information of the target pixel point according to the pixel color difference value of the target pixel point and the color difference value ratio includes:
[0151] Calculating the color change information of the target pixel point according to the pixel color difference value of the target pixel point and the color difference value ratio;
[0152] The color information of the target pixel is adjusted according to the color change information of the target pixel.
[0153] The color change information can be understood as the color change degree information of the pixel point. For example, if the color of the pixel point is 2, -3.8, 2.8, and the color change information is 1, then the color of the pixel point after adjustment is 3, -2.8, 3.8.
[0154] In practical applications, the calculation formula for calculating the color change information of the target pixel point according to the pixel color difference value and the color difference value ratio of the target pixel point is shown in Formula 13:
[0155] (ca) / (ba)*[ba] (Formula 13)
[0156] Among them, a is the initial color information; b is the target color information; c is the color information of the target pixel; (ca) and (ba) are calculated by the calibration color difference formula; [ba] is calculated by the target color difference formula.
[0157] In a specific embodiment of the present application, following the above example, when the standard color difference value calculated by the CIEDE2000 color difference formula is 0.6 and the color difference value calculated by the Euclidean distance color difference formula is 0.5, since the standard color difference value is greater than 0.5, the color change information result is (ca).
[0158] In another specific embodiment of the present application, following the above example, when the standard color difference value calculated by the CIEDE2000 color difference formula for the color difference value of the initial color information and the target color information is 0.1 and the color difference value calculated by the Euler distance color difference formula is 0.4, because the standard color difference value is less than 0.5, the color change information result is (ca)*[ba] / (ba).
[0159] After the color replacement is completed for the area to be processed, the area to be processed may also be faded to generate a target image. Specifically, the method further includes:
[0160] A fade processing operation is performed on the area to be processed to generate a target image.
[0161] The fade method can be achieved by modifying the alpha value of the image. In actual applications, the method of cutout is to replace the color area with black, that is, to reduce the color value of the entire area by a set value. Therefore, due to the reduced color value, the edge area that is not cut out tends to be the inverse color of the target color, which affects the actual use. Therefore, for the edge area of the cutout, by multiplying the feather value by the alpha value of the actual edge, we can make the image as faded as possible when displaying the abnormal effect caused by the inversion.
[0162] The present application provides an image processing method, which receives an image processing request of an image to be processed, determines initial color information and target color information according to the image processing request; determines a region to be processed in the image to be processed according to the initial color information; calculates the pixel color difference value between the color information of each target pixel in the region to be processed and the initial color information, and determines the color difference value ratio according to the initial color information and the target color information; and adjusts the color information of each target pixel in the region to be processed according to the pixel color difference value of each target pixel and the color difference value ratio. By converting the RGB color value in the image to be processed into a Lab color value, and using the CIEDE2000 color difference formula to extract the region close to the target color in the image to be processed, a region to be processed that is more in line with the visual characteristics of the human eye is obtained, and by optimizing the region to be processed, a more accurate region to be processed is obtained; by combining the Euclidean color difference distance formula with the color replacement formula generated by the CIEDE2000 color difference formula, the color in the region to be processed can be replaced more naturally.
[0163] The following combination Figure 4 Taking the application of the image processing method provided by the present application in replacing the color of the sky as an example, the image processing method is further described. Figure 4 A processing flow chart of an image processing method for replacing the sky color provided by an embodiment of the present application is shown, which specifically includes the following steps:
[0164] Step 402: Receive an image processing request for image i1, and determine initial color information and target color information according to the image processing request.
[0165] In a specific embodiment of the present application, an image processing request for image i1 is received, where image i1 is a photo of the sky. According to the image processing request, the initial color information is determined to be “sky blue: “64.2, -11.4, -55.5 (L, a, b)”, and the target color information is determined to be “black: 2.0, -3.8, 2.8 (L, a, b)”.
[0166] Step 404: Calculate an initial color difference value between the color information of each initial pixel in the image to be processed and the initial color information.
[0167] In a specific embodiment of the present application, following the above example, an initial pixel point a1 in the image to be processed is determined, and the initial color difference value between the color information "59.8, -3.6, -62.5 (L, a, b)" of the initial pixel point a1 and the initial color information "64.2, -11.4, -55.5 (L, a, b)" is calculated. The initial color difference value is calculated to be 5.6 using the CIEDE2000 color difference formula.
[0168] Step 406: Determine the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold.
[0169] In a specific embodiment of the present application, following the above example, the preset color difference value threshold is 8. After calculating the color information of each initial pixel point in the image to be processed and the initial color difference value of the initial color information, the initial pixel point whose initial color difference value is less than the preset color difference value threshold is selected as the target pixel point, and all the target pixel points are combined to determine the processing area of the image to be processed.
[0170] Step 408: Calculate the pixel color difference value between the color information of each target pixel in the area to be processed and the initial color information, calculate the mixed color difference value and the standard color difference value according to the initial color information and the target color information, and determine the color difference value ratio according to the mixed color difference value and the standard color difference value.
[0171] In a specific embodiment of the present application, following the above example, the pixel color difference value between the color information of the target pixel a1 and the initial color information is calculated to be 5.6, the mixed color difference value is calculated to be 56.8 based on the initial color information and the target color information, the standard color difference value is calculated to be 56.8 based on the initial color information and the target color information, and the color difference value ratio is determined to be 1 based on the mixed color difference value and the standard color difference value.
[0172] In another specific embodiment of the present application, the pixel color difference value between the color information of the target pixel a2 and the initial color information is calculated using the above example to be 0.2, the mixed color difference value is calculated based on the initial color information and the target color information to be 51.2, the standard color difference value is calculated based on the initial color information and the target color information to be 56.8, and the color difference value ratio is determined to be 0.9 based on the mixed color difference value and the standard color difference value.
[0173] Step 410: determine the current target pixel, calculate the color change information of the target pixel according to the pixel color difference value of the target pixel and the color difference value ratio, and adjust the color information of the target pixel according to the color change information of the target pixel.
[0174] In a specific embodiment of the present application, the above example is used to calculate the color change information of the target pixel point a1 as 5.6*1=5.6 based on the pixel color difference value 5.6 and the color difference value ratio of the target pixel point a1. The color information of the target pixel point a1 is adjusted according to the color change information, and the final color information of the target pixel point a1 is "2.0, -3.8, 2.8 (L, a, b)". Similarly, the color information of each target pixel point in the area to be processed is replaced to generate the target image i2.
[0175] An image processing method for replacing the color of the sky is provided in an embodiment of the present application. The method receives an image processing request of an image i1, determines the initial color information and the target color information according to the image processing request; calculates the initial color difference value between the color information of each initial pixel in the image to be processed and the initial color information; determines the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold; calculates the pixel color difference value between the color information of each target pixel in the area to be processed and the initial color information, calculates the mixed color difference value and the standard color difference value according to the initial color information and the target color information; determines the color difference value ratio according to the mixed color difference value and the standard color difference value. The area to be processed that the user wants to select is selected by the color difference value between the color of each initial pixel in the image to be processed and the initial color; then calculates the color difference value ratio between the initial color and the target color, and according to the color difference value between the color of each target pixel and the initial color, the degree of change of each target pixel can be accurately obtained, thereby accurately obtaining the target image whose color the user wants to replace.
[0176] Corresponding to the above method embodiment, the present application also provides an image processing device embodiment, Figure 5 FIG. 1 is a schematic diagram showing the structure of an image processing device provided by an embodiment of the present application. Figure 5 As shown, the device comprises:
[0177] The receiving module 502 is configured to receive an image processing request of an image to be processed, and determine initial color information and target color information according to the image processing request;
[0178] A determination module 504 is configured to determine a to-be-processed area in the to-be-processed image according to the initial color information;
[0179] A calculation module 506 is configured to calculate a pixel color difference value between the color information of each target pixel in the area to be processed and the initial color information, and determine a color difference value ratio according to the initial color information and the target color information;
[0180] The adjustment module 508 is configured to adjust the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio.
[0181] The determining module 504 is further configured to:
[0182] Calculating an initial color difference value between the color information of each initial pixel in the image to be processed and the initial color information;
[0183] The to-be-processed area in the to-be-processed image is determined according to the initial color difference value of each initial pixel and a preset color difference value threshold.
[0184] The determining module 504 is further configured to:
[0185] Determine the current initial pixel point;
[0186] Determine whether the initial color difference value of the current initial pixel exceeds a preset color difference value threshold;
[0187] If the color difference does not exceed the preset color difference value threshold, determining the current initial pixel point as the target pixel point;
[0188] The area to be processed is determined according to each target pixel.
[0189] The determining module 504 is further configured to:
[0190] Determine an initial area to be processed in the image to be processed according to an initial color difference value of each initial pixel and a preset color difference value threshold;
[0191] Optimization information for the initial area to be processed is obtained, and the initial area to be processed is optimized based on the optimization information to generate an area to be processed.
[0192] The calculation module 506 is further configured to:
[0193] Calculate a mixed color difference value and a standard color difference value according to the initial color information and the target color information;
[0194] The color difference value ratio is determined according to the mixed color difference value and the standard color difference value.
[0195] The calculation module 506 is further configured to:
[0196] Calculate the mixed color difference value of the initial color information and the target color information by using the target color difference formula and the calibration color difference formula;
[0197] The standard color difference value between the initial color information and the target color information is calculated by a target color difference formula.
[0198] The adjustment module 508 is further configured to:
[0199] Determine the current target pixel;
[0200] The color information of the current target pixel is adjusted according to the pixel color difference value of the current target pixel and the color difference value ratio.
[0201] The adjustment module 508 is further configured to:
[0202] Calculating the color change information of the target pixel point according to the pixel color difference value of the target pixel point and the color difference value ratio;
[0203] The color information of the target pixel is adjusted according to the color change information of the target pixel.
[0204] The device further comprises: a fading module configured to perform a fading operation on the area to be processed to generate a target image.
[0205] The present application provides an image processing device, the device includes a receiving module, configured to receive an image processing request of an image to be processed, and determine the initial color information and the target color information according to the image processing request; a determining module, configured to determine the area to be processed in the image to be processed according to the initial color information; a calculating module, configured to calculate the pixel color difference value between the color information of each target pixel in the area to be processed and the initial color information, and determine the color difference value ratio according to the initial color information and the target color information; an adjusting module, configured to adjust the color information of each target pixel in the area to be processed according to the pixel color difference value of each target pixel and the color difference value ratio. By converting the RGB color value in the image to be processed into a Lab color value, and using the CIEDE2000 color difference formula to extract the area close to the target color in the image to be processed, a region to be processed that is more in line with the visual characteristics of the human eye is obtained, and by optimizing the region to be processed, a more accurate region to be processed is obtained; by combining the Euclidean color difference distance formula with the CIEDE2000 color difference formula to generate a color replacement formula, the color in the area to be processed can be replaced more naturally.
[0206] The above is a schematic scheme of an image processing device of this embodiment. It should be noted that the technical scheme of the image processing device and the technical scheme of the above-mentioned image processing method belong to the same concept, and the details not described in detail in the technical scheme of the image processing device can be referred to the description of the technical scheme of the above-mentioned image processing method.
[0207] Figure 6 The block diagram of a computing device 600 according to an embodiment of the present application is shown. The components of the computing device 600 include but are not limited to a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and the database 650 is used to store data.
[0208] The computing device 600 also includes an access device 640 that enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 640 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0209] In one embodiment of the present application, the above components of the computing device 600 and Figure 6 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 6 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0210] The computing device 600 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 600 may also be a mobile or stationary server.
[0211] The processor 620 implements the steps of the image processing method when executing the computer instructions.
[0212] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above-mentioned image processing method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above-mentioned image processing method.
[0213] An embodiment of the present application further provides a computer-readable storage medium storing computer instructions, which implement the steps of the image processing method as described above when executed by a processor.
[0214] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the above-mentioned image processing method belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the above-mentioned image processing method.
[0215] The above describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0216] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0217] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described action sequence, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0218] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0219] The preferred embodiments of the present application disclosed above are only used to help explain the present application. The optional embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the present application. The present application selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present application, so that those skilled in the art can understand and use the present application well. The present application is only limited by the claims and their full scope and equivalents.
Claims
1. An image processing method, characterized in that: include: receiving an image processing request for an image to be processed, and determining initial color information and target color information according to the image processing request; Determine a to-be-processed area in the to-be-processed image according to the initial color information; Calculating the pixel color difference between the color information of each target pixel in the to-be-processed area and the initial color information, and determining the color difference value ratio according to the initial color information and the target color information; Adjusting the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio; Wherein, determining the color difference value ratio according to the initial color information and the target color information includes: calculating a mixed color difference value and a standard color difference value according to the initial color information and the target color information; determining the color difference value ratio according to the mixed color difference value and the standard color difference value; Adjusting the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio, including: calculating the color change information of each target pixel according to the pixel color difference value of each target pixel and the color difference value ratio; adjusting the color information of each target pixel in the to-be-processed area according to the color change information of the target pixel; The color change information of each target pixel is calculated according to the pixel color difference value of each target pixel and the color difference value ratio as follows: color change information of target pixel=(ca) / (ba)×[ba]; wherein a is the initial color information, b is the target color information, c is the color information of the target pixel, (ca) and (ba) are calculated by the calibration color difference formula, and [ba] is calculated by the target color difference formula; The target color difference formula is a formula for calculating the standard color difference value, and the target color difference formula is the CIEDE2000 color difference formula; The color difference correction formula is a formula for calculating a mixed color difference value, and is generated by combining the CIEDE2000 color difference formula with the Euclidean distance color difference formula.
2. The image processing method according to claim 1, characterized in that: Determining a region to be processed in the image to be processed according to the initial color information includes: Calculating an initial color difference value between the color information of each initial pixel in the image to be processed and the initial color information; The to-be-processed area in the to-be-processed image is determined according to the initial color difference value of each initial pixel and a preset color difference value threshold.
3. The image processing method according to claim 2, characterized in that: Determining the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold, comprising: Determine the current initial pixel point; Determine whether the initial color difference value of the current initial pixel exceeds a preset color difference value threshold; If the color difference does not exceed the preset color difference value threshold, determining the current initial pixel point as the target pixel point; The area to be processed is determined according to each target pixel.
4. The image processing method according to claim 2, wherein: Determining the area to be processed in the image to be processed according to the initial color difference value of each initial pixel and a preset color difference value threshold, comprising: Determine an initial area to be processed in the image to be processed according to an initial color difference value of each initial pixel and a preset color difference value threshold; Optimization information for the initial area to be processed is obtained, and the initial area to be processed is optimized based on the optimization information to generate an area to be processed.
5. The image processing method according to claim 1, wherein: Calculating a mixed color difference value and a standard color difference value according to the initial color information and the target color information includes: Calculate the mixed color difference value of the initial color information and the target color information by using the target color difference formula and the calibration color difference formula; The standard color difference value between the initial color information and the target color information is calculated by a target color difference formula.
6. The image processing method according to any one of claims 1 to 5, characterized in that: The method further comprises: A fade processing operation is performed on the area to be processed to generate a target image.
7. An image processing device, characterized in that: include: A receiving module is configured to receive an image processing request of an image to be processed, and determine initial color information and target color information according to the image processing request; A determination module, configured to determine a to-be-processed area in the to-be-processed image according to the initial color information; A calculation module is configured to calculate a pixel color difference value between the color information of each target pixel point in the to-be-processed area and the initial color information, and determine a color difference value ratio according to the initial color information and the target color information; An adjustment module is configured to adjust the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio; Wherein, determining the color difference value ratio according to the initial color information and the target color information includes: calculating a mixed color difference value and a standard color difference value according to the initial color information and the target color information; determining the color difference value ratio according to the mixed color difference value and the standard color difference value; Adjusting the color information of each target pixel in the to-be-processed area according to the pixel color difference value of each target pixel and the color difference value ratio, including: calculating the color change information of each target pixel according to the pixel color difference value of each target pixel and the color difference value ratio; adjusting the color information of each target pixel in the to-be-processed area according to the color change information of the target pixel; The color change information of each target pixel is calculated according to the pixel color difference value of each target pixel and the color difference value ratio as follows: color change information of target pixel=(ca) / (ba)×[ba]; wherein a is the initial color information, b is the target color information, c is the color information of the target pixel, (ca) and (ba) are calculated by the calibration color difference formula, and [ba] is calculated by the target color difference formula; The target color difference formula is a formula for calculating the standard color difference value, and the target color difference formula is the CIEDE2000 color difference formula; The color difference correction formula is a formula for calculating a mixed color difference value, and is generated by combining the CIEDE2000 color difference formula with the Euclidean distance color difference formula.
8. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, characterized in that: When the processor executes the computer instructions, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium storing computer instructions, characterized in that: When the computer instruction is executed by a processor, the steps of the method described in any one of claims 1 to 6 are implemented.
10. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method, system and device for detecting color difference based on machine vision and storage medium
CN109141640A
Identification method and device for designated area in image, readable medium and electronic equipment
CN112241714A