Image conversion method and device, and computer readable storage medium

By converting the YUV image into an intermediate grayscale image and performing information compensation, the image distortion problem when the YUV image is directly converted into an RGB image with a high degree of compression is solved, and the image display effect is improved.

CN114219703BActive Publication Date: 2025-04-11SPREADTRUM COMMUNICATION (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111538752.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2025-04-11
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

When the prior art directly converts YUV images into RGB images with a higher degree of compression, image distortion problems such as local "water stains" and blur are prone to occur, which affects the display effect.

Method used

By converting the YUV image into an intermediate grayscale image (the RGB image in M ​​bit), and determining whether the component information loss of each pixel is greater than the loss threshold during the conversion process, information compensation is performed, and finally converting it into a target grayscale image (the RGB image in N bit).

Benefits of technology

It effectively avoids local water stains and blurring during direct conversion, improves the display effect of the converted image, and improves the compensation accuracy by compensating on the intermediate grayscale image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114219703B_ABST
    Figure CN114219703B_ABST
Patent Text Reader

Abstract

An image conversion method and device, and a computer-readable storage medium, the method comprising: obtaining an initial image, the initial image being a YUV image; converting the initial image into an intermediate grayscale image, the intermediate grayscale image being an M-bit RGB image; converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during conversion is greater than the loss threshold of the component, and compensating for the component whose information loss is greater than the loss threshold; converting the compensated intermediate grayscale image into a second target grayscale image, the first target grayscale image and the second target grayscale image being N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N. Thus, it is possible to solve the image distortion problems such as "water stains" and blurring when a YUV image is directly converted into an RGB image with a high degree of compression and a small amount of data, and improve the display effect of the converted image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and in particular to an image conversion method and device, and a computer-readable storage medium. Background Art

[0002] If the existing conversion methods are directly used, such as Google's built-in image conversion tool libYUV, to convert high-resolution YUV images into RGB images with a higher degree of compression and smaller data volume (such as RGB565 images), image distortion problems such as local "water stains" and blur may occur, affecting the display effect of the converted image. Summary of the invention

[0003] The technical problem solved by the present invention is how to solve the image distortion problems such as "water stains" and blur when a YUV image is directly converted into an RGB image with a high degree of compression, so as to improve the display effect of the converted image.

[0004] To solve the above problems, an embodiment of the present invention provides an image conversion method, which includes: acquiring an initial image, which is a YUV image; converting the initial image into an intermediate grayscale image, which is an M-bit RGB image; converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during the conversion is greater than the loss threshold of the component, and compensating the component whose information loss is greater than the loss threshold; converting the compensated intermediate grayscale image into a second target grayscale image, which is an N-bit RGB image, wherein M and N are both positive integers, and the value of M is greater than N.

[0005] Optionally, the determination of whether the information loss of each component of each pixel during conversion is greater than a loss threshold of the component, and compensation for the component whose information loss is greater than the loss threshold, includes: step A, obtaining the first pixel in the intermediate grayscale image as the current pixel; step B, for the current pixel, obtaining each component in turn as the current component; step C, adjusting the value of the current component to the number of bits of the corresponding component of the first target grayscale image, and obtaining the value of the corresponding component in the first target grayscale image; step D, calculating the difference between the value of the current component and the value of the corresponding component in the first target grayscale image as the information loss of the current component; step E, if the information loss of the current component is greater than the loss threshold of the current component, performing information compensation on the current component; step F, obtaining the next pixel in the intermediate grayscale image as the current pixel, and continuing to execute steps B to D until all pixels in the intermediate grayscale image are traversed.

[0006] Optionally, adjusting the value of the current component to the number of bits of the corresponding component of the first target grayscale image to obtain the value of the corresponding component in the first target grayscale image includes: setting the low L bits of the value of the current component to zero, and shifting the value of the current component left by L bits to obtain the value of the corresponding component in the first target grayscale image; wherein, for the current pixel, the number of bits of the value of the current component is L bits more than the number of bits of the value of the corresponding component in the first target grayscale image, and L is a positive integer.

[0007] Optionally, the performing information compensation on the current component includes: adding a preset value to the value of the current component.

[0008] Optionally, the current component includes an R component, a G component and a B component, and the step of generating the loss threshold of the current component includes: obtaining a pixel value corresponding to the current pixel in a standard pattern of a first Bayer matrix, denoted as a loss threshold of the G component, and the first Bayer matrix is ​​a 2×2 matrix; obtaining a pixel value corresponding to the current pixel in a standard pattern of a second Bayer matrix, denoted as a loss threshold of the R component and the B component, and the second Bayer matrix is ​​a 4×4 matrix.

[0009] Optionally, the second Bayer matrix is ​​obtained by a standard pattern of 16 gray levels, and the first Bayer matrix M1 is represented by the following formula:

[0010]

[0011] Optionally, M is equal to 24, and N is equal to 16.

[0012] To solve the above problems, an embodiment of the present invention further provides an image conversion device, comprising: an initial image acquisition module, used to acquire an initial image, wherein the initial image is a YUV image; a first conversion module, used to convert the initial image into an intermediate grayscale image, wherein the intermediate grayscale image is an M-bit RGB image; a compensation module, used to convert the intermediate grayscale image into a first target grayscale image, determine whether the information loss of each component of each pixel during conversion is greater than a loss threshold of the component, and compensate for the component whose information loss is greater than the loss threshold; a second conversion module, used to convert the compensated intermediate grayscale image into a second target grayscale image, wherein the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N.

[0013] To solve the above problem, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the image conversion methods are executed.

[0014] To solve the above problems, an embodiment of the present invention further provides an image conversion device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor runs the computer program, the steps of any one of the image conversion methods are executed.

[0015] Compared with the prior art, the technical solution of the embodiment of the present application has the following beneficial effects:

[0016] The image conversion method of the embodiment of the present invention converts the initial image in YUV format into a target grayscale image (i.e., an N-bit RGB image) with a high degree of compression and a small amount of data. In order to avoid local water stains, blurring and other problems that may occur in direct conversion, the initial image in YUV format can be first converted into an intermediate grayscale image (M-bit RGB image) for transition. The data volume of the intermediate grayscale image is larger than that of the target grayscale image, and more information is retained. According to the information loss of each component of each pixel in the intermediate grayscale image and the target grayscale image after direct conversion, it is determined whether each component needs information compensation, and the components that need information compensation are compensated. Then, the compensated intermediate grayscale image is converted into the target grayscale image to overcome the problems of local water stains, blurring and other problems caused by information loss during the conversion process. In this scheme, the compensation of each component of the pixel is performed on the basis of the intermediate grayscale image, rather than directly compensating the components of the converted target grayscale image. The compensation accuracy is higher, and the effect of the converted target grayscale image can be effectively improved.

[0017] Furthermore, the Bayer matrix is ​​introduced as a judgment condition for whether to perform information compensation on the components of the pixel, so as to solve the problem of image distortion such as local "water stains" and blur when the initial image is converted into the target grayscale image. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 A schematic diagram of a flow chart of an image conversion method according to an embodiment of the present invention;

[0019] Figure 2 for Figure 1 A schematic diagram of a specific embodiment of step S103;

[0020] Figure 3 A comparison diagram of the effects of image conversion using the solution of the embodiment of the present invention and image conversion using the prior art;

[0021] Figure 4 The figure is a schematic diagram of the structure of an image conversion device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0022] As mentioned in the background technology, in traditional image conversion methods, when converting high-resolution YUV images into RGB images with a high degree of compression and a small amount of data, image distortion problems such as local "water stains" and blur may occur, affecting the display effect of the converted image.

