Grayscale method and device of image data, terminal equipment and readable storage medium

By calculating the grayscale conversion coefficient of image data and performing grayscale conversion, the problem of information loss caused by grayscale conversion in existing technologies is solved, and the contrast is preserved and the grayscale conversion efficiency is improved.

CN114882125BActive Publication Date: 2026-03-27WUHAN TCL CORP RES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-05
Publication Date
2026-03-27

AI Technical Summary

Technical Problem

Existing image grayscale conversion techniques cannot preserve the contrast of the original image data, resulting in information loss in the converted grayscale image.

Method used

By determining the relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed, the grayscale conversion coefficient is calculated, and the image data is converted to grayscale based on the coefficient, including the grayscale conversion of image blocks and pixels.

Benefits of technology

It effectively preserves the contrast information of image data, improving grayscale conversion efficiency and the quality of target grayscale image data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114882125B_ABST
    Figure CN114882125B_ABST
Patent Text Reader

Abstract

The application is suitable for the technical field of image processing, and provides a grayscale method and device of image data, a terminal equipment and a readable storage medium, the method comprises the following steps: determining a first relationship among a grayscale conversion coefficient, a pixel value and a color contrast of to-be-processed image data; determining the pixel value and the color contrast of a plurality of pixel pairs in the to-be-processed image data; determining the grayscale conversion coefficient according to the first relationship, the pixel value and the color contrast of the plurality of pixel pairs; and performing grayscale conversion on the to-be-processed image data according to the grayscale conversion coefficient, so as to obtain target grayscale image data. The pixel value and the color contrast of the plurality of pixel pairs in the to-be-processed image data are used to calculate the conversion coefficient and perform grayscale conversion on the to-be-processed image data, so that the target grayscale image data after conversion can retain the contrast information of the to-be-processed image data, and the grayscale conversion efficiency and the quality of the target grayscale image data are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of image processing technology, and in particular relates to a method, apparatus, terminal device and readable storage medium for grayscale conversion of image data. Background Technology

[0002] In image application technology, image grayscale conversion is a common technique. Grayscale images are often used in fields such as digital printing and photo rendering.

[0003] Existing image grayscale conversion techniques typically fail to preserve the contrast of the original image data, resulting in information loss in the converted grayscale image. Summary of the Invention

[0004] This application provides a method, apparatus, terminal device, and readable storage medium for converting image data to grayscale, which can solve the problem that existing image grayscale conversion techniques cannot retain the contrast of the original image data, resulting in information loss in the converted grayscale image.

[0005] In a first aspect, embodiments of this application provide a method for grayscale conversion of image data, including:

[0006] Determine the primary relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed;

[0007] Determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs;

[0008] The grayscale conversion coefficient is determined based on the first relationship, the pixel value, and the color contrast.

[0009] The image data to be processed is converted to grayscale according to the grayscale conversion coefficient to obtain the target grayscale image data.

[0010] In one embodiment, the step of converting the image data to be processed to grayscale according to the grayscale conversion coefficient to obtain target grayscale image data includes:

[0011] The grayscale value of a preset pixel in the image data to be processed is determined based on the grayscale conversion coefficient.

[0012] The target grayscale image data corresponding to the image data to be processed is determined based on the grayscale value.

[0013] In one embodiment, determining the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed includes:

[0014] Select multiple image blocks from the image data to be processed, and construct multiple image block pairs based on the multiple image blocks;

[0015] The pixel value and color contrast of each image block pair are calculated based on the pixel values ​​of all pixels in each image block.

[0016] In one embodiment, calculating the pixel value and color contrast of each image block pair based on the pixel values ​​of all pixels in each image block includes:

[0017] Based on the RGB three-channel pixel values ​​of all pixels in each image block, the average pixel value of each image block in the RGB three channels is calculated and used as the RGB three-channel pixel value of each image block.

[0018] Based on the Lab three-channel pixel values ​​of all pixels in each image block, the average pixel value of each image block in the Lab three-channel is calculated and used as the Lab three-channel pixel value of each image block;

