Image processing methods, apparatus, devices and storage media
By converting the image from RGBA8888 format to RGBA5658 format and dividing it into first and second pixel groups for encoding, the problem of high resource consumption in the prior art is solved, and a more efficient encoding and decoding process is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN BLUETRUM TECH CO LTD
- Filing Date
- 2023-11-28
- Publication Date
- 2026-04-17
AI Technical Summary
Existing image encoding and decoding methods in embedded systems require converting RGBA5658 format images to RGBA8888 format before processing, which increases system resource consumption and reduces encoding and decoding efficiency.
The image to be encoded is converted from a first image format to a second image format, divided into first and second pixel groups, and encoded separately. Finally, the encoded data is combined to reduce memory usage and lower system resource consumption.
By reducing memory usage, system resource consumption is lowered, encoding and decoding efficiency is improved, and system space is saved.
Smart Images

Figure CN117640966B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image coding technology, and in particular to image processing methods, apparatus, devices and storage media. Background Technology
[0002] Existing image encoding and decoding methods are based on processing images in RGBA8888 or RGB888 format. In embedded systems, to reduce image resource consumption, RGBA5658 or RGB565 format images are often used. Compared to RGBA8888 format, RGBA5658 can reduce data storage space by one-third. However, when processing RGBA5658 images, existing encoding and decoding methods usually convert the RGBA5658 format image to RGBA8888 format before processing, which requires more storage space to store the encoded data, increasing the system's resource consumption. Summary of the Invention
[0003] This application provides an image processing method, apparatus, device, and storage medium to solve the technical problem of high resource consumption when encoding and decoding images in embedded systems.
[0004] Firstly, an image processing method is provided, the image processing method comprising:
[0005] The first image to be encoded is converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded.
[0006] The k pixel rows in the second image to be encoded are divided into first pixel groups and second pixel groups, respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel.
[0007] The pixel values of k first pixels are encoded using preset first encoding information to obtain k first encoded data;
[0008] Based on the pixel parameters corresponding to the k second pixel groups, determine the k second encoding information;
[0009] The k groups of second pixels are encoded using the corresponding second encoding information to obtain k second encoded data.
[0010] The k first encoded data are combined with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows.
[0011] In this technical solution, the first image to be encoded can be converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is smaller than that occupied by the first image to be encoded. The second image to be encoded is divided into k first pixels and k second pixels, and the k first pixels and k second pixels are encoded respectively. Finally, the obtained encoded data are combined to obtain the encoded data corresponding to the second image to be encoded. Thus, the second image to be encoded with low memory space can be directly encoded, reducing the memory occupation when encoding the image, thereby reducing the system resource consumption rate.
[0012] In one possible implementation, determining the k second encoded information based on the pixel parameters corresponding to the k second pixel groups includes:
[0013] Extract the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, wherein the target pixel group is any one of the k second pixel groups;
[0014] Based on the pixel parameters and pixel values corresponding to the n second pixels, the encoding information corresponding to the n second pixels is determined, and the second encoding information of the target pixel group is obtained.
[0015] Repeat the above process of extracting the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, determining the encoding information corresponding to the n second pixels based on the pixel parameters and pixel values of the n second pixels, and obtaining the second encoding information of the target pixel group, until the encoding information corresponding to k second pixel groups is obtained, thus obtaining k second encoding information.
[0016] In one possible implementation, determining the encoding information corresponding to each of the n second pixels based on the pixel parameters and pixel values corresponding to the n second pixels, to obtain the second encoding information of the target pixel group, includes:
[0017] Determine whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, then determine the encoding information of the previous pixel as the encoding information of the target second pixel. The target second pixel is any one of n second pixels.
[0018] If they are the same, the encoding information corresponding to the second pixel of the target is determined based on the pixel value of the second pixel of the target and the pixel value of the previous second pixel.
[0019] Repeat the above process of determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, the encoding information of the previous pixel is determined as the encoding information of the target second pixel. If they are the same, the encoding information corresponding to the target second pixel is determined based on the pixel value of the target second pixel and the pixel value of the previous pixel. This process continues until the encoding information corresponding to each of the n second pixels is obtained, thus obtaining the second encoding information of the target pixel group.
[0020] In one possible implementation, determining the encoding information corresponding to the target second pixel based on the pixel value of the target second pixel and the pixel value of the previous second pixel includes:
[0021] If the pixel value of the second pixel of the target is the same as the pixel value of the previous pixel, then the encoding information corresponding to the second pixel of the target is determined to be the first sub-encoding information.
[0022] If they are different, then obtain the difference in the RGB channels between the pixel value of the target second pixel and the pixel value of the previous second pixel;
[0023] The encoding information of the target second pixel is determined based on the difference between the RGB channels.
[0024] In one possible implementation, determining the encoding information of the target second pixel based on the difference between the RGB channels includes:
[0025] Determine whether the difference between the RGB channels is within a preset channel difference range. If so, determine that the encoding information corresponding to the target second pixel is the second sub-encoding information.
[0026] If not, then the encoding information corresponding to the second pixel of the target is determined to be the third sub-encoding information. The third sub-encoding information is different from the second sub-encoding information, and the length of the encoding data corresponding to the second sub-encoding information is less than the length of the encoding data corresponding to the third sub-encoding information.
[0027] In one possible implementation, the storage method of the encoded data corresponding to the k rows of pixels is the same as the storage method of the second image to be encoded.
[0028] In one possible implementation, after combining the k first encoded data with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows, the method further includes:
[0029] A pixel row identifier table is determined, which includes the starting position information and the identifier information of each pixel row in the encoded data;
[0030] When constructing the compressed data packet corresponding to the first image to be encoded, the pixel row identifier table is placed between the encoded data and the header data;
[0031] When decoding the compressed data packet, the starting position information corresponding to the target pixel row is extracted from the pixel identification table using the identification information of the target pixel row to be decoded.
[0032] Extract the encoded data corresponding to the target pixel row based on the starting position information;
[0033] The encoded data corresponding to the row of target pixels is decoded to obtain decoded data.
[0034] In a second aspect, an image processing apparatus is provided, the image processing apparatus comprising:
[0035] The conversion unit is used to convert the first image to be encoded from a first image format to a second image format to obtain a second image to be encoded, wherein the memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded.
[0036] The partitioning unit is used to divide the k pixel rows in the second image to be encoded into first pixel groups and second pixel groups respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel.
[0037] The first encoding unit is used to encode the pixel values of k first pixels using preset first encoding information to obtain k first encoded data.
[0038] The determining unit is used to determine k second encoding information based on the pixel parameters corresponding to the k second pixel point groups respectively;
[0039] The second encoding unit is used to encode the k groups of second pixels using the corresponding second encoding information to obtain k second encoded data.
[0040] The processing unit is used to combine k first encoded data with the corresponding second encoded data to obtain encoded data corresponding to k pixel rows.
[0041] Thirdly, a computer device is provided, including a memory, a communication interface, and one or more processors, wherein the memory and the communication interface are connected to the one or more processors, and the one or more processors are configured to execute one or more computer programs stored in the memory, wherein when the one or more processors execute the one or more computer programs, the computer device implements the image processing method of the first aspect described above.
[0042] Fourthly, a computer-readable storage medium is provided, which stores a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the image processing method of the first aspect.
[0043] This application can achieve the following technical effects: it can directly encode a second image with low memory space usage, reducing memory usage during image encoding and thus reducing system resource usage. Attached Figure Description
[0044] Figure 1 A schematic flowchart of an image processing method provided in an embodiment of this application;
[0045] Figure 2 This application provides a schematic diagram of pixel division.
[0046] Figure 3 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application;
[0047] Figure 4 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0048] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0049] To better understand the image processing method provided in this application embodiment, a brief introduction to existing image processing methods is given below. In embedded systems, to reduce image resource consumption, images in RGBA5658 or RGB565 format are often used. Therefore, RGBA8888 or RGB888 format images are converted to RGBA5658 or RGB565 format images and stored to reduce resource consumption in embedded systems. However, in existing solutions, when encoding and decoding images in RGBA5658 or RGB565 format in embedded systems, it is usually necessary to convert the RGBA5658 format image (using RGBA5658 format as an example here) to RGBA8888 format before encoding and decoding. At this time, the encoding and decoding process is based on the RGBA8888 format image. However, the memory space occupied by the RGBA8888 format image is much larger than that occupied by the RGBA5658 format image. This causes the system space occupancy rate of the embedded system to increase sharply during image encoding and decoding, thereby reducing the number of images that can be encoded and decoded at one time, reducing efficiency. At the same time, the increased system space occupancy rate also reduces the system space available for data processing, further reducing the encoding and decoding efficiency.
[0050] This application aims to solve the above-mentioned problems and proposes an image processing method. A first image to be encoded can be converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is less than that occupied by the first image to be encoded. The second image to be encoded is divided into k first pixels and k second pixels, and each of the k first pixels and k second pixels is encoded. Finally, the resulting encoded data is combined to obtain the encoded data corresponding to the second image to be encoded. This method allows for direct encoding of the second image to be encoded, which has a low memory footprint, reducing memory usage during image encoding and thus lowering system resource consumption.
[0051] This application provides an image processing method that can be applied to electronic devices or servers. The electronic devices can be, but are not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The invention will now be described in detail through specific embodiments.
[0052] See Figure 1 , Figure 1 This is a flowchart illustrating an image processing method provided in an embodiment of this application. This method can be applied to electronic devices or servers, such as... Figure 1 As shown, the method includes the following steps:
[0053] S101. Convert the first image to be encoded from the first image format to the second image format to obtain the second image to be encoded. The memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded.
[0054] The first image to be encoded can be any image requiring encoding processing, and it can be a color image, etc. The first image format can be either RGBA8888 or RGB888. If the first image format is RGBA8888, the converted second image to be encoded will have a second image format of RGBA5658; if the first image format is RGB888, the converted second image to be encoded will have a second image format of RGB565. The second image to be encoded in RGBA5658 format occupies one-third less memory space than the first image to be encoded in RGBA5658 format. Therefore, this significantly reduces the memory space occupied by the image during subsequent encoding and decoding, thus reducing system resource consumption.
[0055] Of course, the above steps can be performed in advance. For example, when storing the first image to be encoded, the first image to be encoded can be converted into a second image to be encoded to reduce its memory footprint. Therefore, the second image to be encoded with the second image format can be directly obtained for subsequent encoding processing.
[0056] S102. Divide the k pixel rows in the second image to be encoded into first pixel groups and second pixel groups respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel.
[0057] Please refer to Figure 2 , Figure 2 A schematic diagram of pixel division is shown. For example... Figure 2 As shown, the second image to be encoded includes k rows of pixels, such as a first row of pixels. The first pixel is the first pixel in the row, and the second pixel is all the pixels in the row except the first pixel. Dividing the pixel row into a first pixel group and a second pixel group facilitates the subsequent confirmation of the encoded information of the pixels, improving convenience.
[0058] S103. The pixel values of k first pixels are encoded using preset first encoding information to obtain k first encoded data.
[0059] The preset first encoding information may include a first encoding structure (RGBA source code encoding), which may be a 1-byte encoding attribute and a 3-byte RGBA source code. The 1-byte encoding attribute includes a 3-bit encoding type and a 5-bit reserved bit, and the 3-bit encoding type is fixed to 0b110.
[0060] In a specific example, the pixel value of the first pixel is [16,32,16,255], and the first encoded data after encoding with the preset first encoding information is [0xc1,0x10,0x84,0xff].
[0061] S104. Determine k second encoding information based on the pixel parameters corresponding to the k second pixel groups respectively.
[0062] The encoding information of the second pixel can be determined by extracting the pixel parameters and pixel values corresponding to each second pixel in the second pixel group, thus obtaining the second encoding information of the second pixel group. The pixel parameters can be the alpha value corresponding to the second pixel. For example, if the pixel value corresponding to the second pixel is [16,32,16,255], then the pixel parameter corresponding to the second pixel is 255.
[0063] The second encoding information may include multiple encoding structures, such as the second encoding structure (RGB original code), the third encoding structure (run-length encoding), and the fourth encoding structure (differential encoding). Specifically, the second encoding structure can be 1 byte of encoding attribute + 2 bytes of RGB original code. The 1 byte of encoding attribute is further divided into 3 bits of encoding type + 5 bits of run-length. The 3 bits of encoding type are fixed as 0b101.
[0064] The third encoding structure can be: 1 byte of encoding attribute + 2 bytes of RGB original code. The 1 byte of encoding attribute is further divided into 3 bits of encoding type + 5 bits of run length. The 3 bits of encoding type are fixed as 0b100.
[0065] The fourth encoding structure can be: 1 bit of encoding attribute + 2 bits of difference. The 1 bit of encoding type is fixed as 0b0. The encoding attribute bit width is set to only 1 bit in order to increase the bit width of the difference. Therefore, this encoding can compress wider data, thereby improving the compression ratio. Here, there are 7 bits of bit width to represent the difference of the three channels of RGB. The difference bit width of RGB is further allocated to 2, 3, and 2 bits, so the difference range that can be represented are R[-2,1], G[-4,3] and B[-2,1], respectively.
[0066] S105. Encode the k groups of second pixels using the corresponding second encoding information to obtain k second encoded data.
[0067] Therefore, the second pixel group is encoded using the corresponding second encoding information to obtain the second encoded data. Specifically, the second encoding information can be encoded using a general encoding method to obtain the second encoded data.
[0068] S106. Combine the k first encoded data with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows.
[0069] The first encoded data is combined with the corresponding second encoded data to obtain the encoded data for the corresponding pixel row. Specifically, the second encoded data is placed after the first encoded data and concatenated to obtain the encoded data for the pixel row. For example, if the first encoded data is [0xc1,0x10,0x84,0xff] and the corresponding second encoded data is [0xc1,0x43,0x8,0x0],[0xa1,0x4d,0x7f],[0xa1,0xa3,0x20],[0x83],[0x74]], then the combined encoded data is: [0xc1,0x10,0x84,0xff], [0xc1,0x43,0x8,0x0],[0xa1,0x4d,0x7f],[0xa1,0xa3,0x20],[0x83],[0x74].
[0070] The storage method for storing the encoded data corresponding to each of the k pixel rows can be the same as the storage method for the second image to be encoded, thus further saving system space.
[0071] In this example, the first image to be encoded can be converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is less than that occupied by the first image to be encoded. The second image to be encoded is divided into k first pixels and k second pixels, and the k first pixels and k second pixels are encoded respectively. Finally, the obtained encoded data are combined to obtain the encoded data corresponding to the second image to be encoded. Thus, the second image to be encoded with low memory space can be directly encoded, reducing the memory occupation when encoding the image, thereby reducing the system resource consumption rate.
[0072] In one possible implementation, a method for determining k second encoded information based on pixel parameters corresponding to k second pixel groups includes:
[0073] A1. Extract the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, wherein the target pixel group is any one of the k second pixel groups;
[0074] A2. Determine the encoding information corresponding to each of the n second pixel points based on the pixel parameters and pixel values corresponding to each of the n second pixel points, and obtain the second encoding information of the target pixel point group;
[0075] A3. Repeat the above steps to extract the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group. Determine the encoding information corresponding to the n second pixels based on the pixel parameters and pixel values of the n second pixels to obtain the second encoding information of the target pixel group. Continue until the encoding information corresponding to k second pixel groups is obtained to obtain k second encoding information.
[0076] Here, the target pixel group is any one of the k second pixel groups. For example, the target pixel can be the second pixel group in the first pixel row; this is just an example and not a specific limitation. The target second pixel group includes n second pixels, which are all the second pixels in the target pixel group. Specifically, it can be understood that the target second pixel group includes n second pixels.
[0077] It can be determined whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, the encoding information of the previous pixel can be used as the encoding information of the target second pixel. If they are the same, the encoding information of the target second pixel can be determined based on the pixel value of the target second pixel and the pixel value of the previous pixel. The target second pixel can be any one of n second pixels.
[0078] The preceding pixel of the target second pixel can be either a second pixel or a first pixel. For example, if the second pixel is the second pixel immediately adjacent to the first pixel in the pixel row, then its preceding pixel is the first pixel. If the second pixel and the first pixel are not immediately adjacent, then its preceding pixel is the second pixel.
[0079] In this example, by determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel, and determining the encoding information of the previous pixel as the encoding information of the target second pixel when they are different, and determining the encoding information of the target second pixel based on the pixel value of the target second pixel and the pixel value of the previous second pixel when they are the same, the encoding information of the target second pixel can be quickly determined when the pixel parameters are the same, thus improving the efficiency of encoding information determination.
[0080] In one possible implementation, a method for determining encoding information corresponding to each of the n second pixels based on pixel parameters and pixel values corresponding to the n second pixels, to obtain second encoding information of the target pixel group, includes:
[0081] B1. Determine whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, determine the encoding information of the previous pixel as the encoding information of the target second pixel. The target second pixel is any one of n second pixels.
[0082] B2. If they are the same, the encoding information corresponding to the second pixel of the target is determined based on the pixel value of the second pixel of the target and the pixel value of the previous pixel.
[0083] B3. Repeat the above method of determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, the encoding information of the previous pixel is determined as the encoding information of the target second pixel. If they are the same, the encoding information corresponding to the target second pixel is determined based on the pixel value of the target second pixel and the pixel value of the previous pixel. This process continues until the encoding information corresponding to each of the n second pixels is obtained, thus obtaining the second encoding information of the target pixel group.
[0084] The encoding information of the preceding pixel may include any one of the first, second, third, and fourth encoding structures described in the preceding embodiments. For example, if the preceding pixel is the first pixel, then its encoding information includes the first encoding structure.
[0085] The method for determining the encoding information corresponding to the second pixel of a target based on the pixel value of the second pixel and the pixel value of the previous pixel can be as follows: It can be determined whether the pixel value of the second pixel is the same as the pixel value of the previous pixel. If they are the same, the encoding information of the second pixel is determined as the first encoding information; if they are different, the encoding information of the second pixel can be determined based on the difference in the RGB channels between the pixel values of the second pixel and the previous pixel. The encoding structure of the first encoding information can be a third encoding structure.
[0086] The aforementioned method for obtaining the encoding information of the second pixel of the target can be repeated until the encoding information corresponding to each second pixel in the target pixel group is obtained, and finally the second encoding information of the target pixel group is obtained.
[0087] In this example, by determining whether the pixel parameters of the second pixel of the target are the same as those of the previous pixel, and if they are different, the encoding information of the previous pixel is determined as the encoding information of the second pixel of the target, thus quickly obtaining the encoding information of the second pixel of the target and improving efficiency.
[0088] In one possible implementation, a method for determining the encoded information corresponding to a target second pixel based on the pixel value of the target second pixel and the pixel value of the previous second pixel includes:
[0089] C1. If the pixel value of the second pixel of the target is the same as the pixel value of the previous pixel, and if they are the same, then the encoding information corresponding to the second pixel of the target is determined to be the first sub-encoding information.
[0090] C2. If they are different, obtain the difference in the RGB channels between the pixel value of the second pixel and the pixel value of the previous pixel.
[0091] C3. Determine the encoding information of the target second pixel based on the difference between the RGB channels.
[0092] Specifically, when the pixel value of the second pixel of the target is the same as the pixel value of the previous pixel, the encoding information corresponding to the second pixel of the target is determined as the first sub-encoding information. The first sub-encoding information may include a third encoding structure, which can be a 1-byte encoding attribute + a 2-byte RGB original code. The 1-byte encoding attribute is further divided into a 3-bit encoding type + a 5-bit run length, and the 3-bit encoding type is fixed as 0b100.
[0093] The difference in RGB channels between the pixel value of the second pixel and the pixel value of the previous pixel can be: In a specific example, the pixel value of the second pixel is [16,60,16,0], and the pixel value of the previous pixel is [1,2,3,0], then the difference in RGB channels is [15,58,13].
[0094] After obtaining the difference between the RGB channels, the encoding information of the target second pixel can be determined based on this difference. Specifically, it can be done by determining whether the difference between the RGB channels is within a preset channel difference range, and then determining the encoding information of the target second pixel based on the determination result. The encoding information of the target second pixel determined based on the determination result can include second encoding information and third encoding information. The encoding structure of the second encoding information can be a fourth encoding structure, and the encoding structure of the third encoding information can be the second encoding structure.
[0095] In this example, by determining whether the pixel parameters of the second pixel of the target are the same as the pixel value of the previous pixel, and if they are the same, the encoding information corresponding to the second pixel of the target is determined as the first sub-encoding information, the encoding information of the second pixel of the target can be obtained quickly, thus improving efficiency.
[0096] In one possible implementation, a method for determining the encoding information of the target second pixel based on the difference between the RGB channels includes:
[0097] D1. Determine whether the difference between the RGB channels is within the preset channel difference range. If so, determine that the encoding information corresponding to the target second pixel is the second sub-encoding information.
[0098] D2. If not, then the encoding information corresponding to the second pixel of the target is determined to be the third sub-encoding information. The third sub-encoding information is different from the second sub-encoding information, and the length of the encoding data corresponding to the second sub-encoding information is less than the length of the encoding data corresponding to the third sub-encoding information.
[0099] The preset channel difference ranges can be R[-2,1], G[-4,3], and B[-2,1]. Whether the difference between the RGB channels is within the preset difference range can be understood as whether each channel difference is within the preset channel difference range. If so, the difference between the RGB channels is within the preset difference range; otherwise, the difference between the RGB channels is outside the preset difference range. For example, if the pixel value of the second target pixel is [16,60,16,0] and the pixel value of the previous pixel is [1,2,3,0], then the difference between the RGB channels is [15,58,13]. The preset channel difference range is R[-2,1], G[-4,3] and B[-2,1]. If the difference between the RGB channels is outside the preset difference range, then the encoding information corresponding to the second target pixel is the third sub-encoding information. The encoding structure of the third sub-encoding information can be the second encoding structure, specifically: 1 byte of encoding attribute + 2 bytes of RGB original code. The 1 byte of encoding attribute is further divided into 3 bits of encoding type + 5 bits of run length. The 3 bits of encoding type are fixed as 0b101.
[0100] For example, if the pixel value of the second target pixel is [5,6,1,0] and the pixel value of the previous pixel is [4,5,3,0], then the difference between the RGB channels is [1,1,-2]. Since the difference between the RGB channels [1,1,-2] falls within the preset channel difference range of R[-2,1], G[-4,3], and B[-2,1], the encoded information of the second target pixel is the second sub-encoded information. The encoding structure of the second sub-encoded information is the fourth encoding structure. Specifically, the fourth encoding structure consists of 1 bit of encoded attribute + 2 bits of difference. The 1 bit of encoding type is fixed as 0b0. Setting the encoding attribute width to only 1 bit increases the width of the difference, thus allowing for wider data compression and improving the compression ratio. Therefore, the length of the encoded data corresponding to the second sub-encoded information is less than the length of the encoded data corresponding to the third encoded information.
[0101] In one possible implementation, after combining k first encoded data with corresponding second encoded data to obtain encoded data corresponding to k pixel rows, a compressed data packet can be constructed. In existing compressed data packet construction, the compressed data packet includes header data and encoded data. The encoded data corresponding to the k pixel rows is placed at the encoded data location, and the header data is constructed to complete the construction of the compressed data packet. However, when decoding the compressed data packet, if only the pixel values of a specific pixel row are needed, the entire compressed data packet needs to be decompressed before the pixel values of that pixel row can be obtained, resulting in low decoding efficiency. To solve the above problem, this application provides a method that supports individual decoding of any pixel row, as follows:
[0102] E1. Determine the pixel row identifier table, which includes the starting position information and the identifier information of each pixel row in the encoded data;
[0103] E2. When constructing the compressed data packet corresponding to the first image to be encoded, the pixel row identifier table is placed between the encoded data and the header data;
[0104] E3. When decoding the compressed data packet, the starting position information corresponding to the target pixel row is extracted from the pixel identification table using the identification information of the target pixel row to be decoded.
[0105] E4. Extract the encoded data corresponding to the target pixel row based on the starting position information;
[0106] E5. Decode the encoded data corresponding to the row of target pixels to obtain decoded data.
[0107] The starting position information corresponding to each row of pixels can be represented using a common method for representing starting position information. The identifier information of each row of pixels corresponds one-to-one and is used to uniquely identify the row of pixels.
[0108] By placing the pixel row identifier table between the encoded data and the header data of the compressed data packet, the starting position information corresponding to the target pixel row can be obtained through the pixel row identifier table during decoding. Based on the starting position information, the encoded data of the target pixel row can be extracted and subsequent decoding processing can be performed to obtain the decoded data corresponding to the target pixel row.
[0109] In this example, by placing the pixel row identifier table between the encoded data and the header data when constructing the compressed data packet corresponding to the first image to be encoded, the corresponding starting position information can be extracted according to the identifier information of the target pixel row during decoding. Data extraction and decoding can then be performed based on this starting position information, thus eliminating the need to fully decode the compressed data packet before extracting the decoded data of the target pixel row, thereby improving decoding efficiency.
[0110] In one specific embodiment, an image processing method is provided, which is as follows:
[0111] This section uses the first image to be encoded as having an RGBA8888 format for illustration. The pixel values of a single row of pixels in the image to be encoded are:
[0112] [[128,128,128,255],[8,8,24,0],[128,240,128,0],[32,20,24,0],[32,20,24,0],[32,20,24,0],[32,20,24,0],[40,24,8,0]];
[0113] Perform a format conversion on this row of pixels, converting it from RGBA8888 format to RGBA5658 format. The pixel values in the converted RGBA5658 format are:
[0114] [[[16,32,16,255],[1,2,3,0],[16,60,16,0],[4,5,3,0],[4,5,3,0],[4,5,3,0],[4,5,3,0],[5,6,1,0]];
[0115] To encode pixel values in RGBA5658 format, the first pixel is encoded using a preset first encoding information, resulting in the encoded data [0xc1, 0x10, 0x84, 0xff]. Note that this is also stored in RGBA5658 format, thus leveraging its small storage space to reduce system storage consumption. The second pixel, because its pixel parameter (alpha value) differs from the previous pixel, is also encoded using the preset first encoding information, resulting in the encoded value [0xc1, 0x43, 0x8, 0x0]. The third pixel has the same alpha value as the previous pixel, but its RGB value differs. The difference between the RGB channels is calculated as [15, 58, 13]. This RGB difference is not within the preset channel difference range. The values are within the ranges [-2,1], [-4,3], and [-2,1], so only the second encoding structure can be used for encoding, with the encoding value being [0xa1,0x4d,0x7f]. The encoding attributes are deliberately grouped together for easier processing. The fourth pixel is also encoded using the second encoding structure, with the encoding value being [0xa1,0xa3,0x20]. The values of the fifth, sixth, and seventh pixels are exactly the same as the previous pixel, so the third encoding structure is used to compress these three pixels to [0x83], with a run length of 3. The difference between the RGB channel values of the eighth pixel and the previous pixel is [1,1,-2], which is within the preset channel difference range, so the fourth encoding structure is used for encoding. To facilitate the compression of the difference, an offset needs to be added to the difference to convert it to a positive number. The RGB differences are added by 2, 4, and 2 respectively, and the difference is updated to [0x3,0x5,0x0]. The encoding value with the encoding type is [0x74].
[0116] The final encoded data is: [[0xc1,0x10,0x84,0xff],[0xc1,0x43,0x8,0x0],[0xa1,0x4d,0x7f],[0xa1,0xa3,0x20],[0x83],[0x74]], where the length before encoding is 32 bytes and the length after encoding is 24 bytes.
[0117] The decoding process of the above encoded data is as follows. First, read the first byte. The encoding type of 0xc1 corresponds to the type of the first encoded information, so the first pixel is RGBA original code. Then, read 3 bytes of data consecutively to get the value of the first pixel in the pixel row as [16,32,16,255]. Continue to take the next byte, which is also RGBA original code, and decode it to get the value of the second pixel as [1,2,3,0]. The encoding attribute 0xa1 of the next byte corresponds to the second encoding structure, and the alpha value is the same as the previous pixel, so the value of the third pixel is decoded as [16,60,16,0]. The encoding structure of the next byte is the second encoding structure, and decode it to get the value of the fourth pixel as [4,5,3,0]. The next byte is 0x83, which corresponds to the run length encoding, and the run length value is = (0x83&0x1f) = 3, which can continuously decode 3 pixels, resulting in the values of pixels 5 to 7 as [[4,5,3,0],[4,5,3,0],[4,5,3,0]; taking the encoding attribute of the next byte as 0x74, for the fourth encoding structure, the differential encoding value is converted to a difference of 0x74, and further parsing yields the RGB offset differences as [0x3,0x5,0x0], and then subtracting the offset of the RGB channels respectively, to obtain the true RGB difference value as [1,1,-2]. Adding the true difference to the previous pixel value yields the current pixel value as [5,6,1,0]. Finally, the pixel value before compression is decoded. In the above method, except for the lossy operation of converting the RGBA8888 format to the RGBA5658 format, the other operations will not degrade the image quality.
[0118] The method of this application has been described above; the apparatus of this application will be described below.
[0119] See Figure 3 , Figure 3 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application. This image processing device is applied to the aforementioned electronic device or server. Figure 3 As shown, the image processing apparatus 30 includes:
[0120] The conversion unit 301 is used to convert the first image to be encoded from a first image format to a second image format to obtain a second image to be encoded, wherein the memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded.
[0121] The partitioning unit 302 is used to divide the k pixel rows in the second image to be encoded into first pixel groups and second pixel groups respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel.
[0122] The first encoding unit 303 is used to encode the pixel values of k first pixels using preset first encoding information to obtain k first encoded data.
[0123] The determining unit 304 is used to determine k second encoding information based on the pixel parameters corresponding to the k second pixel point groups respectively;
[0124] The second encoding unit 305 is used to encode the k groups of second pixels using the corresponding second encoding information to obtain k second encoded data.
[0125] The processing unit 306 is used to combine k first encoded data with corresponding second encoded data to obtain encoded data corresponding to k pixel rows.
[0126] In one possible implementation, the determining unit 304 is specifically used for:
[0127] Extract the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, wherein the target pixel group is any one of the k second pixel groups;
[0128] Based on the pixel parameters and pixel values corresponding to the n second pixels, the encoding information corresponding to the n second pixels is determined, and the second encoding information of the target pixel group is obtained.
[0129] Repeat the above process of extracting the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, determining the encoding information corresponding to the n second pixels based on the pixel parameters and pixel values of the n second pixels, and obtaining the second encoding information of the target pixel group, until the encoding information corresponding to k second pixel groups is obtained, thus obtaining k second encoding information.
[0130] In one possible implementation, in determining the encoding information corresponding to each of the n second pixels based on the pixel parameters and pixel values corresponding to the n second pixels respectively, to obtain the second encoding information of the target pixel group, the determining unit 304 is specifically used for:
[0131] Determine whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, then determine the encoding information of the previous pixel as the encoding information of the target second pixel. The target second pixel is any one of n second pixels.
[0132] If they are the same, the encoding information corresponding to the second pixel of the target is determined based on the pixel value of the second pixel of the target and the pixel value of the previous pixel.
[0133] Repeat the above process of determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel. If they are different, the encoding information of the previous pixel is determined as the encoding information of the target second pixel. If they are the same, the encoding information corresponding to the target second pixel is determined based on the pixel value of the target second pixel and the pixel value of the previous pixel. This process continues until the encoding information corresponding to each of the n second pixels is obtained, thus obtaining the second encoding information of the target pixel group.
[0134] In one possible implementation, in determining the encoding information corresponding to the target second pixel based on the pixel value of the target second pixel and the pixel value of the previous pixel, the determining unit 304 is specifically used for:
[0135] If the pixel value of the second pixel of the target is the same as the pixel value of the previous pixel, and if they are the same, then the encoding information corresponding to the second pixel of the target is determined to be the first sub-encoding information (run-length encoding).
[0136] If they are different, then obtain the difference in the RGB channels between the pixel value of the second pixel and the pixel value of the previous pixel;
[0137] The encoding information of the target second pixel is determined based on the difference between the RGB channels.
[0138] In one possible implementation, the determining unit 304 is specifically configured to: determine the encoding information of the target second pixel based on the difference between the RGB channels.
[0139] Determine whether the difference between the RGB channels is within a preset channel difference range. If so, determine that the encoding information corresponding to the target second pixel is the second sub-encoding information (differential encoding).
[0140] If not, then the encoding information corresponding to the second pixel of the target is determined to be the third sub-encoding information (RGB original code encoding). The third sub-encoding information is different from the second sub-encoding information, and the length of the encoded data corresponding to the second sub-encoding information is less than the length of the encoded data corresponding to the third sub-encoding information.
[0141] In one possible implementation, the storage method of the encoded data corresponding to the k rows of pixels is the same as the storage method of the second image to be encoded.
[0142] In one possible implementation, after combining the k first encoded data with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows, the device is further configured to:
[0143] A pixel row identifier table is determined, which includes the starting position information and the identifier information of each pixel row in the encoded data;
[0144] When constructing the compressed data packet corresponding to the first image to be encoded, the pixel row identifier table is placed between the encoded data and the header data;
[0145] When decoding the compressed data packet, the starting position information corresponding to the target pixel row is extracted from the pixel identification table using the identification information of the target pixel row to be decoded.
[0146] Extract the encoded data corresponding to the target pixel row based on the starting position information;
[0147] The encoded data corresponding to the row of target pixels is decoded to obtain decoded data.
[0148] It should be noted that, Figure 3 For any content not mentioned in the corresponding embodiments, please refer to the description of the foregoing method embodiments, which will not be repeated here.
[0149] See Figure 4 , Figure 4 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device can be an electronic device or a server. The computer device 40 includes a processor 401, a memory 402, and a communication interface 403. The memory 402 and the communication interface 403 are connected to the processor 401, for example, via a bus.
[0150] Processor 401 is configured to support the computer device 40 in performing the corresponding functions in the methods described in the above method embodiments. Processor 401 may be a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof. The aforementioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0151] Memory 402 is used to store program code, etc. Memory 402 may include volatile memory (VM), such as random access memory (RAM); memory 402 may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 402 may also include combinations of the above types of memory.
[0152] The communication interface 403 can be a hardware interface, such as a USB interface; or it can be a software interface, such as a Bluetooth interface or a WiFi interface. It is not limited to these limitations.
[0153] Optionally, the computer device 40 may also include an input interface 404 and / or an output interface 405. The input interface 404 can be used to acquire user instructions, and the input interface may include, for example, a touch screen, buttons, etc.; the output interface 405 is used to output encoded data.
[0154] Processor 401 can call the program code to perform the following operations:
[0155] The first image to be encoded is converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded.
[0156] The k pixel rows in the second image to be encoded are divided into first pixel groups and second pixel groups, respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel.
[0157] The pixel values of k first pixels are encoded using preset first encoding information to obtain k first encoded data;
[0158] Based on the pixel parameters corresponding to the k second pixel groups, determine the k second encoding information;
[0159] The k groups of second pixels are encoded using the corresponding second encoding information to obtain k second encoded data.
[0160] The k first encoded data are combined with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows.
[0161] This application also provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the image processing method as described in the foregoing embodiments.
[0162] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0163] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. An image processing method, characterized in that, The image processing method includes: The first image to be encoded is converted from a first image format to a second image format to obtain a second image to be encoded. The memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded. The k pixel rows in the second image to be encoded are divided into first pixel groups and second pixel groups, respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row excluding the first pixel. The pixel values of k first pixels are encoded using preset first encoding information to obtain k first encoded data; Based on the pixel parameters corresponding to the k second pixel groups, determine the k second encoding information, including: Extract the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, wherein the target pixel group is any one of the k second pixel groups, and the pixel parameter is the alpha value corresponding to the second pixel; The second encoding information of the target pixel group is obtained by determining the encoding information corresponding to each of the n second pixels based on the pixel parameters and pixel values of the n second pixels respectively. This includes: determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel; if they are different, determining the encoding information of the previous pixel as the encoding information of the target second pixel, where the target second pixel is any one of the n second pixels; if they are the same, determining the encoding information corresponding to the target second pixel based on the pixel values of the target second pixel and the previous pixel; repeating the above method of determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel until the encoding information corresponding to each of the n second pixels is obtained, thus obtaining the second encoding information of the target pixel group. Repeat the above process of extracting the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, determining the encoding information corresponding to the n second pixels based on the pixel parameters and pixel values of the n second pixels, and obtaining the second encoding information of the target pixel group, until the encoding information corresponding to k second pixel groups is obtained, thus obtaining k second encoding information. The k groups of second pixels are encoded using the corresponding second encoding information to obtain k second encoded data. The k first encoded data are combined with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows.
2. The image processing method according to claim 1, characterized in that, The step of determining the encoding information corresponding to the second pixel of the target based on the pixel value of the second pixel and the pixel value of the previous pixel includes: If the pixel value of the second pixel of the target is the same as the pixel value of the previous pixel, then the encoding information corresponding to the second pixel of the target is determined to be the first sub-encoding information. If they are different, then obtain the difference in the RGB channels between the pixel value of the second pixel and the pixel value of the previous pixel; The encoding information of the target second pixel is determined based on the difference between the RGB channels.
3. The image processing method according to claim 2, characterized in that, Determining the encoding information of the target second pixel based on the difference between the RGB channels includes: Determine whether the difference between the RGB channels is within a preset channel difference range. If so, determine that the encoding information corresponding to the target second pixel is the second sub-encoding information. If not, then the encoding information corresponding to the second pixel of the target is determined to be the third sub-encoding information. The third sub-encoding information is different from the second sub-encoding information, and the length of the encoding data corresponding to the second sub-encoding information is less than the length of the encoding data corresponding to the third sub-encoding information.
4. The image processing method according to any one of claims 1-3, characterized in that, The storage method for the encoded data corresponding to the k rows of pixels is the same as the storage method for the second image to be encoded.
5. The image processing method according to claim 4, characterized in that, After combining the k first encoded data with the corresponding second encoded data to obtain the encoded data corresponding to the k pixel rows, the method further includes: A pixel row identifier table is determined, which includes the starting position information and the identifier information of each pixel row in the encoded data; When constructing the compressed data packet corresponding to the first image to be encoded, the pixel row identifier table is placed between the encoded data and the header data; When decoding the compressed data packet, the starting position information corresponding to the target pixel row is extracted from the pixel identification table using the identification information of the target pixel row to be decoded. Extract the encoded data corresponding to the target pixel row based on the starting position information; The encoded data corresponding to the row of target pixels is decoded to obtain decoded data.
6. An image processing apparatus, characterized in that, The image processing device includes: The conversion unit is used to convert the first image to be encoded from a first image format to a second image format to obtain a second image to be encoded, wherein the memory space occupied by the second image to be encoded is less than the memory space occupied by the first image to be encoded. The partitioning unit is used to divide the k pixel rows in the second image to be encoded into first pixel groups and second pixel groups respectively, to obtain k first pixel groups and k second pixel groups. The first pixel is the first pixel in the pixel row, and the second pixel in the second pixel group is the pixel in the pixel row other than the first pixel. The first encoding unit is used to encode the pixel values of k first pixels using preset first encoding information to obtain k first encoded data. The determining unit is used to determine k second encoding information based on the pixel parameters corresponding to the k second pixel point groups respectively, including: extracting the pixel parameters corresponding to n second pixel points from the pixel parameters of the target pixel point group, wherein the target pixel point group is any one of the k second pixel point groups, and the pixel parameter is the alpha value corresponding to the second pixel point; The second encoding information of the target pixel group is obtained by determining the encoding information corresponding to each of the n second pixels based on the pixel parameters and pixel values of the n second pixels respectively. This includes: determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel; if they are different, determining the encoding information of the previous pixel as the encoding information of the target second pixel, where the target second pixel is any one of the n second pixels; if they are the same, determining the encoding information corresponding to the target second pixel based on the pixel values of the target second pixel and the previous pixel; repeating the above method of determining whether the pixel parameters of the target second pixel are the same as those of the previous pixel until the encoding information corresponding to each of the n second pixels is obtained, thus obtaining the second encoding information of the target pixel group. Repeat the above process of extracting the pixel parameters corresponding to n second pixels from the pixel parameters of the target pixel group, determining the encoding information corresponding to the n second pixels based on the pixel parameters and pixel values of the n second pixels, and obtaining the second encoding information of the target pixel group, until the encoding information corresponding to k second pixel groups is obtained, thus obtaining k second encoding information. The second encoding unit is used to encode the k groups of second pixels using the corresponding second encoding information to obtain k second encoded data. The processing unit is used to combine k first encoded data with the corresponding second encoded data to obtain encoded data corresponding to k pixel rows.
7. A computer device, characterized in that, The device includes a memory, a processor, and a communication interface, wherein the memory and the communication interface are connected to the processor, and the processor is configured to execute one or more computer programs stored in the memory, wherein when the processor executes the one or more computer programs, the computer device causes the computer device to perform the method as described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Image processing method and device, electronic equipment and readable storage medium
CN116320395A
Image processing apparatus, image processing method and program
US20120170664A1