[0023] To solve the above problems, an embodiment of the present invention provides an image conversion method, including: obtaining an initial image, the initial image is an image in YUV format; converting the initial image into an intermediate grayscale image, the intermediate grayscale image is an M-bit RGB image; converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during conversion is greater than the loss threshold of the component, and compensating for the component whose information loss is greater than the loss threshold; converting the compensated intermediate grayscale image into a second target grayscale image, the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N. In this way, the image distortion problems such as "water stains and blurring" when the YUV image is directly converted into an RGB image with a high degree of compression and a small amount of data can be solved, and the display effect of the converted image can be improved.

[0024] For ease of understanding, the common terms involved in the embodiments of the present invention are explained below.

[0025] 1. YUV is a color encoding method. Y represents brightness, that is, grayscale value. U and V represent chromaticity, which is used to describe the color and saturation of the image and is used to specify the color of the pixel. YUV images are images encoded using the YUV encoding method.

[0026] 2. YUV420SP is a YUV format, which is a two-plane mode, that is, Y and UV are divided into two planes, but UV is stored in an interlaced manner instead of being divided into three planes.

[0027] 3. RGB is a color standard that obtains various colors by changing the three color channels of red (denoted as R), green (denoted as G), and blue (denoted as B) and superimposing them on each other. RGB represents the colors of the three channels of red, green, and blue. RGB images are images that are coded with RGB annotations. RGB images can include RGB565, RGB888, RGB666, etc.

[0028] 4. RGB565 is a color mode, one pixel occupies two bytes. The first 5 bits of the low byte are used to represent B, the last three bits of the low byte and the first three bits of the high byte are used to represent G, and the last 5 bits of the high byte are used to represent R. That is, R occupies 5 bits, G occupies 6 bits, and B occupies 5 bits.

[0029] 5. RGB888 is another color mode. One pixel occupies 3 bytes, R occupies 8 bits, G occupies 8 bits, and B occupies 8 bits. In RGB666, R occupies 6 bits, G occupies 6 bits, and B occupies 6 bits.