[0019] The color contrast of each image block pair is calculated and determined based on the Lab three-channel pixel values ​​of each image block in each image block pair.

[0020] In one embodiment, determining the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed further includes:

[0021] Select multiple pixels from the image data to be processed, and construct multiple pixel pairs based on the multiple pixels;

[0022] Determine the RGB three-channel pixel values ​​and color contrast for each pixel pair.

[0023] In one embodiment, determining the grayscale conversion coefficient based on the first relationship, the pixel value, and the color contrast includes:

[0024] Substitute the RGB three-channel pixel values ​​and color contrast of the multiple pixel pairs into the first relationship to obtain the grayscale conversion coefficient matrix;

[0025] The least-squares solution of the grayscale conversion coefficient matrix is ​​calculated based on the pixel values ​​and color contrast of the multiple pixel pairs, and is used as the grayscale conversion coefficient.

[0026] In one embodiment, determining the first relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed includes:

[0027] The first relationship is determined based on the second and third relationships of the image data to be processed; wherein the second relationship is the relationship between grayscale value and color contrast, and the third relationship is the relationship between grayscale conversion coefficient, pixel value and grayscale value.

[0028] Secondly, embodiments of this application provide a grayscale conversion device for image data, comprising:

[0029] The first determining module is used to determine the first relationship between the grayscale conversion coefficient, pixel value and color contrast of the image data to be processed;

[0030] The second determining module is used to determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs;

[0031] The third determining module is used to determine the grayscale conversion coefficient based on the first relationship, the pixel value, and the color contrast.

[0032] The conversion module is used to perform grayscale conversion on the image data to be processed according to the grayscale conversion coefficient to obtain the target grayscale image data.

[0033] In one embodiment, the conversion module includes:

[0034] A conversion unit is used to determine the grayscale value of a preset pixel in the image data to be processed based on the grayscale conversion coefficient.

[0035] The traversal unit is used to determine the target grayscale image data corresponding to the image data to be processed based on the grayscale value.

[0036] In one embodiment, the second determining module includes:

[0037] The first selection unit is used to select multiple image blocks in the image data to be processed, and to construct multiple image block pairs based on the multiple image blocks;

[0038] The first calculation unit is used to calculate the pixel value and color contrast of each image block pair based on the pixel values ​​of all pixels in each image block.

[0039] In one embodiment, the first computing unit includes:

[0040] The first calculation subunit is used to calculate the average pixel value of each image block in the RGB three channels based on the RGB three-channel pixel values ​​of all pixels in each image block, and use it as the RGB three-channel pixel value of each image block.

[0041] The second calculation subunit is used to calculate the average value of the pixels in the Lab three channels of each image block based on the Lab three-channel pixel values ​​of all pixels in each image block, and use it as the Lab three-channel pixel value of each image block.

[0042] The third calculation subunit is used to calculate and determine the color contrast of each image block pair based on the Lab three-channel pixel values ​​of each image block in each image block pair.

[0043] In one embodiment, the second determining module includes:

[0044] The second selection unit is used to select multiple pixels in the image data to be processed, and to construct multiple pixel pairs based on the multiple pixels;

[0045] The determination unit is used to determine the RGB three-channel pixel values ​​and color contrast for each pixel pair.

[0046] In one embodiment, the third determining module includes:

[0047] The second calculation unit is used to substitute the RGB three-channel pixel values ​​and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix.

[0048] The third calculation unit is used to calculate the least squares solution of the grayscale conversion coefficient matrix based on the pixel values ​​and color contrast of the plurality of pixel pairs, and use it as the grayscale conversion coefficient.

[0049] In one embodiment, the determining module includes:

[0050] The determining unit is configured to determine the first relationship based on the second relationship and the third relationship of the image data to be processed; wherein the second relationship is the relationship between grayscale value and color contrast, and the third relationship is the relationship between grayscale conversion coefficient, pixel value and grayscale value.

[0051] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the grayscale conversion method for image data as described in any one of the first aspects above.

[0052] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the grayscale conversion method for image data as described in any one of the first aspects above.