[0030] 6. Bayer matrix (also called Bayer array) is a common method used to collect digital images when Charge Coupled Device (CCD) or Complementary Metal-Oxide-Semiconductor (CMOS) devices are used as light sensors. The Bayer matrix is ​​generally formed by multiple identical 2×2 matrices, in which there is 1 R, 1 B, and 2 G. A 2×2 matrix is ​​recorded as a pixel. At this time, each pixel in the Bayer matrix has 1 / 4 R, 1 / 4 B, and 1 / 2 G, so only 1 / 3 of the content is real.

[0031] 7. libYUV is an open source library from Google that implements various YUV and RGB conversion, rotation, and scaling. libYUV is cross-platform and supports Windows, Linux, Mac, Android and other operating systems.

[0032] In order to make the above-mentioned objects, features and beneficial effects of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0033] See also Figure 1 , Figure 1 A flow chart of an image conversion method provided in an embodiment of the present invention is provided. The method is executed by a terminal, and the terminal may include a device such as a smart phone, a computer, a tablet computer or a smart watch. In particular, the terminal is a device including a camera for capturing images. The method includes the following steps S101 to S104, which are described in detail as follows.

[0034] Step S101, obtaining an initial image, wherein the initial image is an image in a YUV format.

[0035] The initial image is an image captured by an image capturing device, and the resolution of the initial image is generally high and the data volume is large. For example, the initial image is acquired by a camera of a smartphone or a computer, or by a camera.

[0036] Step S102: converting the initial image into an intermediate grayscale image, wherein the intermediate grayscale image is an M-bit RGB image.

[0037] The intermediate grayscale image is a grayscale image used as an intermediate transition in the process of converting the initial image (YUV image) into the target grayscale image (an RGB image with a small amount of data and a low resolution). The data amount of the intermediate grayscale image is larger than that of the target grayscale image and the resolution is higher. Optionally, the intermediate grayscale image can be an RGB888 image or an RGB666 image, etc.

[0038] Step S103, converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during the conversion is greater than the loss threshold of the component, and compensating for the component whose information loss is greater than the loss threshold.

[0039] The first target grayscale image and the second target grayscale image are target grayscale images obtained by converting the intermediate grayscale image twice. The first target grayscale image is used to determine the information loss during the conversion process, and the second target grayscale image is the target grayscale image obtained by conversion.

[0040] When the intermediate grayscale image is converted to the first target grayscale image, the pixels in the two images before and after the conversion correspond to each other, and the intermediate grayscale image and the first target grayscale image both contain R component, G component and B component. The information loss of each component of each pixel during the conversion includes: for each pixel, the information loss of the R component, the information loss of the G component and the information loss of the B component during the conversion.

[0041] For a single pixel, the information loss of the R component during conversion includes: the difference between the pixel value of the R component in the intermediate grayscale image of this pixel and the pixel value of the R component in the first target grayscale image. The loss threshold of the R component is the threshold corresponding to the R component.

[0042] For a single pixel, the information loss of the G component during conversion includes: the difference between the pixel value of the G component in the intermediate grayscale image of this pixel and the pixel value of the G component in the first target grayscale image. The loss threshold of the G component is the threshold corresponding to the G component.

[0043] For a single pixel, the information loss of the B component during conversion includes: the difference between the pixel value of the B component in the intermediate grayscale image of this pixel and the pixel value of the B component in the first target grayscale image. The loss threshold of the B component is the threshold corresponding to the B component.

[0044] For a single pixel, if the information loss of one or more components during conversion is greater than the loss threshold of the component, it means that the information loss of the component is large during the image conversion process, which may cause information loss and affect the display effect of the converted image (i.e., the first target grayscale image). Therefore, information compensation can be performed on the intermediate grayscale image for the components with large information loss of each pixel during conversion.

[0045] Step S104: converting the compensated intermediate grayscale image into a second target grayscale image, wherein the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N.

[0046] After obtaining the compensated intermediate grayscale image, it is converted into an N-bit RGB image, that is, the second target grayscale image, as the final conversion result.

[0047] Optionally, converting the compensated intermediate grayscale image into a second target grayscale image may include: for the compensated intermediate grayscale image, sequentially acquiring individual pixels therein, taking each component in the acquired pixels as the current component in turn, setting the lower L bits of the value of the current component to zero, and shifting the value of the current component left by L bits to obtain the value of the corresponding component in the second target grayscale image; wherein, for the current pixel, the number of bits of the current component value is L bits more than the number of bits of the corresponding component value in the second target grayscale image, and L is a positive integer.

[0048] For example, when the compensated intermediate grayscale image - RGB888 image is converted to the second target grayscale image - RGB565 image, each pixel in RGB888 is obtained in turn, and for each pixel: the lower 3 bits of the value of the R component of the pixel (that is, the pixel value of the component) are set to zero and shifted left by 3 bits; the lower 2 bits of the value of the G component of the pixel (that is, the pixel value of the component) are set to zero and shifted left by 2 bits; the lower 3 bits of the value of the B component of the pixel (that is, the pixel value of the component) are set to zero and shifted left by 3 bits.

[0049] If the compensated intermediate grayscale image or the second target grayscale image is other RGB images, L may take other values.

[0050] pass Figure 1The method described above converts the initial image in YUV format into a target grayscale image (i.e., an N-bit RGB image) with a high degree of compression and a small amount of data. In order to avoid local water stains, blurring, and other problems that may occur in direct conversion, the initial image in YUV format can be first converted into an intermediate grayscale image for transition. The data volume of the intermediate grayscale image is larger than that of the target grayscale image, and more information is retained. According to the information loss of each component of each pixel in the intermediate grayscale image and the target grayscale image after direct conversion, it is determined whether each component needs information compensation, and the components that need information compensation are compensated. Then, the compensated intermediate grayscale image is converted into the target grayscale image to overcome the problems of local water stains, blurring, etc. caused by information loss during the conversion process. In this scheme, the compensation of each component of the pixel is performed on the basis of the intermediate grayscale image, rather than directly compensating the components of the converted target grayscale image. The compensation accuracy is higher, and the effect of the converted target grayscale image (i.e., the second target grayscale image) can be effectively improved.

[0051] In a specific application scenario, the first terminal converts the collected analog signal (i.e., YUV image) into a digital signal and outputs an RGB image (i.e., a target grayscale image), such as an RGB565 image, and the second terminal uses the RGB565 format for rendering and display. The RGB565 image has a small amount of data, which can save the occupied bandwidth and improve the efficiency of image transmission. The first terminal and the second terminal can be the same terminal or different terminals. For example, after the first terminal collects the YUV image, it converts it into an RGB image and sends the RGB image to the second terminal, which renders the RGB image and displays it.

[0052] In another specific application scenario, the target grayscale image (RGB image, such as RGB565 image) is a thumbnail of the initial image (YUV image), which corresponds one-to-one to the initial image. Thumbnails of multiple initial images can be displayed on the same display page of the terminal to facilitate users to view multiple initial images on the terminal.

[0053] In a specific embodiment of the above two application scenarios, the initial image is a YUV420SP image, the intermediate grayscale image is an RGB888 image, and the target grayscale image (including the first target grayscale image and the second target grayscale image) is an RGB565 image.

[0054] In one embodiment, see Figure 2 , Figure 2 for Figure 1 FIG. 1 is a schematic diagram of a specific embodiment of step S103 in FIG. 1 , where step S103 may include steps A to F, which are described in detail as follows.

[0055] Step A, obtaining the first pixel in the intermediate grayscale image as the current pixel.

[0056] Step B: for the current pixel, sequentially obtain each component as the current component.

[0057] That is, for the intermediate grayscale image, one pixel is processed each time, and the pixel processed each time is used as the current pixel. Each time a component of the current pixel is obtained as the current component, and through the following steps C to E, it is determined whether the current component of the current pixel needs to be compensated. After traversing all components of the current pixel, the determination of the current pixel is completed.

[0058] Step C: adjusting the value of the current component to the number of bits of the corresponding component of the first target grayscale image to obtain the value of the corresponding component in the first target grayscale image.

[0059] When converting an M-bit RGB image (i.e., an intermediate grayscale image) into an N-bit RGB image (i.e., a first target grayscale image), the bit number of each current component in the M-bit RGB image is adjusted to the bit number of the corresponding component in the N-bit RGB image.

[0060] For example, an M-bit RGB image is an RGB888 image, and its R component, G component, and B component all occupy 8 bits. An N-bit RGB image is an RGB565 image, and its R component and B component each occupy 5 bits, and the G component occupies 6 bits. If the R component of the current pixel in the RGB888 image is the current component, the value of the current component is adjusted to the number of bits of the corresponding component of the first target grayscale image (i.e., the RGB565 image), including: adjusting the 8-bit value of the R component of the current pixel to a 5-bit value, that is, removing 3 bits of the pixel value of the R component in the current pixel.

[0061] Further, in the example of converting the intermediate grayscale image - RGB888 image to the first target grayscale image - RGB565 image, adjusting the 8-bit value of the R component of the current pixel to a 5-bit value can be done in at least the following two ways:

[0062] Method 1: The lowest 3 bits of the pixel value of the R component in the current pixel can be set to zero, and the pixel value of the R component after being set to zero can be shifted left by 3 bits to obtain the pixel value of the R component of the corresponding pixel in the first target grayscale image.

[0063] Method 2: The pixel value of the lowest 3 bits of the pixel value of the R component in a single pixel ranges from 0 to 7. It can be determined whether the pixel value of the lowest 3 bits of the pixel value of the R component in the current pixel is greater than the median of its value range, that is, 3.5. If it is greater than the median, while setting the values ​​of the lowest 3 bits of the pixel value of the R component in the current pixel to zero, add 1 to the 4th bit of the pixel value of the R component in the current pixel from low to high to obtain the pixel value of the R component of the corresponding pixel in the first target grayscale image.