[0053] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the grayscale conversion method for image data described in any of the first aspects.

[0054] By calculating the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed, grayscale conversion coefficients are obtained. Based on the grayscale conversion coefficients, the coefficients of the image to be processed are converted to grayscale to obtain the target grayscale image data. The computation is small, and the converted target grayscale image data can retain the contrast information of the image data to be processed, thus improving the grayscale conversion efficiency and the quality of the target grayscale image data.

[0055] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0056] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0057] Figure 1 This is a schematic flowchart of the grayscale conversion method for image data provided in an embodiment of this application;

[0058] Figure 2 This is a flowchart illustrating step S104 of the grayscale conversion method for image data provided in this application embodiment;

[0059] Figure 3 This is a flowchart illustrating step S102 of the grayscale conversion method for image data provided in this application embodiment;

[0060] Figure 4 This is a flowchart illustrating step S1022 of the grayscale conversion method for image data provided in this application embodiment;

[0061] Figure 5 This is another flowchart illustrating step S102 of the grayscale conversion method for image data provided in the embodiments of this application;

[0062] Figure 6(a) , 6(b) 6(c) is a schematic diagram of grayscale image data obtained based on different image grayscale conversion methods provided in the embodiments of this application;

[0063] Figure 7 This is a schematic diagram of the structure of the grayscale conversion device for image data provided in the embodiments of this application;

[0064] Figure 8 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0065] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0066] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0067] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0068] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0069] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0070] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0071] The grayscale conversion method for image data provided in this application can be applied to terminal devices such as mobile phones, tablets, and laptops. This application does not impose any restrictions on the specific type of terminal device.

[0072] Figure 1 A schematic flowchart of the grayscale conversion method for image data provided in this application is shown. This is an example and not a limitation, and the method can be applied to the aforementioned laptop computer.

[0073] S101. Determine the first relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed.

[0074] In practical applications, grayscale values ​​can be determined based on the pixel values ​​and conversion coefficients of pixel pairs in the image data to be processed. The corresponding color contrast can then be determined based on the grayscale values ​​of the pixel pairs, thereby establishing the primary relationship between the grayscale conversion coefficient, pixel values, and color contrast. A pixel pair refers to a pair of pixels located at different positions in the image data to be processed.

[0075] The image data to be processed refers to the actual image data that needs to be converted to grayscale. It is understood that during the image grayscale conversion process, it is necessary to determine the conversion coefficients W for the R, G, and B channels respectively. R W G W B Then, the RGB three channels of the pixels in the image data to be processed are converted to grayscale.

[0076] In one embodiment, step S101 includes:

[0077] The first relationship is determined based on the second and third relationships of the image data to be processed; wherein the second relationship is the relationship between grayscale value and color contrast, and the third relationship is the relationship between grayscale conversion coefficient, pixel value and grayscale value.

[0078] In practical applications, to ensure that the converted target grayscale image data retains as much color contrast as possible from the image data to be processed, the conversion objective is set as: minimizing the color contrast between pixel pairs in the image data to be processed. Therefore, the second relationship between the grayscale value and color contrast of a pixel pair can be expressed as:

[0079] min∑ x,y (g x -g y -δ x,y ) 2 ;Formula (1)

[0080] In practical applications, the grayscale value of a pixel is determined by converting the RGB values ​​of the pixel into grayscale values ​​using three-channel conversion coefficients. Therefore, the third relationship can be expressed as:

[0081]

[0082] In the formula, x and y represent a pair of pixels in the image data to be processed, and g x g represents the grayscale value of pixel x in the image data to be processed. y δ represents the grayscale value of pixel y in the image data to be processed. x,y Indicates the corresponding color contrast; W R W G W B These represent the conversion coefficients for the three RGB channels, Ri and Rj respectively. x G x B x These represent the pixel values ​​of the R, G, and B channels of pixel x in the image data to be processed, respectively. y G y B y The values ​​of the R, G, and B channels of pixel y in the image data to be processed are represented respectively.

[0083] In practical applications, by substituting the third relationship between grayscale conversion coefficient, pixel value, and grayscale value into the second relationship between grayscale value and color contrast, and setting the polynomial of the second relationship to 0, we can obtain:

[0084] W R ·R x +W G ·G x +W B ·B x -(W R ·R y +W G ·G y +W B ·B y )=δx,y ;Formula (3)

[0085] By rearranging formula (3), we obtain:

[0086] W R ·(R x -R y )+W G ·(G x -G y )+W B ·(B x -B y )=δ x,y ;Formula (4)

[0087] Let I R =R x -R y I G =G x -G y I B =B x -B y This yields the first relationship between the grayscale conversion coefficient, pixel value, and color contrast:

[0088] W R ·I R +W G ·I G +W B ·I B =δ x,y ;Formula (5).

[0089] The color contrast of a pixel pair can be obtained using the following formula:

[0090]

[0091] In the formula, L x a represents the L-channel pixel value of pixel x in the image data to be processed. x This represents the pixel value of channel a of pixel x in the image data to be processed, and channel b... x L represents the b-channel pixel value of pixel x in the image data to be processed; y a represents the L-channel pixel value of pixel y in the image data to be processed. y This represents the pixel value of channel a of pixel y in the image data to be processed, and channel b... y This represents the b-channel pixel value of pixel y in the image data to be processed.

[0092] S102. Determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs.

[0093] In practical applications, by selecting multiple pixel pairs (including but not limited to image block pairs or pixel point pairs) from the image data to be processed, a better grayscale conversion coefficient can be calculated and determined based on the pixel values ​​and color contrast of the multiple pixel pairs. This allows for grayscale conversion of the image data to be processed to obtain the target grayscale image data. An image block pair refers to a pair of image blocks located at different positions in the image data to be processed.

[0094] S103. Determine the grayscale conversion coefficient based on the first relationship, the pixel value, and the color contrast.

[0095] In practical applications, by selecting pixel pairs from multiple image data to be processed, the pixel values ​​and color contrast of multiple pixel pairs are determined. Based on the pixel values ​​and color contrast of multiple pixel pairs, the first relationship is transformed into a grayscale conversion coefficient matrix. Then, the least squares solution of the grayscale conversion coefficient matrix is ​​calculated to obtain the grayscale conversion coefficients.

[0096] S104. Perform grayscale conversion on the image data to be processed according to the grayscale conversion coefficient to obtain the target grayscale image data.

[0097] In practical applications, grayscale conversion coefficients are used to convert the grayscale of each pixel in the image data to be processed, thereby obtaining the target grayscale image data corresponding to the image data to be processed.

[0098] like Figure 2 As shown, in one embodiment, step S104 includes:

[0099] S1041. Determine the grayscale value of a preset pixel in the image data to be processed based on the grayscale conversion coefficient;

[0100] S1042. Determine the target grayscale image data corresponding to the image data to be processed based on the grayscale value.

[0101] In practical applications, when determining the conversion coefficients of the R, G, and B channels, the pixel values ​​of the R, G, and B channels of a preset pixel in the image data to be processed are obtained. The R, G, and B channel values ​​of the preset pixel are then converted to grayscale using the conversion coefficients of the R, G, and B channels respectively, to obtain the grayscale value of the preset pixel after conversion. Based on the grayscale value of the preset pixel, the target grayscale image data corresponding to the image data to be processed is obtained.

[0102] Understandably, during grayscale conversion, each pixel in the image data to be processed needs to be converted to grayscale individually. Therefore, a preset set of pixels is defined as all pixels in the image data to be processed. Specifically, the conversion coefficients of the R, G, and B channels are used to convert the R, G, and B channel values ​​of each pixel in the image data to be processed, obtaining the grayscale value of each pixel in the converted image data, and thus obtaining the target grayscale image data corresponding to the image data to be processed.

[0103] The grayscale conversion of pixel values ​​using a conversion coefficient can be expressed as:

[0104] g(o,c)=W R ·R(o,c)+W G ·G(o,c)+W B ·B(o,c) formula (7);