[0064] It should be noted that the above is an example of processing the pixel value of the R component when converting the intermediate grayscale image - RGB888 image to the first target grayscale image - RGB565 image. In actual use, the number of bits occupied by each component in the intermediate grayscale image and the first target grayscale image can be other values. The processing ideas for each component of each pixel refer to the processing ideas for the R component in the above example, that is:

[0065] Figure 2 Step C in the step of adjusting the value of the current component to the number of bits of the corresponding component of the first target grayscale image to obtain the value of the corresponding component in the first target grayscale image may include: setting the low L bits of the value of the current component to zero, and shifting the value of the current component left by L bits to obtain the value of the corresponding component in the first target grayscale image; wherein, for the current pixel, the number of bits of the value of the current component is L bits more than the number of bits of the value of the corresponding component in the first target grayscale image, and L is a positive integer.

[0066] In the example of converting the intermediate grayscale image - RGB888 image to the first target grayscale image - RGB565 image, the L value corresponding to the R and B components is 3, and the L value corresponding to the G component is 2. The processing of the R component refers to the above method 1, and the processing idea of ​​the G and B components is the same, which will not be repeated here.

[0067] Step D, calculating the difference between the value of the current component and the value of the corresponding component in the first target grayscale image as the information loss of the current component.

[0068] Specifically, the difference between the value of the R component in the current pixel (i.e., the pixel value of the R component) and the value of the corresponding component in the first target grayscale image (i.e., the pixel value of the R component after conversion) is recorded as the information loss of the R component in the current pixel. The difference between the value of the G component in the current pixel (i.e., the pixel value of the G component) and the value of the corresponding component in the first target grayscale image (i.e., the pixel value of the G component after conversion) is recorded as the information loss of the G component in the current pixel. The difference between the value of the B component in the current pixel (i.e., the pixel value of the B component) and the value of the corresponding component in the first target grayscale image (i.e., the pixel value of the B component after conversion) is recorded as the information loss of the B component in the current pixel.

[0069] Step E: If the information loss of the current component is greater than the loss threshold of the current component, information compensation is performed on the current component.

[0070] Optionally, if the information loss of the current component is not greater than the loss threshold of the current component, no information compensation is performed on the current component.

[0071] In a specific embodiment, in the example of converting the intermediate grayscale image-RGB888 image to the first target grayscale image-RGB565 image, if the current component G component of the current pixel is recorded as "0xFC" in hexadecimal, when it is converted to 6 bits, the lower 2 bits of "0xFC" are first set to zero, and then shifted left by 2 bits. The value of the corresponding G component in the first target grayscale image obtained is recorded as high_var, and the information loss generated is recorded as low_var. If the information loss low_var is greater than the loss threshold thr_g of the G component, the current component is compensated for information, for example, a preset value can be added to the value of the current component.

[0072] Furthermore, if the information loss of the current component is greater than the loss threshold of the current component, and it can also be determined whether the value of the corresponding component in the first target grayscale image is less than the maximum value of the component, if these two conditions are met, information compensation is performed on the current component.

[0073] For example, if the first target grayscale image is an RGB565 image, the maximum value of the 6-bit G component is (2 6 -1)=63, if the information loss low_var is greater than the loss threshold thr_g of the G component, and high_var is less than 63, information compensation is performed on the current component.

[0074] If the current component is the R or B component, if the current component R / B component of the current pixel is recorded as "0XF8" in hexadecimal, when it is converted to 6 bits, first set the lower 2 bits of "0XF8" to zero and shift it left by 2 bits. The value of the corresponding R / B component in the first target grayscale image is recorded as high_var, and the resulting information loss is recorded as low_var. If the information loss low_var is greater than the loss threshold thr_rb of the R / B component, the current component is compensated for information, for example, a preset value can be added to the value of the current component. The maximum value of the 5-bit R / B component is (2 5 -1)=31, if the information loss low_var is greater than the loss threshold thr_rb of the R / B component, and high_var is less than 31, information compensation is performed on the current component.

[0075] Optionally, performing information compensation on the current component may include: adding a preset value to the value of the current component.

[0076] Specifically, adding a preset value to the value of the current component means adding the preset value to the pixel value (referred to as the value of the component) of the component to be compensated for information of the pixel (i.e., the current component), and calculating the sum of the two. Optionally, the preset value can be 1 or 2 or other numerical values, which can be determined as needed. The preset values ​​for compensating the same component of different pixels can be the same or different. The preset values ​​for compensating different components of the same pixel can be the same or different.

[0077] Step F, obtaining the next pixel in the intermediate grayscale image as the current pixel, and ending if all pixels in the intermediate grayscale image are traversed.

[0078] In this embodiment, it is provided Figure 1 A detailed execution flow of step S103 is provided, which traverses each component of each pixel to accurately determine whether each component of each pixel in the intermediate grayscale image needs information compensation, and adds a preset value to the corresponding component of the pixel that needs compensation to achieve information compensation.

[0079] In one embodiment, the current component includes an R component, a G component and a B component, the initial image forms a Bayer image, and the step of generating the loss threshold of the current component may include: obtaining a pixel value corresponding to the current pixel in a standard pattern of a first Bayer matrix, recorded as a loss threshold of the G component, and the first Bayer matrix is ​​a 2×2 matrix; obtaining a pixel value corresponding to the current pixel in a second Bayer matrix standard pattern, recorded as a loss threshold of the R component and the B component, and the second Bayer matrix is ​​a 4×4 matrix.

[0080] The position of each pixel in the intermediate grayscale image in the frame image can be represented by the row coordinates and column coordinates of the pixel, the row coordinate is marked as x, the column coordinate is marked as y, then the current pixel can be recorded as (x, y), and the value range of x and y is determined according to the number of pixels in the intermediate grayscale image. In this embodiment, the Bayer matrix (including the first Bayer matrix and the second Bayer matrix) is used to calculate the loss thresholds corresponding to the R component, the G component and the B component of each pixel (x, y), respectively, the loss thresholds of the R component and the B component are recorded as thr_rb, and the loss threshold of the G component is recorded as thr_g.

[0081] Therefore, the Bayer matrix is ​​introduced as a judgment condition for whether to compensate the information of the pixel components, so as to solve the problem of image distortion such as local "water stains" and blur when the initial image is converted into the target grayscale image.

[0082] Traditionally, the working principle of dithering the pixels of an image (also known as pixel value compensation) is to simply add a pseudo-random value to each pixel before reducing the number of bits of each color. This value can switch to the next color value according to the correct proportion of pixels within the range of color accuracy loss, so that the image produces a better gradient effect. The embodiment of the present invention uses the Bayer matrix as a basis for judging the dither value (that is, whether the pixel value needs to be compensated), which has a better image display effect than the traditional dithering method.

[0083] In a specific embodiment, the first Bayer matrix is ​​a 2×2 Bayer matrix, and the second Bayer matrix is ​​a 4×4 Bayer matrix. The first Bayer matrix is ​​denoted as M1, which can be expressed as the following formula (1), and the second Bayer matrix is ​​denoted as M2. Optionally, the second Bayer matrix M2 is obtained by a standard pattern M with 16 gray levels (see formula (2)). Optionally, some or all parameters in the matrix M can be adjusted to obtain the matrix M2. The standard pattern M with 16 gray levels is calculated by an algorithm for designing a standard pattern proposed by Limb.

[0084]

[0085]

[0086] Assuming the unit matrix is ​​denoted as U, it can be expressed as formula (3):

[0087]

[0088] The matrix M in the above formula (2) can be obtained by referring to the following formula (4):

[0089]

[0090] Substituting the matrix M1 in formula (1) and the matrix U in formula (3) into formula (4), the matrix M in the above formula (2) can be obtained after expansion.

[0091] The row coordinate x of the current pixel is operated modulo 2, the column coordinate y is operated modulo 2 and shifted left by 1 bit, and then added to find the pixel value corresponding to the standard pattern of the current pixel in the first Bayer matrix M1, recorded as thr_g; the row coordinate x of the current pixel is operated modulo 4, the column coordinate y is operated modulo 4 and shifted left by 2 bits, to find the pixel value corresponding to the standard pattern of the current pixel in the second Bayer matrix M2, recorded as thr_rb.

[0092] Thus, it is possible to use separate matrices for different color channels, which in turn improves the image display quality. Introducing the separation of color channels can make the image have a smoother transition.