[0105] In the formula, R(o,c) represents the pixel value of the R channel of the pixel in the o-th row and c-th column of the image data to be processed, G(o,c) represents the pixel value of the G channel of the pixel in the o-th row and c-th column of the image data to be processed, B(o,c) represents the pixel value of the B channel of the pixel in the o-th row and c-th column of the image data to be processed, and g(o,c) represents the grayscale value of the pixel in the o-th row and c-th column after conversion.

[0106] like Figure 3 As shown, in one embodiment, step S102 includes:

[0107] S1021. Select multiple image blocks from the image data to be processed, and construct multiple image block pairs based on the multiple image blocks;

[0108] S1022. Calculate the pixel value and color contrast of each image block pair based on the pixel values ​​of all pixels in each image block.

[0109] In practical applications, multiple image blocks are randomly selected from the image data to be processed, and these image blocks are randomly paired to construct multiple image block pairs. The pixel values ​​of all pixels in each image block are identified, and the average pixel values ​​of all pixels in each image block in the R, G, and B channels are calculated as the pixel values ​​of each image block in the R, G, and B channels. The average pixel values ​​of all pixels in each image block in the L, a, and b channels in the CIELab color space are also calculated as the pixel values ​​of each image block in the L, a, and b channels. Based on the pixel values ​​of each image block in the L, a, and b channels of each image block in each pair (specifically substituted into Formula 6), the color contrast of each image block pair is calculated.

[0110] like Figure 4As shown, in one embodiment, step S1022 includes:

[0111] S10221. Based on the RGB three-channel pixel values ​​of all pixels in each image block, calculate the average pixel value of each image block in the RGB three channels, and use it as the RGB three-channel pixel value of each image block.

[0112] S10222. Based on the Lab three-channel pixel values ​​of all pixels in each image block, calculate the average pixel value of each image block in the Lab three-channel, and use it as the Lab three-channel pixel value of each image block.

[0113] S10223. Calculate and determine the color contrast of each image block pair based on the Lab three-channel pixel values ​​of each image block in each image block pair.

[0114] In practical applications, the pixel values ​​of the R, G, and B channels of all pixels in each image block are obtained separately. Based on the pixel values ​​of the R, G, and B channels of all pixels in each image block, the average pixel values ​​of the R, G, and B channels of each image block are calculated and used as the pixel values ​​of the R, G, and B channels of each image block. The pixel values ​​of the L, a, and b channels of all pixels in each image block in the CIELab color space are also obtained separately. Based on the pixel values ​​of the L, a, and b channels of all pixels in each image block, the average pixel values ​​of the L, a, and b channels of each image block are calculated and used as the pixel values ​​of the L, a, and b channels of each image block. Based on the pixel values ​​of the L, a, and b channels of each image block in each image block pair, the color contrast of each image block pair is calculated.

[0115] The average pixel values ​​of the R channel, G channel, and B channel in image patch x and y can be obtained using the following formula:

[0116]

[0117] In the formula, R x,i This represents the pixel value of the R channel and G channel of the i-th pixel in image block x in the image data to be processed. x,i B represents the pixel value of the G channel of the i-th pixel in image block x in the image data to be processed. x,i R represents the pixel value of the B channel of the i-th pixel in image block x of the image data to be processed. x-block G represents the average pixel value of the R channel of image patch x in the image data to be processed; x-block B represents the average pixel value of the G channel of image patch x in the image data to be processed; x-blockLet R represent the average pixel value of the B channel of image patch x in the image data to be processed; correspondingly, let R represent the average pixel value of the R, G, and B channels of image patch y in the image data to be processed. y-block G y-block B y-block and the color contrast δ of the corresponding image patch y x,y-block The calculation method and R x-block G x-block B x-block The calculation method is the same, and will not be repeated here.

[0118] like Figure 5 As shown, in one embodiment, step S102 further includes:

[0119] S1023. Select multiple pixels in the image data to be processed, and construct multiple pixel pairs based on the multiple pixels;

[0120] S1024. Determine the RGB three-channel pixel values ​​and color contrast for each pixel pair.

[0121] In practical applications, multiple pixels in the image data to be processed are randomly selected and randomly paired to construct multiple pixel pairs. The RGB three-channel pixel values ​​of each pixel in each pixel pair and the Lab three-channel pixel values ​​of each pixel in each pixel pair are identified. Based on the Lab three-channel pixel values ​​of each pixel in each pixel pair, the color contrast of each pixel pair is calculated and determined using the above formula 6.

[0122] In practical applications, the pixel value of a single pixel is easily affected by noise and becomes unstable, leading to inconsistent accuracy in calculation results obtained from randomly determined pixel pairs. To address this, image block pairs are selected from the image data to be processed. The average pixel value of each image block pair is used as its pixel value, and the average color contrast of each image block pair is used as its color contrast. The corresponding conversion coefficient is then calculated based on the pixel value and color contrast of each image block pair, improving the accuracy and stability of the calculation results.

[0123] In one embodiment, step S103 includes:

[0124] Substitute the RGB three-channel pixel values ​​and color contrast of the multiple pixel pairs into the first relationship to obtain the grayscale conversion coefficient matrix;

[0125] The least-squares solution of the grayscale conversion coefficient matrix is ​​calculated based on the pixel values ​​and color contrast of the multiple pixel pairs, and is used as the grayscale conversion coefficient.

[0126] In practical applications, by selecting multiple pixel pairs and substituting the RGB three-channel pixel values ​​and color contrast of the multiple pixel pairs into the first relation (i.e., Formula 5 above), the corresponding set of equations can be obtained, and then the corresponding grayscale conversion coefficient matrix can be obtained. The least squares solution of the grayscale conversion coefficient matrix is ​​calculated based on the pixel values ​​and color contrast of the multiple pixel pairs, and is used as the corresponding grayscale conversion coefficient.

[0127] Taking pixel pairs as image block pairs as an example, by substituting the RGB three-channel pixel values ​​and color contrast of m image block pairs into the first relation, we can obtain:

[0128]

[0129] Among them, I R-block =R x-block -R y-block I G-block =G x-block -G y-block I B-block =B x-block -B y-block ;

[0130] By transforming formula (9), the grayscale conversion coefficient matrix is ​​obtained as follows:

[0131]

[0132] make The simplified grayscale conversion coefficient matrix can be obtained as: UV = k;

[0133] WhenU T When U is invertible, it can be determined by V = (U T ·U) -1 U T k calculates the least-squares solution of the grayscale conversion coefficient matrix.

[0134] By randomly selecting pixel pairs from multiple image data to be processed, the calculated grayscale conversion coefficient has better stability, thus maximizing the preservation of the contrast of the image data to be processed, making the contrast of the target grayscale image data as close as possible to the contrast of the image data to be processed.

[0135] Figure 6 provides an exemplary schematic diagram of grayscale image data obtained based on different image grayscale conversion methods;

[0136] For the same image to be processed, Figure 6(a) shows the first grayscale image data obtained by calculating the conversion coefficient based on the RGB three-channel pixel values ​​and color contrast of pixel pairs and then converting the image to grayscale; Figure 6(b) shows the target grayscale image data obtained by calculating the conversion coefficient based on the RGB three-channel pixel values ​​and color contrast of image block pairs and then converting the image to grayscale; Figure 6(c) shows the second grayscale image data obtained based on the existing grayscale conversion method.

[0137] This embodiment calculates grayscale conversion coefficients by using the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed, and then performs grayscale conversion on the coefficients of the image to be processed based on the grayscale conversion coefficients to obtain the target grayscale image data. The computational load is small, and at the same time, the converted target grayscale image data can retain the contrast information of the image data to be processed, thus improving the grayscale conversion efficiency and the quality of the target grayscale image data.

[0138] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0139] Corresponding to the grayscale conversion method of image data described in the above embodiments, Figure 7 A structural block diagram of an image data grayscale conversion apparatus provided in an embodiment of this application is shown. For ease of explanation, only the parts related to the embodiments of this application are shown.

[0140] Reference Figure 7 The grayscale conversion device 100 for the image data includes:

[0141] The first determining module 101 is used to determine a first relationship between the grayscale conversion coefficient, pixel value and color contrast of the image data to be processed;