[0093] See also Figure 3 , Figure 3 The figure is a comparison diagram of image conversion effects according to an embodiment of the present invention. Figure 3 The left picture A in the figure shows the display effect of an N-bit RGB image obtained using the patented algorithm. Figure 3 The middle right image B shows the display effect of an N-bit RGB image obtained by image conversion using existing tools (such as Google's libYUV). Comparing the two, it can be clearly seen that there is a more obvious water stain in the right image B. The water stain is Figure 3 The area corresponding to the dotted box 301 and the dotted box 302.

[0094] In one embodiment, see Figure 4 , Figure 4 The present invention is a schematic diagram of an image conversion device 40 according to an embodiment of the present invention, which may include: an initial image acquisition module 401, used to acquire an initial image, wherein the initial image is a YUV image; a first conversion module 402, used to convert the initial image into an intermediate grayscale image, wherein the intermediate grayscale image is an M-bit RGB image; a compensation module 403, used to convert the intermediate grayscale image into a first target grayscale image, determine whether the information loss of each component of each pixel during conversion is greater than a loss threshold of the component, and compensate for the component whose information loss is greater than the loss threshold; a second conversion module 404, used to convert the compensated intermediate grayscale image into a second target grayscale image, wherein the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N.

[0095] In one embodiment, Figure 4The compensation module 403 in may include: a current pixel acquisition unit, used to execute step A, to acquire the first pixel in the intermediate grayscale image as the current pixel; a current component acquisition unit, used to execute step B, for the current pixel, to sequentially acquire each component as the current component; a first bit adjustment unit, used to execute step C, to adjust the value of the current component to the bit number of the corresponding component of the first target grayscale image, and obtain the value of the corresponding component in the first target grayscale image; a loss calculation unit, used to execute step D, to calculate the difference between the value of the current component and the value of the corresponding component in the first target grayscale image as the information loss of the current component; a compensation unit, used to execute step E, if the information loss of the current component is greater than the loss threshold of the current component, then perform information compensation on the current component; a loop unit, used to execute step F, to acquire the next pixel in the intermediate grayscale image as the current pixel, and continue to execute steps B to D until all pixels in the intermediate grayscale image are traversed.

[0096] In one embodiment, the first bit adjustment unit is also used to set the lower L bits of the value of the current component to zero, and shift the value of the current component left by L bits to obtain the value of the corresponding component in the first target grayscale image; wherein, for the current pixel, the number of bits of the value of the current component is L bits more than the number of bits of the value of the corresponding component in the first target grayscale image, and L is a positive integer.

[0097] In one embodiment, the compensation unit is further configured to add a preset value to the value of the current component.

[0098] In one embodiment, the current component includes an R component, a G component and a B component, and the image conversion device 40 may further include: a first threshold determination module, used to obtain the pixel value corresponding to the current pixel in the standard pattern of the first Bayer matrix, recorded as the loss threshold of the G component, and the first Bayer matrix is ​​a 2×2 matrix; a second threshold determination module, used to obtain the pixel value corresponding to the current pixel in the standard pattern of the second Bayer matrix, recorded as the loss threshold of the R component and the B component, and the second Bayer matrix is ​​a 4×4 matrix.

[0099] Optionally, the second Bayer matrix is ​​obtained by a standard pattern of 16 gray levels, and the first Bayer matrix M1 is represented by the following formula:

[0100]

[0101] Optionally, M is equal to 24, and N is equal to 16.

[0102] For more information about the working principle and working method of the image conversion device 40, please refer to Figures 1 to 3The relevant description of the image conversion method will not be repeated here.

[0103] In a specific implementation, the above-mentioned image conversion device 40 can correspond to a chip with an image processing function in a terminal, or to a chip with a data processing function, such as a system-on-a-chip (SOC), a radio frequency chip, etc.; or to a chip module in the terminal that includes a chip with an image processing function; or to a chip module with a chip with a data processing function, or to a terminal.

[0104] Regarding the various modules / units included in the various devices and products described in the above embodiments, they can be software modules / units, or hardware modules / units, or they can be partially software modules / units and partially hardware modules / units. For example, for various devices and products applied to or integrated in a chip, the various modules / units included therein can all be implemented in the form of hardware such as circuits, or at least some of the modules / units can be implemented in the form of software programs, which run on a processor integrated inside the chip, and the remaining (if any) modules / units can be implemented in the form of hardware such as circuits; for various devices and products applied to or integrated in a chip module, the various modules / units included therein can all be implemented in the form of hardware such as circuits, and different modules / units can be located in the same component (such as a chip, circuit module, etc.) or different components of the chip module, or at least some of the modules / units can be implemented in the form of hardware such as circuits. The element can be implemented in the form of a software program, which runs on a processor integrated inside the chip module, and the remaining (if any) modules / units can be implemented in the form of hardware such as circuits; for various devices and products applied to or integrated in the terminal, the various modules / units contained therein can be implemented in the form of hardware such as circuits, and different modules / units can be located in the same component (for example, chip, circuit module, etc.) or in different components in the terminal, or, at least some modules / units can be implemented in the form of a software program, which runs on a processor integrated inside the terminal, and the remaining (if any) modules / units can be implemented in the form of hardware such as circuits.

[0105] The embodiment of the present invention further provides a storage medium having a computer program stored thereon, wherein the computer program is executed when the processor is running. Figures 1 to 3 The steps of the image conversion method. The storage medium may be a computer-readable storage medium, for example, may include a non-volatile memory or a non-transitory memory, and may also include an optical disk, a mechanical hard disk, a solid-state hard disk, etc.

[0106] The embodiment of the present invention further provides an image conversion device, which may include a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and the processor executes the computer program when running the computer program. Figures 1 to 3 The steps of the image conversion method.

[0107] Specifically, in the embodiment of the present invention, the processor may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0108] It should also be understood that the memory in the embodiments of the present application may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM) and direct rambus RAM (DR RAM).

[0109] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article indicates that the associated objects before and after are in an "or" relationship.

[0110] The "plurality" appearing in the embodiments of the present application refers to two or more.