[0142] The second determining module 102 is used to determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs or pixel point pairs;

[0143] The third determining module 103 is used to determine the grayscale conversion coefficient based on the first relationship, the pixel value and the color contrast.

[0144] The conversion module 104 is used to perform grayscale conversion on the image data to be processed according to the grayscale conversion coefficient to obtain target grayscale image data.

[0145] In one embodiment, the conversion module 104 includes:

[0146] A conversion unit is used to determine the grayscale value of a preset pixel in the image data to be processed based on the grayscale conversion coefficient.

[0147] The traversal unit is used to determine the target grayscale image data corresponding to the image data to be processed based on the grayscale value.

[0148] In one embodiment, the second determining module 102 includes:

[0149] The first selection unit is used to select multiple image blocks in the image data to be processed, and to construct multiple image block pairs based on the multiple image blocks;

[0150] The first calculation unit is used to calculate the pixel value and color contrast of each image block pair based on the pixel values ​​of all pixels in each image block.

[0151] In one embodiment, the first computing unit includes:

[0152] The first calculation subunit is used to calculate the average pixel value of each image block in the RGB three channels based on the RGB three-channel pixel values ​​of all pixels in each image block, and use it as the RGB three-channel pixel value of each image block.

[0153] The second calculation subunit is used to calculate the average value of the pixels in the Lab three channels of each image block based on the Lab three-channel pixel values ​​of all pixels in each image block, and use it as the Lab three-channel pixel value of each image block.

[0154] The third calculation subunit is used to calculate and determine the color contrast of each image block pair based on the Lab three-channel pixel values ​​of each image block in each image block pair.

[0155] In one embodiment, the second determining module 102 includes:

[0156] The second selection unit is used to select multiple pixels in the image data to be processed, and to construct multiple pixel pairs based on the multiple pixels;

[0157] The determination unit is used to determine the RGB three-channel pixel values ​​and color contrast for each pixel pair.

[0158] In one embodiment, the third determining module 103 includes:

[0159] The second calculation unit is used to substitute the RGB three-channel pixel values ​​and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix.

[0160] The third calculation unit is used to calculate the least squares solution of the grayscale conversion coefficient matrix based on the pixel values ​​and color contrast of the plurality of pixel pairs, and use it as the grayscale conversion coefficient.

[0161] In one embodiment, the determining module 101 includes:

[0162] The determining unit is configured to determine the first relationship based on the second relationship and the third relationship of the image data to be processed; wherein the second relationship is the relationship between grayscale value and color contrast, and the third relationship is the relationship between grayscale conversion coefficient, pixel value and grayscale value.

[0163] This embodiment calculates grayscale conversion coefficients by using the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed, and then performs grayscale conversion on the coefficients of the image to be processed based on the grayscale conversion coefficients to obtain the target grayscale image data. The computational load is small, and at the same time, the converted target grayscale image data can retain the contrast information of the image data to be processed, thus improving the grayscale conversion efficiency and the quality of the target grayscale image data.

[0164] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.

[0165] Figure 8 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Figure 8 As shown, the terminal device 8 of this embodiment includes: at least one processor 80 ( Figure 8 (Only one is shown) a processor, a memory 81, and a computer program 82 stored in the memory 81 and executable on the at least one processor 80, which, when executing the computer program 82, implements the steps in the grayscale conversion method embodiments of any of the above image data.

[0166] The terminal device 8 can be a desktop computer, laptop, handheld computer, or cloud server, etc. This terminal device may include, but is not limited to, a processor 80 and a memory 81. Those skilled in the art will understand that... Figure 8 This is merely an example of terminal device 8 and does not constitute a limitation on terminal device 8. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input / output devices, network access devices, etc.

[0167] The processor 80 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0168] In some embodiments, the memory 81 may be an internal storage unit of the terminal device 8, such as a hard disk or memory of the terminal device 8. In other embodiments, the memory 81 may be an external storage device of the terminal device 8, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the terminal device 8. Furthermore, the memory 81 may include both internal and external storage units of the terminal device 8. The memory 81 is used to store the operating system, applications, bootloader, data, and other programs, such as the program code of the computer program. The memory 81 can also be used to temporarily store data that has been output or will be output.

[0169] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0170] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.

[0171] This application provides a computer program product that, when run on a mobile terminal, enables the mobile terminal to implement the steps described in the above-described method embodiments.

[0172] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a photographing device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0173] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0174] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0175] In the embodiments provided in this application, it should be understood that the disclosed apparatus / network devices and methods can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0176] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0177] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for converting image data to grayscale, characterized in that, include: Determine the primary relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed; Determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs; The grayscale conversion coefficient is determined based on the first relationship, the pixel value, and the color contrast. The image data to be processed is converted to grayscale according to the grayscale conversion coefficient to obtain the target grayscale image data. Determining the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed includes: selecting multiple image blocks in the image data to be processed, and constructing multiple image block pairs based on the multiple image blocks; calculating the pixel values ​​and color contrast of each image block pair based on the average pixel values ​​of all pixels in each image block. The step of determining the grayscale conversion coefficient based on the first relationship, the pixel value, and the color contrast includes: substituting the RGB three-channel pixel values ​​and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix; and calculating the least squares solution of the grayscale conversion coefficient matrix based on the pixel values ​​and color contrast of the plurality of pixel pairs as the grayscale conversion coefficient.

2. The grayscale conversion method for image data as described in claim 1, characterized in that, The step of converting the image data to be processed into grayscale based on the grayscale conversion coefficient to obtain the target grayscale image data includes: The grayscale value of a preset pixel in the image data to be processed is determined based on the grayscale conversion coefficient. The target grayscale image data corresponding to the image data to be processed is determined based on the grayscale value.

3. The grayscale conversion method for image data as described in claim 1, characterized in that, The step of calculating the pixel value and color contrast of each image block pair based on the pixel values ​​of all pixels in each image block includes: Based on the RGB three-channel pixel values ​​of all pixels in each image block, the average pixel value of each image block in the RGB three channels is calculated and used as the RGB three-channel pixel value of each image block. Based on the Lab three-channel pixel values ​​of all pixels in each image block, the average pixel value of each image block in the Lab three-channel is calculated and used as the Lab three-channel pixel value of each image block; The color contrast of each image block pair is calculated and determined based on the Lab three-channel pixel values ​​of each image block in each image block pair.

4. The grayscale conversion method for image data as described in claim 1, characterized in that, Determining the first relationship between the grayscale conversion coefficient, pixel value, and color contrast of the image data to be processed includes: The first relationship is determined based on the second and third relationships of the image data to be processed; wherein the second relationship is the relationship between grayscale value and color contrast, and the third relationship is the relationship between grayscale conversion coefficient, pixel value and grayscale value.

5. A device for converting image data to grayscale, characterized in that, include: The first determining module is used to determine the first relationship between the grayscale conversion coefficient, pixel value and color contrast of the image data to be processed; The second determining module is used to determine the pixel values ​​and color contrast of multiple pixel pairs in the image data to be processed; wherein, the pixel pairs include image block pairs; The third determining module is used to determine the grayscale conversion coefficient based on the first relationship, the pixel value, and the color contrast. The conversion module is used to perform grayscale conversion on the image data to be processed according to the grayscale conversion coefficient to obtain target grayscale image data; The second determining module includes: The first selection unit is used to select multiple image blocks in the image data to be processed, and to construct multiple image block pairs based on the multiple image blocks; The first calculation unit is used to calculate the pixel value and color contrast of each image block pair based on the average pixel value of all pixels in each image block; The third determining module includes: The second calculation unit is used to substitute the RGB three-channel pixel values ​​and color contrast of the plurality of pixel pairs into the first relationship to obtain a grayscale conversion coefficient matrix. The third calculation unit is used to calculate the least squares solution of the grayscale conversion coefficient matrix based on the pixel values ​​and color contrast of the plurality of pixel pairs, and use it as the grayscale conversion coefficient.

6. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 4.

7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 4.