[0111] The first, second, etc. descriptions appearing in the embodiments of the present application are only used for illustration and distinction of the description objects. There is no order, nor do they indicate any special limitation on the number of devices in the embodiments of the present application, and cannot constitute any limitation on the embodiments of the present application.

[0112] The "connection" that appears in the embodiments of the present application refers to various connection methods such as direct connection or indirect connection to achieve communication between devices, and the embodiments of the present application do not impose any limitations on this.

[0113] Although the present invention is disclosed as above, the present invention is not limited thereto. Any person skilled in the art can make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the scope defined by the claims.

Claims

1. An image conversion method, characterized in that: The method comprises: Acquire an initial image, where the initial image is a YUV image; Converting the initial image into an intermediate grayscale image, wherein the intermediate grayscale image is an M-bit RGB image; Converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during the conversion is greater than a loss threshold of the component, and compensating for the component whose information loss is greater than the loss threshold; Converting the compensated intermediate grayscale image into a second target grayscale image, wherein the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N; The step of determining whether the information loss of each component of each pixel during conversion is greater than a loss threshold of the component, and compensating the component whose information loss is greater than the loss threshold, includes: Step A, obtaining the first pixel in the intermediate grayscale image as the current pixel; Step B, for the current pixel, sequentially obtaining each component as the current component; Step C, adjusting the value of the current component to the bit number of the corresponding component of the first target grayscale image, to obtain the value of the corresponding component in the first target grayscale image; Step D, calculating the difference between the value of the current component and the value of the corresponding component in the first target grayscale image as the information loss of the current component; Step E: if the information loss of the current component is greater than the loss threshold of the current component, information compensation is performed on the current component; Step F, obtaining the next pixel in the intermediate grayscale image as the current pixel, and continuing to execute steps B to D until all pixels in the intermediate grayscale image are traversed.

2. The method according to claim 1, characterized in that The step of adjusting the value of the current component to the number of bits of the component corresponding to the first target grayscale image to obtain the value of the component corresponding to the first target grayscale image includes: Set the low L bits of the value of the current component to zero, and shift the value of the current component left by L bits to obtain the value of the corresponding component in the first target grayscale image; Among them, for the current pixel, the number of bits of the value of the current component is L bits more than the number of bits of the value of the corresponding component in the first target grayscale image, and L is a positive integer.

3. The method according to claim 1, characterized in that The performing information compensation on the current component includes: A preset value is added to the value of the current component.

4. The method according to any one of claims 1 to 3, characterized in that: The current component includes an R component, a G component and a B component, and the step of generating the loss threshold of the current component includes: Obtaining a pixel value corresponding to the current pixel in a standard pattern of a first Bayer matrix, recorded as a loss threshold of a G component, where the first Bayer matrix is ​​a 2×2 matrix; A pixel value corresponding to the current pixel in a second Bayer matrix standard pattern is obtained, which is recorded as a loss threshold of an R component and a B component, and the second Bayer matrix is ​​a 4×4 matrix.

5. The method according to claim 4, characterized in that The second Bayer matrix is ​​obtained by a standard pattern of 16 gray levels, and the first Bayer matrix M1 is represented by the following formula: 。 6. The method according to any one of claims 1 to 3, characterized in that: The M is equal to 24, and the N is equal to 16.

7. An image conversion device, characterized in that: include: An initial image acquisition module, used to acquire an initial image, wherein the initial image is a YUV image; A first conversion module, used for converting the initial image into an intermediate grayscale image, wherein the intermediate grayscale image is an M-bit RGB image; a compensation module, used for converting the intermediate grayscale image into a first target grayscale image, determining whether the information loss of each component of each pixel during the conversion is greater than a loss threshold of the component, and compensating for the component whose information loss is greater than the loss threshold; A second conversion module is used to convert the compensated intermediate grayscale image into a second target grayscale image, wherein the first target grayscale image and the second target grayscale image are N-bit RGB images, wherein M and N are both positive integers, and the value of M is greater than N; The step of determining whether the information loss of each component of each pixel during conversion is greater than a loss threshold of the component, and compensating the component whose information loss is greater than the loss threshold, includes: Step A, obtaining the first pixel in the intermediate grayscale image as the current pixel; Step B, for the current pixel, sequentially obtaining each component as the current component; Step C, adjusting the value of the current component to the bit number of the corresponding component of the first target grayscale image, to obtain the value of the corresponding component in the first target grayscale image; Step D, calculating the difference between the value of the current component and the value of the corresponding component in the first target grayscale image as the information loss of the current component; Step E: if the information loss of the current component is greater than the loss threshold of the current component, information compensation is performed on the current component; Step F, obtaining the next pixel in the intermediate grayscale image as the current pixel, and continuing to execute steps B to D until all pixels in the intermediate grayscale image are traversed.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are performed.

9. An image conversion device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor runs the computer program, the steps of the method according to any one of claims 1 to 6 are performed.

Citation Information

Patent Citations

  • Image ripple processing method

    CN110473240A

  • Imaging apparatus

    US20050062854A1