Image processing method, device, electronic device and storage medium
By blocking and rearranging the original image, compressed image and index information are generated, the texture compression algorithm is solved, and the problem of high memory consumption and image quality is reduced on mobile devices is achieved, lossless compression and cross-platform compatibility are achieved, and it is suitable for rendering of electronic games, video effects and movie effects.
Patent Information
- Application Number
- CN202111350346.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-15
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2041-11-15
AI Technical Summary
The existing texture compression algorithms cause high memory consumption, large transmission bandwidth, and degraded image quality on mobile devices, which cannot be compatible with H264 video encoding technology.
By chunking the original image, identifying and rearranging the target image blocks containing the foreground pixels, and generating compressed image and index information, ensuring lossless image quality while reducing memory usage.
While ensuring lossless image quality, it greatly reduces memory usage and improves texture compression performance. It is suitable for a variety of platforms and is compatible with H264 video encoding technology.
Smart Images

Figure CN114157867B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to an image processing method, device, electronic device, and storage medium. Background Art
[0002] With the development of computer image rendering technology, texture (UV) mapping is a relatively commonly used rendering technology in a wide range of application scenarios such as rendering of electronic games, rendering of video special effects, and rendering of movie special effects. For example, magic expressions and special effect pendants added to users' selfie videos can all be achieved using texture mapping technology.
[0003] Although the GPU (Graphics Processing Unit) can directly read some uncompressed texture maps, directly loading uncompressed texture maps on mobile devices will result in high memory consumption and transmission bandwidth, leading to a series of performance issues such as device overheating and application lag. Therefore, texture compression is usually required to ensure that the compressed image has a low memory usage and can be read by the GPU.
[0004] Common texture compression algorithms include DXT (DirectX Texture) and ETC (Ericsson Texture Compression). These are lossy texture compression algorithms. The texture maps decompressed and rendered by the peer end will result in varying degrees of image quality degradation compared to the original texture maps. Summary of the Invention
[0005] The present disclosure provides an image processing method, apparatus, electronic device, and storage medium that significantly save memory usage while at least ensuring lossless image quality before and after compression. The technical solutions of the present disclosure are as follows:
[0006] According to one aspect of an embodiment of the present disclosure, there is provided an image processing method, including:
[0007] Divide the original image into blocks to obtain multiple image blocks;
[0008] determining a plurality of target image blocks among the plurality of image blocks, the target image blocks including foreground pixels in the original image;
[0009] Based on the multiple target image blocks, a compressed image and index information are generated, where the compressed image is an image obtained by rearranging the multiple target image blocks, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image.
[0010] In some embodiments, generating a compressed image based on the multiple target image blocks includes:
[0011] The multiple target image blocks are copied, and the copied multiple target image blocks are rearranged to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
[0012] In some embodiments, generating a compressed image based on the multiple target image blocks includes:
[0013] Determine a first image block corresponding to each target image block, where the first image block includes the corresponding target image block and a first edge region extending outward from an edge of the target image block;
[0014] The first image blocks are rearranged to obtain the compressed image.
[0015] In some embodiments, generating a compressed image based on the multiple target image blocks includes:
[0016] Based on the target ratio, the original image is reduced to obtain a first image;
[0017] In the first image, determining a second image block corresponding to each target image block, wherein the second image block includes the corresponding reduced target image block and a second edge region extending outward from an edge of the reduced target image block;
[0018] The second image blocks are rearranged to obtain the compressed image; wherein the target ratio is the ratio of the size of the target image block after reduction to the size of the target image block before reduction.
[0019] In some embodiments, generating index information based on the multiple target image blocks includes:
[0020] For each target image block among the plurality of target image blocks, determining a mapping relationship between a position coordinate of each target image block in the original image and a position coordinate of each target image block in the compressed image;
[0021] The index information is generated based on the mapping relationship of each target image block.
[0022] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the compressed image.
[0023] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
[0024] In some embodiments, the method further comprises:
[0025] Determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being a proportion of a target image block obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks;
[0026] selecting a target compression ratio from the plurality of compression ratios;
[0027] The step of dividing the original image into blocks to obtain the plurality of image blocks is performed using a preset image block size corresponding to the target compression rate.
[0028] According to another aspect of the present disclosure, there is provided an image processing method, including:
[0029] Acquire a compressed image and index information, wherein the compressed image is an image obtained by rearranging multiple target image blocks of an original image, the target image blocks including foreground pixels in the original image, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image;
[0030] Based on the index information, for each image block to be rendered, obtaining foreground pixels from the corresponding target image block in the compressed image;
[0031] Based on the foreground pixels corresponding to each image block to be rendered, the corresponding image block is rendered to obtain the original image.
[0032] In some embodiments, obtaining foreground pixels from a corresponding target image block in the compressed image for each image block to be rendered based on the index information includes:
[0033] For each image block to be rendered, determining a target image block in the compressed image corresponding to the image block based on the index information;
[0034] The foreground pixels are read from the target image block of the compressed image.
[0035] According to another aspect of an embodiment of the present disclosure, there is provided an image processing apparatus, including:
[0036] A blocking unit is configured to block the original image to obtain a plurality of image blocks;
[0037] a determining unit configured to determine a plurality of target image blocks among the plurality of image blocks, wherein the target image blocks include foreground pixels in the original image;
[0038] A generating unit is configured to generate a compressed image and index information based on the multiple target image blocks, wherein the compressed image is an image obtained by rearranging the multiple target image blocks, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image.
[0039] In some embodiments, the generating unit is configured to perform:
[0040] The multiple target image blocks are copied, and the copied multiple target image blocks are rearranged to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
[0041] In some embodiments, the generating unit is configured to perform:
[0042] Determine a first image block corresponding to each target image block, where the first image block includes the corresponding target image block and a first edge region extending outward from an edge of the target image block;
[0043] The first image blocks are rearranged to obtain the compressed image.
[0044] In some embodiments, the generating unit is configured to perform:
[0045] Based on the target ratio, the original image is reduced to obtain a first image;
[0046] In the first image, determining a plurality of second image blocks corresponding to each target image block, wherein the second image blocks include the corresponding reduced target image block and a second edge region extending outward from an edge of the reduced target image block;
[0047] The second image blocks are rearranged to obtain the compressed image; wherein the target ratio is the ratio of the size of the target image block after reduction to the size of the target image block before reduction.
[0048] In some embodiments, the generating unit is configured to perform:
[0049] For each target image block among the plurality of target image blocks, determining a mapping relationship between a position coordinate of each target image block in the original image and a position coordinate of each target image block in the compressed image;
[0050] The index information is generated based on the mapping relationship of each target image block.
[0051] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the compressed image.
[0052] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
[0053] In some embodiments, the segmentation unit is further configured to perform:
[0054] Determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being a proportion of a target image block obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks;
[0055] selecting a target compression ratio from the plurality of compression ratios;
[0056] The step of dividing the original image into blocks to obtain the plurality of image blocks is performed using a preset image block size corresponding to the target compression rate.
[0057] According to another aspect of an embodiment of the present disclosure, there is provided an image processing apparatus, including:
[0058] a first acquiring unit configured to acquire a compressed image and index information, wherein the compressed image is an image obtained by rearranging a plurality of target image blocks of an original image, the target image blocks including foreground pixels in the original image, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image;
[0059] A second acquiring unit is configured to acquire foreground pixels from a corresponding target image block in the compressed image for each image block to be rendered based on the index information;
[0060] The rendering unit is configured to render the corresponding image block based on the foreground pixels corresponding to each image block to be rendered, so as to obtain the original image.
[0061] In some embodiments, the second acquiring unit is configured to perform:
[0062] For each image block to be rendered, determining a target image block in the compressed image corresponding to the image block based on the index information;
[0063] The foreground pixels are read from the target image block of the compressed image.
[0064] According to another aspect of the present disclosure, an electronic device is provided, including:
[0065] one or more processors;
[0066] one or more memories for storing the one or more processor-executable instructions;
[0067] The one or more processors are configured to execute the image processing method in any possible implementation of the above aspect.
[0068] According to another aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When at least one instruction in the computer-readable storage medium is executed by one or more processors of an electronic device, the electronic device is enabled to execute the image processing method in any possible implementation of the above-mentioned aspect.
[0069] According to another aspect of an embodiment of the present disclosure, a computer program product is provided, comprising one or more instructions, wherein the one or more instructions can be executed by one or more processors of an electronic device, so that the electronic device can execute the image processing method in any possible implementation of the above-mentioned aspect.
[0070] The technical solutions provided by the embodiments of the present disclosure bring at least the following beneficial effects:
[0071] After dividing the original image into blocks, the target image blocks in the original image are identified, and the target image blocks are rearranged to obtain a compressed image. In this way, the background pixels that originally accounted for a large proportion in the original image are discarded in the compressed image, and only the target image blocks containing foreground pixels are retained. At the same time, an index information is generated to indicate the position mapping relationship of the target image blocks before and after the rearrangement, which facilitates the restoration of the compressed image to the original image. Since the storage overhead of the index information is very small, the memory occupied by the image can be greatly reduced while ensuring the lossless image quality.
[0072] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] The accompanying drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute an improper limitation of the present disclosure.
[0074] Figure 1 is a schematic diagram of an implementation environment of an image processing method according to an exemplary embodiment;
[0075] Figure 2 is a flowchart of an image processing method according to an exemplary embodiment;
[0076] Figure 3 is a flowchart of an image processing method according to an exemplary embodiment;
[0077] Figure 4 is a schematic diagram of a hollow map provided by an embodiment of the present disclosure;
[0078] Figure 5 is a schematic diagram of image segmentation provided by an embodiment of the present disclosure;
[0079] Figure 6 is a schematic diagram of the principle of the tile rearrangement process provided by an embodiment of the present disclosure;
[0080] Figure 7 is a schematic diagram of a principle of a tile rearrangement process provided by an embodiment of the present disclosure;
[0081] Figure 8 This is a comparison diagram of rendering results when performing image restoration based on different index maps, provided by an embodiment of the present disclosure;
[0082] Figure 9 is a schematic diagram of edge defects in a restored image provided by an embodiment of the present disclosure;
[0083] Figure 10 This is a schematic diagram of the principle of an edge adding method provided by an embodiment of the present disclosure;
[0084] Figure 11 This is a comparison chart of image quality using different edge addition methods provided by an embodiment of the present disclosure;
[0085] Figure 12 is a flowchart of an image processing method according to an exemplary embodiment;
[0086] Figure 13 This is a schematic diagram of a principle of an image restoration process provided by an embodiment of the present disclosure;
[0087] Figure 14 is a schematic diagram of the principle of image compression and image restoration provided by an embodiment of the present disclosure;
[0088] Figure 15 This is a comparison chart of rendering effects before and after texture compression provided by an embodiment of the present disclosure;
[0089] Figure 16 is a logical structure block diagram of an image processing device according to an exemplary embodiment;
[0090] Figure 17 is a logical structure block diagram of an image processing device according to an exemplary embodiment;
[0091] Figure 18 A structural block diagram of a terminal provided by an exemplary embodiment of the present disclosure is shown;
[0092] Figure 19 It is a structural diagram of a server provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0093] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0094] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure as detailed in the appended claims.
[0095] The user information involved in this disclosure may be information authorized by the user or fully authorized by all parties.
[0096] In the field of computer image rendering, texture (UV) mapping is a common rendering technology, suitable for a wide range of application scenarios such as rendering of electronic games, rendering of video special effects, and rendering of movie special effects. For example, the surface details of models such as scene models and character models in electronic games can be rendered by attaching texture maps to three-dimensional models. For example, video effects such as magic expressions and special effects pendants added to user selfie videos can be rendered by attaching texture maps to the user's facial area.
[0097] To reduce the memory usage of texture maps, texture compression is often performed. DXT is a lossy texture compression algorithm supported by many PC (Personal Computer) graphics cards. DXT formats range from DXT1 to DXT5, with DXT1 and DXT5 being more common. Because the DXT algorithm uses lossy compression, the image quality of a texture map after compression and decompression is significantly reduced compared to the original texture map. Furthermore, the DXT algorithm only works on Windows systems, making it less compatible with other platforms. Furthermore, the DXT algorithm cannot be combined with audio and video encoding technologies like H.264, resulting in poor compatibility with other technologies.
[0098] In addition to the DXT algorithm commonly used on PCs, ETC is a lossy texture compression algorithm commonly used on mobile devices. It is currently the standard texture compression solution for Android devices, and both OpenGL (Open Graphics Library) and OpenGL ES (OpenGL for Embedded Systems) support ETC1. Because the ETC algorithm is also lossy compression, the image quality of a texture map restored after compression and decompression is significantly reduced compared to the original texture map. In addition, the ETC algorithm can only be used on the Android system, with poor cross-platform compatibility. Furthermore, the ETC algorithm cannot be combined with audio and video encoding technologies such as H264, meaning that it has poor compatibility with other technologies.
[0099] In summary, traditional texture compression algorithms will cause loss of image quality and are not compatible with H264 video encoding technology. The disclosed embodiment proposes a lossless texture compression solution with good compatibility, low computational cost, and cross-platform. For various types of original images, such as some original images with a background pixel ratio greater than a ratio threshold (texture maps with a large number of hollowed-out parts, etc.), the texture compression performance is significantly improved, which is described in detail below.
[0100] The following describes the architecture of the embodiments of the present disclosure.
[0101] Figure 1 is a schematic diagram of an implementation environment of an image processing method according to an exemplary embodiment. Figure 1 In this implementation environment, a terminal 101 and a server 102 may be included, where the terminal 101 and the server 102 are both exemplary illustrations of electronic devices.
[0102] Terminal 101 installs and runs an application that supports image rendering. Optionally, the application includes but is not limited to: short video applications, game applications, audio and video applications, video on demand applications, social applications, conference applications, enterprise applications, etc. The embodiment of this disclosure does not specifically limit the type of application.
[0103] The terminal 101 is connected to the server 102 for direct or indirect communication via a wired or wireless manner.
[0104] Server 102 comprises at least one of a single server, multiple servers, a cloud computing platform, or a virtualization center. Server 102 provides background services for applications that support image rendering. For example, server 102 performs texture compression on raw images. Optionally, server 102 performs primary computing tasks, while terminal 101 performs secondary computing tasks. Alternatively, server 102 performs secondary computing tasks, while terminal 101 performs primary computing tasks. Alternatively, terminal 101 and server 102 utilize a distributed computing architecture for collaborative computing.
[0105] Optionally, server 102 is an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.
[0106] Schematically, taking the video special effects rendering scenario as an example, in a streaming media transmission mode, the terminal 101 records a selfie video based on an application, and a variety of magic expressions or special effects widgets are provided in the application. After the user selects the magic expression or special effects widget of interest, the terminal 101 downloads the compressed image and index information of the texture map of the magic expression or special effects widget from the server 102, and restores the compressed image after texture compression to the original texture map based on the index information, and then pastes the restored texture map to the specified area in the video stream, for example, pasting the magic expression to the face area, or pasting the head widget to the hair area, etc., or pasting the special effects widget to the end point of the dragging trajectory as the user drags the finger, etc. The embodiments of the present disclosure do not specifically limit this.
[0107] Terminal 101 generally refers to one of a plurality of terminals. Terminal 101 may be, but is not limited to, at least one of a smartphone, tablet computer, smart speaker, smartwatch, laptop computer, or desktop computer. For example, terminal 101 may be a smartphone or other handheld portable communication device.
[0108] Those skilled in the art will appreciate that the number of terminals 101 may be greater or less. For example, there may be only one terminal 101, or there may be dozens, hundreds, or even more terminals 101. The embodiments of this disclosure do not limit the number or device type of terminals 101.
[0109] Figure 2 is a flowchart of an image processing method according to an exemplary embodiment. Figure 2 The image processing method is applied to electronic devices, and is described below using the electronic device as a server as an example.
[0110] In step 201, the original image is divided into blocks to obtain a plurality of image blocks.
[0111] In step 202, a plurality of target image blocks are determined from the plurality of image blocks, where the target image blocks include foreground pixels in the original image.
[0112] In step 203, a compressed image and index information are generated based on the multiple target image blocks. The compressed image is an image obtained by rearranging the multiple target image blocks. The index information is used to indicate the position mapping relationship between the target image block in the original image and the compressed image.
[0113] The method provided by the embodiment of the present disclosure divides the original image into blocks, identifies the target image blocks in the original image, and rearranges the target image blocks to obtain a compressed image, so that the background pixels that originally accounted for a large proportion in the original image are discarded in the compressed image, and only the target image blocks containing foreground pixels are retained. At the same time, an index information is generated to indicate the position mapping relationship of the target image blocks before and after the rearrangement, which facilitates the restoration of the compressed image to the original image. Since the storage overhead of the index information is very small, the memory occupied by the image can be greatly reduced while ensuring the lossless image quality.
[0114] In some embodiments, generating a compressed image based on the multiple target image blocks includes: copying the multiple target image blocks, rearranging the copied multiple target image blocks to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
[0115] In some embodiments, generating a compressed image based on the multiple target image blocks includes: determining a first image block corresponding to each target image block, the first image block including the corresponding target image block and a first edge area extending outward from the edge of the target image block; and rearranging each of the first image blocks to obtain the compressed image.
[0116] In some embodiments, generating a compressed image based on the multiple target image blocks includes: reducing the original image based on a target ratio to obtain a first image; in the first image, determining a second image block corresponding to each target image block, the second image block containing the corresponding reduced target image block and a second edge area extending outward from the edge of the reduced target image block; rearranging each of the second image blocks to obtain the compressed image; wherein the target ratio is the ratio of the size of the reduced target image block to the size of the target image block before reduction.
[0117] In some embodiments, generating index information based on the multiple target image blocks includes: determining, for each target image block in the multiple target image blocks, a mapping relationship between the position coordinates of each target image block in the original image and the position coordinates in the compressed image; and generating the index information based on the mapping relationship of each target image block.
[0118] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image.
[0119] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
[0120] In some embodiments, the method further includes: determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being the proportion of the target image block obtained by dividing the original image into blocks with the corresponding preset image block size in the corresponding multiple image blocks; selecting a target compression ratio from the multiple compression ratios; and executing the step of dividing the original image into blocks with the preset image block size corresponding to the target compression ratio to obtain the multiple image blocks.
[0121] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0122] Figure 3 is a flowchart of an image processing method according to an exemplary embodiment. Figure 3 As shown, in the embodiment of the present disclosure, the image compression process will be introduced in detail. The image compression process can be executed by an electronic device, and the electronic device is taken as the server 102 in the above implementation environment as an example for explanation.
[0123] In step 301, the server obtains the background pixel ratio in the original image.
[0124] Among them, the original image is any image to be processed, such as a texture map, or an image to be compressed, etc. The original image can be read by the server from a local image database, or downloaded by the server from a cloud image database, or uploaded to the server after being produced by the terminal. The embodiment of the present disclosure does not specifically limit the source of the original image.
[0125] In some embodiments, the server obtains the number of background pixels in the original image and determines the ratio of the number of background pixels to the total number of pixels in the original image as the background pixel ratio. In other words, the server can divide the pixels in the original image into foreground pixels and background pixels, where the foreground pixels are equivalent to valid pixel information in the original image, while the background pixels are equivalent to invalid pixel information in the original image.
[0126] In some embodiments, the server divides foreground pixels and background pixels based on pixel values. For example, for a hollow map, pixels whose transparency (α) channel has a value of 0, that is, fully transparent pixels, refer to background pixels, while pixels whose transparency channel value is not 0 refer to foreground pixels.
[0127] Figure 4 This is a schematic diagram of a hollow map provided by an embodiment of the present disclosure, such as Figure 4 As shown, five possible hollow maps 401 to 405 are shown. Hollow maps are very common in video special effects rendering and game rendering. The characteristic of hollow maps is that the background pixels account for a high proportion, that is, there are large hollow areas (the value of the transparency channel is 0, that is, the background area). For example, each of the hollow maps 401 to 405 contains a large hollow area (shown as a white background in the figure, but can be set to a fully transparent background). At this time, the image compression process provided by the embodiment of the present disclosure can be used to spatially rearrange the hollow maps and discard invalid hollow areas to ensure that the compressed image meets the texture requirements of the GPU and can occupy less memory space during rendering.
[0128] In some embodiments, the server uses a machine learning-based image segmentation algorithm or image segmentation model to distinguish between background and foreground areas in the original image, and determines the background pixel ratio as the ratio of the area of the background area to the area of the original image. For example, for a skin color map, the skin color map is input into the image segmentation model so that the image segmentation model distinguishes between foreground and background areas in the skin color map, with pixels in the foreground area being foreground pixels and pixels in the background area being background pixels. Furthermore, the background pixel ratio is determined as the ratio of the area of the background area to the area of the original image.
[0129] In some embodiments, after the server obtains the background pixel ratio in the original image, if the background pixel ratio is greater than the ratio threshold, the server executes the following step 302; if the background pixel ratio is less than or equal to the ratio threshold, it means that there are more foreground pixels, i.e., valid pixel information in the original image. At this time, the texture compression effect of this texture compression scheme is not significantly improved, and traditional texture compression algorithms such as DXT or ETC can be used.
[0130] It should be noted that the embodiment of the present disclosure only takes the example of starting the texture compression scheme when the background pixel ratio is greater than the ratio threshold. In some embodiments, there is no need to calculate the background pixel ratio of the original image. Instead, the texture compression scheme can be directly started for any original image to perform texture compression, that is, the operation of "dividing the original image into blocks to obtain multiple target image blocks" in the following step 302 is directly performed on any original image. The embodiment of the present disclosure does not specifically limit whether the background pixel ratio of the original image needs to be greater than the ratio threshold.
[0131] In step 302 , in response to the fact that the proportion of background pixels in the original image is greater than a ratio threshold, the server divides the original image into blocks to obtain a plurality of image blocks.
[0132] The ratio threshold is any value greater than or equal to 0 and less than or equal to 1. For example, the ratio threshold is 0.6 or other values.
[0133] When the proportion of background pixels in the original image is greater than the ratio threshold, it means that the area of the discarded background area is larger, so the texture compression effect will be more obvious. Therefore, the image compression process of the embodiment of the present disclosure is entered, and the original image is segmented and divided into multiple image blocks.
[0134] In some embodiments, the size of each image block in the multiple image blocks is the same, for example, 16×16, 32×32 or 64×64; or, the sizes of different image blocks in the multiple image blocks may also be different, for example, a large background area is divided into larger image blocks, and the boundary between the background area and the foreground area is also finely divided into smaller image blocks. The embodiments of the present disclosure do not specifically limit whether the image blocks are the same.
[0135] Taking the case where each image block has the same size as an example, different image block sizes can be set for original images of different sizes. For example, for an original image of 1024×1024, a 32×32 image block size is used by default. Of course, other default sizes can also be set. This is not specifically limited in the embodiments of the present disclosure.
[0136] In some embodiments, the same image block size is used for original images whose sizes are within a certain range. That is, a mapping relationship is established between the size range of the original image and the image block size, so that when the size range to which the size of the original image belongs is determined, the image block size corresponding to the size range is determined based on the mapping relationship.
[0137] In some embodiments, after the original image is divided into blocks using multiple preset image block sizes, the final image block size is selected according to the compression ratio calculated after the block division. Optionally, the server determines multiple compression ratios based on the multiple preset image block sizes, each compression ratio being the proportion of the target image blocks obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks, wherein the corresponding multiple image blocks refer to all image blocks obtained by dividing the original image using the corresponding preset image block size. That is, for each preset image block size, the server divides the original image into blocks using the image block size, counts the number of overall image blocks after the block division, and then determines the number of target image blocks in the overall image block. The ratio between the number of target image blocks and the number of overall image blocks is determined as the compression ratio for the block division at that image block size.
[0138] Figure 5 is a schematic diagram of an image segmentation provided by an embodiment of the present disclosure, such as Figure 5 As shown in the figure, the server presets three image block sizes: 16×16, 32×32 and 64×64, and uses the above three image block sizes to divide the same original image into blocks. Figure 4 Take the hollow map 402 in the example as an example, we get Figure 5 The three segmentation results 4021-4023 are shown in FIG. After image segmentation, image blocks containing foreground pixels (i.e., pixels with a non-zero transparency value) are considered target image blocks. For example, the shaded image blocks in segmentation results 4021-4023 are target image blocks. Furthermore, the ratio of the number of target image blocks to the total number of image blocks is used as the corresponding compression ratio. Thus, the compression ratios corresponding to the three image block sizes are calculated as 0.140, 0.186, and 0.258, respectively.
[0139] In some embodiments, the server selects a target compression rate from the multiple compression rates, and performs the operation of dividing the original image into blocks in the above step 302 to obtain the multiple image blocks using a preset image block size corresponding to the target compression rate. In the above process, by flexibly selecting the preset image block size corresponding to the target compression rate, it is only necessary to change the target compression rate selection strategy to adaptively adjust the image block size for dividing the original image, thereby meeting business needs in different scenarios. For example, selecting the median of multiple compression rates as the target compression rate can take into account both the compression rate and the memory usage of the index information. Of course, the maximum or minimum value of the multiple compression rates can also be selected as the target compression rate. The embodiment of the present disclosure does not specifically limit the target compression rate selection strategy.
[0140] In some embodiments, the server's strategy for selecting a target compression rate can be flexible and diverse. For example, the median of the multiple compression rates can be selected. For example, the median of 0.186 in the above example is used as the target compression rate, and the original image is segmented using the image block size of 32×32 corresponding to the target compression rate of 0.186. Since the image segmentation has already been performed when calculating the target compression rate, the segmentation results of the remaining two image block sizes are directly deleted, and the subsequent process is executed based on the segmentation result of the image block size of 32×32. At this time, since the smaller the image block size and the lower the compression rate, the more overall image blocks there are, the larger the amount of data required to generate the index information for subsequent compression. For example, for index information in the form of an index map, the size of the index map will be increased, thereby occupying more additional memory. Therefore, a more compromised image block size can be selected to balance the compression rate and the memory usage of the index information.
[0141] In step 303 , the server determines a plurality of target image blocks among the plurality of image blocks, where the target image blocks include foreground pixels in the original image.
[0142] In some embodiments, since the original image has been divided into foreground pixels and background pixels when determining the background pixel ratio in the above step 301, it is relatively convenient to determine the image block containing foreground pixels as the target image block. In other words, the server traverses each image block of the original image and determines whether each image block contains foreground pixels. If the current image block contains foreground pixels, it is determined as the target image block, and similar operations are continued to be performed on the next image block. Finally, all target image blocks in the original image can be determined.
[0143] In step 304, the server generates a compressed image and index information based on the multiple target image blocks. The compressed image is an image obtained by rearranging the multiple target image blocks, and the index information is used to indicate the position mapping relationship of the target image block in the original image and the compressed image.
[0144] In some embodiments, when generating a compressed image, the server copies the multiple target image blocks and rearranges the copied multiple target image blocks to obtain the compressed image. Since the background pixel ratio of the original image itself is relatively high, the number of target image blocks is relatively small relative to the number of overall image blocks, resulting in the size of the compressed image being smaller than the size of the original image. In other words, while preserving the effective pixel information (foreground pixels) in the original image, the size of the original image is compressed, thereby reducing the memory occupied by the original image. Moreover, since the target image blocks are merely rearranged without any modification, the image quality will not be lost, thereby achieving a lossless compression effect.
[0145] Figure 6 is a schematic diagram of the principle of the tile rearrangement process provided by the embodiment of the present disclosure, such as Figure 6 As shown, the texture compression process of the embodiment of the present disclosure is actually a process of migrating or copying the target image block from the original image to the compressed image. On the basis of locating the position of the target image block through the above step 303, it is only necessary to migrate each target image block one by one in sequence to another compressed image, and record the index information of the migration at the same time, so as to achieve the effect of image compression. Since the target image blocks are closely arranged in the compressed image, in other words, the compressed image only contains the target image blocks, and thus the compressed image actually discards the background pixels in the original image. Although the index information will bring additional memory overhead, the memory occupied by the index information is much smaller than the memory occupied by the background pixels in the original image. Therefore, the overall memory overhead is greatly saved without losing image quality.
[0146] Please refer to Figure 6 , schematically, using Figure 5The image is divided into 32×32 blocks, resulting in a block size of 4022, which is used as the original image. The original image 4022 has a size of 1024×1024. For each pixel, the color values of the R (red), G (green), and B (blue) channels, as well as the transparency of the alpha (transparency) channel, are recorded. Therefore, the memory occupied by the original image 4022 is 1024×1024×4. The target image block in the original image 4022 is transferred to another image and rearranged to obtain a compressed image 601. Compressed image 601 does not contain the background pixels of the original image 4022, so the size of compressed image 601 must be much smaller than the size of the original image 4022. Assuming that the size of compressed image 601 is 1024×256, and that the color values of the RGB channels and the transparency of the alpha channel are also retained for each pixel, the memory occupied by compressed image 601 is 1024×256×4. At the same time, to record the position mapping relationship of the target image block before and after migration, an additional index map 602 is generated. Each element in index map 602 only needs to record one position coordinate (the horizontal and vertical coordinates occupy a total of 2 bits). Therefore, the memory occupied by index map 602 is represented as 32×32×2. Obviously, index map 602 only brings a small amount of additional memory overhead. The total memory occupied by compressed image 601 and index map 602 is much smaller than the memory occupied by original image 4022. In addition, each pixel in compressed image 601 retains all the information (color value and transparency) of the corresponding pixel in original image 4022, that is, the image quality is lossless, thus significantly saving memory overhead without sacrificing image quality.
[0147] In some embodiments, when generating index information, for each target image block among the multiple target image blocks, the server determines the mapping relationship between the position coordinates of each target image block in the original image and the position coordinates in the compressed image; based on the mapping relationship of each target image block, the index information is generated, that is, the set of mapping relationships of all target image blocks constitutes the index information.
[0148] Optionally, the data structure of the index information is diverse, such as an index map, a key-value pair, a dynamic array, a hash table, etc. The embodiment of the present disclosure does not specifically limit the data structure of the index information.
[0149] In the above process, since the final index information is generated based on the position mapping relationship of each target image block in the original image and the compressed image, the index information can reflect the set of mapping relationships of all target image blocks. This ensures that the corresponding image blocks will not be migrated to the wrong position when the compressed image is restored to the original image, thereby ensuring that texture compression will not have an adverse effect on the image restoration process.
[0150] In some embodiments, the index information is an index map, and each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image. Precisely because each element in the index map uniquely corresponds to an image block in the original image, the position coordinates of each element in the index map are the same as the position coordinates in each image block, that is, the position coordinates of the elements in the index map naturally represent the position coordinates of the image block in the original image, so it is only necessary to store the position coordinates of the target image block in the compressed image in each element. Therefore, the position coordinates of each element itself in the index map and the position coordinates stored in the element can reflect the position mapping relationship between the target image block in the original image and the compressed image, thereby ensuring that the index map occupies minimal memory.
[0151] based on Figure 6 For example, Figure 6 Index information in the form of an index map is shown. Assume that the target image block with the position coordinates (8, 14) in the original image 4022 is to be migrated to the compressed image 601. After arranging in sequence, the target image block will be migrated to the 4th row and 22nd column of the compressed image 601, that is, the position coordinates of the target image block in the original image 4022 are (8, 14), and the position coordinates in the compressed image 601 are (22, 4). Therefore, (22, 4) is stored in the element located at (8, 14) in the index map 602.
[0152] In some embodiments, since the position coordinates of the target image block actually refer to the position coordinates of the upper left corner of the target image block, assuming that the size of the image block is a, for an image block with position coordinates (8, 14), during the compression process, pixels in the range of (8, 14) to (8+a, 14+a) in the original image need to be copied to the range of (22, 4) to (22+a, 4+a) in the compressed image; similarly, during the decompression or restoration process, pixels in the range of (22, 4) to (22+a, 4+a) in the compressed image need to be copied to the range of (8, 14) to (8+a, 14+a) in the image to be rendered. In order to ensure that the copying process of pixels in the entire range mentioned above is error-free, it involves solving the local coordinates inside the image block. The solution process of the local coordinates inside the image block is expressed as the following formula:
[0153] fracCoord=frac(Coord*tilesNum) / tilesNum
[0154] Among them, frac() represents a function that takes decimals, Coord represents the position coordinates in the original image or the image to be rendered (both are the same), tilesNum represents the number of image blocks contained in the original image, and considering that Coord includes both the horizontal coordinate and the vertical coordinate inside the image block, if the calculated Coord is the horizontal coordinate, tilesNum uses the number of image blocks contained horizontally in the original image. If the calculated Coord is the vertical coordinate, tilesNum uses the number of image blocks contained vertically in the original image. For example, for a square original image, the values of tilesNum in the horizontal and vertical directions are equal.
[0155] It should be noted that the above-mentioned compression process is usually performed by the CPU (Central Processing Unit), while the restoration process is usually performed by the GPU. The calculation principles of the two are not exactly the same in the process of copying each pixel inside the image block. Considering the effect of the rounding function, there may be errors in numerical precision, which will cause the GPU to calculate the local coordinates of the edge pixels of the image block. This will cause edge errors with the position coordinates of the image block read from the index map, which will cause the restored original image to have defects at the edge of the image block.
[0156] In response to the previous question, in some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
[0157] Figure 7 This is a schematic diagram of a block rearrangement process provided by an embodiment of the present disclosure. Figure 7 As shown, taking the index information as index image 701 as an example, compared with Figure 6 For example, suppose a target image block with coordinates (8, 14) in original image 4022 is to be migrated to compressed image 601. After sequential arrangement, the target image block will be migrated to row 4 and column 22 of compressed image 601. That is, the target image block has coordinates (8, 14) in original image 4022 and (22, 4) in compressed image 601. Therefore, the element at (8, 14) in index map 701 stores the pair of coordinates (8, 14) and (22, 4). Since each pair of coordinates is recorded, each coordinate consists of two bits for the horizontal and vertical coordinates, meaning each element occupies four bits in total, the memory occupied by index map 701 is 32 × 32 × 4.
[0158] Since each element of the index map not only stores the position coordinates of the corresponding target image block in the compressed image, but also stores the position coordinates of the target image block in the original image, the GPU can directly read a pair of position coordinates from the index map without having to perform local coordinate solution itself. Although this will slightly increase the memory occupied by the index map, it can reduce the computational overhead of the GPU and effectively alleviate the edge defects caused by the above principle in the image restoration process.
[0159] Figure 8 This is a comparison diagram of rendering results when performing image restoration based on different index maps provided by the embodiment of the present disclosure, such as Figure 8 As shown, the leftmost portion 801 shows the GPU's calculation error in restoring the texture coordinates at the edge of the image block. The error is circled with a white circle. The error here refers to the defect caused by the uneven edge texture between adjacent image blocks. The middle portion shows the restored rendering result 802 when each element in the index map only stores a single position coordinate (i.e., the position coordinate of the corresponding target image block in the compressed image). It can be seen that there are certain defects at the edge. The defects are circled with a white circle. It can be seen that since the defects in rendering result 802 are caused by the edge error of the local solution of the texture coordinates, the defects in rendering result 802 correspond to the texture coordinate errors in the leftmost portion 801. The rightmost portion shows the restored rendering result 803 when each element in the index map stores a pair of position coordinates (i.e., the position coordinates of the corresponding target image block in the original image and the compressed image, respectively). It can be seen that the defects at the edge are significantly improved, thereby further optimizing the quality of the restored image.
[0160] The method provided by the embodiment of the present disclosure divides the original image into blocks, identifies the target image blocks in the original image, and rearranges the target image blocks to obtain a compressed image, so that the background pixels that originally accounted for a large proportion in the original image are discarded in the compressed image, and only the target image blocks containing foreground pixels are retained. At the same time, an index information is generated to indicate the position mapping relationship of the target image blocks before and after the rearrangement, which facilitates the restoration of the compressed image to the original image. Since the storage overhead of the index information is very small, the memory occupied by the image can be greatly reduced while ensuring the lossless image quality.
[0161] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0162] In the above embodiment, an image compression process is introduced, in which the target image blocks in the original image are rearranged to obtain a compressed image. If the target image blocks are simply migrated, it is very likely that when the compressed image is resampled (i.e., the pixels of the target image block in the original image are sampled and then copied to the compressed image), the edges of the target image blocks will be mixed with information from other adjacent image blocks, resulting in obvious defects at the edges when the compressed image is restored.
[0163] Since bilinear sampling is usually used when GPU renders textures, if the target image block samples in the original image are directly migrated to the compressed image, it is inevitable that the components of other image blocks will be mixed at the edge of the target image (this is determined by the bilinear sampling method), resulting in a more obvious sense of splicing in the final restored image, that is, the splicing effect of the restored image is poor. Figure 9 FIG. 1 is a schematic diagram of edge defects in a restored image provided by an embodiment of the present disclosure, such as Figure 9 As shown, the restored image 901 is shown on the left. If the circled area on the left is enlarged, the image 9011 on the right is obtained. It can be found that after enlarging, it can be clearly seen that the splicing traces of the image blocks are quite serious and the splicing effect is not good.
[0164] To address the above problem, we can improve it by adding edges to the target image block. For the edge pixels of the target image block, considering that the GPU's bilinear sampling method will only perform bilinear interpolation on the surrounding 4 pixels, we can consider sampling an additional outer edge of the target image block (i.e., the edge area extending from the edge of the target image block to the outside) when resampling the target image block to improve the above-mentioned edge defect problem. The edge addition method can be divided into external edge addition and internal edge addition. External edge addition refers to sampling an additional edge area outside the target image block, which will cause the size of the target image block stored in the compressed image to become larger. Internal edge addition refers to reducing the original image according to a certain target ratio and still using the original image block size for sampling. When the image block size remains unchanged, the sampled image block includes the reduced target image block and an additional edge area.
[0165] In some embodiments, the external margining process includes: determining a first image block corresponding to each target image block, wherein the first image block includes the corresponding target image block and a first edge region extending outward from the edge of the target image block; and rearranging each of the first image blocks to obtain the compressed image. It can be seen that because the first image block includes the target image block and the first edge region, the image block size of the first image block is larger than the image block size of the target image block. Optionally, the process of rearranging the first image blocks to obtain the compressed image is similar to the process of rearranging the target image blocks to obtain the compressed image in step 304 above, and is not further described here.
[0166] In the above-mentioned external edge adding process, by additionally sampling a circle of the first edge area of the target image block, the edge defect problem caused by the bilinear sampling method is greatly improved, and the texture effect is enhanced.
[0167] In some embodiments, the internal margining process includes: reducing the original image based on a target ratio to obtain a first image; determining, in the first image, a second image block corresponding to each target image block, wherein the second image block includes the corresponding reduced target image block and a second edge region extending outward from the edge of the reduced target image block; and rearranging each of the second image blocks to obtain the compressed image; wherein the target ratio is the ratio of the size of the reduced target image block to the size of the target image block before reduction. Optionally, the process of rearranging the second image blocks to obtain the compressed image is similar to the process of rearranging the target image blocks to obtain the compressed image in step 304 above, and is not further described here.
[0168] Optionally, the image block size of the second image block is the same as the image block size of the target image block. Since the original image is reduced in advance to obtain the first image, even if the same image block size is used for sampling in the first image, the sampled second image block includes the reduced target image block and a second edge area outside the reduced target image block. This can greatly improve the edge defect problem without changing the image block size of each image block stored in the compressed image.
[0169] Figure 10 This is a schematic diagram of a principle of an edge adding method provided by an embodiment of the present disclosure, such as Figure 10As shown, the first row shows a method of directly sampling the target image block in the original image and copying it to the compressed image without adding edges. That is, a 16×16 target image block 1001 is sampled from the original image and migrated to the compressed image for rearrangement. The second row shows a method of using external adding edges. For the 16×16 target image block in the original image, an 18×18 first image block 1002 is sampled and copied to the compressed image for rearrangement. It should be noted that in the restoration process, only the 16×16 target image block (framed by white dotted lines) contained in the 18×18 first image block 1002 is restored. The third row shows the use of an internal margining method. For the 16×16 target image block in the original image, the original image is first reduced according to the target ratio of 14 / 16. Then, in the reduced first image, a 16×16 second image block 1003 is sampled and copied to the compressed image for rearrangement. It should be noted that in the restoration process, only the 14×14 reduced target image block (framed by a white dotted line) contained in the 16×16 second image block 1003 is amplified and restored. Because the external margining method will increase the image block size of the image block stored in the compressed image, it is easy to cause the enlarged image block size to not be a power of 2, which will bring inconvenience to other calculations and processing. Therefore, the internal margining method can be used by default.
[0170] Figure 11 This is a comparison chart of image quality using different edge addition methods provided by the embodiment of the present disclosure. Figure 11 As shown, from left to right, the original image 1101, the image 1102 restored without bordering, the image 1103 restored with internal bordering, and the image 1104 restored with external bordering are shown. Compared to the original image 1101, the image 1102 restored without bordering has multiple image block edge defects (see the horizontal lines in the center of image 1102). After using external bordering or internal bordering, the restored images 1103 and 1104 have improved edge defects compared to the image 1102 restored without bordering, thereby improving the image quality of the restored images.
[0171] Figure 12 is a flowchart of an image processing method according to an exemplary embodiment. Figure 12 As shown, in the embodiment of the present disclosure, the image restoration process will be introduced in detail. The image restoration process can be executed by an electronic device, and the electronic device is taken as the terminal 101 in the above implementation environment as an example for explanation.
[0172] In step 1201, the terminal obtains a compressed image and index information, where the compressed image is an image obtained by rearranging multiple target image blocks of an original image, where the target image blocks include foreground pixels in the original image, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image.
[0173] In some embodiments, the terminal downloads the compressed image and index information from the server in response to an operation instruction triggered by the user. Optionally, the compressed image and index information are obtained by the server performing texture compression on the original image based on the image compression process in the above embodiment.
[0174] Optionally, the operation instruction is an instruction to load the original image. After the user inputs the instruction to load the original image, the terminal sends an image loading request to the server. In response to the image loading request, the server does not return the original image, but returns a compressed image and index information obtained through texture compression to the terminal, which can save communication overhead between the terminal and the server.
[0175] Optionally, in a game rendering scenario, the original image is usually used to enrich the surface details of an object model or a character model. Therefore, the operation instruction is not necessarily a loading instruction for the original image. It may be a game start instruction, or an assembly instruction for a virtual prop, etc. The embodiment of the present disclosure does not specifically limit this.
[0176] In other embodiments, the terminal may also read the compressed image and index information from the local disk. For example, in a video special effects rendering scenario, when editing a recorded selfie video, the user may choose to try out a variety of special effects widgets. Only when a special effects widget is clicked for the first time will the terminal download the corresponding compressed image and index information from the server. If the user clicks the special effects widget again thereafter, the terminal may directly read the corresponding compressed image and index information from the cache. The disclosed embodiment does not specifically limit the method for obtaining the compressed image and index information.
[0177] In step 1202, the terminal obtains foreground pixels from the corresponding target image block in the compressed image for each image block to be rendered based on the index information.
[0178] In some embodiments, for each image block to be rendered, the terminal determines a target image block corresponding to the image block in the compressed image based on the index information; and reads the foreground pixel from the target image block in the compressed image.
[0179] In the above process, since the index information stores the position mapping relationship between the target image block in the original image and the compressed image, for each image block to be rendered, it is only necessary to use its own position coordinates as the position coordinates of the original image, and query the position coordinates of the corresponding target image block in the compressed image from the index information, so as to find the target image block corresponding to the image block, and then read the foreground pixels, which can ensure a one-to-one correspondence between the image block to be rendered and the target image block without error, thereby ensuring a good image restoration effect.
[0180] Optionally, the terminal creates an image to be rendered and performs the same block processing on the image to be rendered as on the original image to ensure that the size of the image blocks to be rendered in the image to be rendered is the same as that of the image blocks in the original image. Similarly, the position coordinates of each image block to be rendered and each image block in the original image are also the same. Since the index information represents the position mapping relationship between the target image block in the original image and the compressed image, in the image restoration process, it is necessary to restore the compressed image to the original image based on the index information. That is, for each image block to be rendered, the position coordinates of the corresponding target image block in the compressed image are queried from the index information based on the position coordinates of the image block in the image to be rendered (equivalent to the position coordinates of the corresponding image block in the original image), and based on the position coordinates of the target image block in the compressed image obtained by the query, the target image block is determined in the compressed image, the foreground pixels in the target image block are read, and the foreground pixels are copied to the image block to be rendered. The above operation is performed for each image block to be rendered, so as to ensure that the original image is displayed after the image to be rendered is rendered.
[0181] In some embodiments, the index information is an index map, and each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image. In this case, after the terminal creates an image to be rendered and divides the image to be rendered into blocks to obtain each image block to be rendered, it can traverse each image block to be rendered, determine the element corresponding to the current image block in the index map, and if the position coordinates are not stored in the element, the transparency value of each pixel in the current image block is set to 0. If the position coordinates are stored in the element, the corresponding target image block is sampled in the compressed image according to the position coordinates, and the foreground pixel is read from the target image block, and the foreground pixel is assigned to the current image block. The above operation is repeated until all image blocks to be rendered are traversed, and the image restoration process is completed.
[0182] Figure 13 This is a schematic diagram of a principle of an image restoration process provided by an embodiment of the present disclosure, such as Figure 13As shown, assuming that the image block (8, 14) to be rendered in the image to be rendered 1301 is to be restored, then according to the position coordinate (8, 14), another position coordinate (22, 4) stored in the element located at (8, 14) is queried from the index map 1302. This position coordinate (22, 4) represents that the position coordinate of the target image block in the compressed image 1303 is the 4th row and 22nd column. Therefore, according to the other position coordinate (22, 4) obtained by querying from the index map 1302, the foreground pixel is read in the target image block at the 4th row and 22nd column in the compressed image 1303 and assigned to the image block (8, 14) to be rendered in the image to be rendered 1301.
[0183] In some embodiments, the index information is an index map, and each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the original image and the compressed image, respectively. In this case, after the terminal creates the image to be rendered and divides the image to be rendered into blocks to obtain the image blocks to be rendered, it can traverse each element in the index map. If the current element does not store the position coordinates, the transparency value of the image block to be rendered corresponding to the current element is set to 0. If the current element stores a pair of position coordinates, the target image block is first located in the image to be rendered according to the position coordinates of the target image block in the original image, and then the target image block is sampled in the compressed image according to the position coordinates of the target image block in the compressed image, and the foreground pixel is read from the target image block. The foreground pixel is assigned to the image block located in the image to be rendered before, and the above operation is repeated until the index map is traversed, and the image restoration process is completed.
[0184] In step 1203, the terminal renders the corresponding image block based on the foreground pixels corresponding to each image block to be rendered to obtain the original image.
[0185] In some embodiments, the operation of rendering image blocks on the terminal can be implemented by controlling the GPU by the rendering engine. For each image block to be rendered, in the rendering pipeline Shader of the rendering engine, according to the texture coordinates of the current image block, the position coordinates of the corresponding target image block in the compressed image are read from the index information, and then the target image block in the compressed image is located, and the target image block is sampled to obtain the foreground pixel (including color value and transparency value), and the foreground pixel is assigned to the current image block to be rendered, so that the original image can be rendered to the terminal screen.
[0186] Figure 14 This is a schematic diagram of the principle of image compression and image restoration provided by an embodiment of the present disclosure, such as Figure 14As shown, in the image compression stage, the image compression method in the previous embodiment is used to rearrange the target image blocks in the original image 1401 to obtain a compressed image 1402 and index information 1403. In the image restoration process, the image restoration method in the disclosed embodiment is used to restore the compressed image 1402 to the original image 1401 based on the position mapping relationship recorded in the index information 1403. This can greatly save the memory occupied by the image while ensuring that the quality of the restored image is lossless.
[0187] The method provided by the embodiment of the present disclosure obtains a compressed image and index information, and directly restores the compressed image to the original image based on the index information. Since each target image block of the compressed image stores the original foreground pixels in the original image, the restored original image is lossless. That is, while greatly saving memory usage, the image quality of the restored original image is guaranteed to be lossless, greatly improving the texture compression effect.
[0188] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0189] In some embodiments, based on the texture compression methods provided in the above embodiments, after compressing and restoring the original image, tests were performed according to different original image sizes and different image block sizes. The test results are shown in Table 1 below.
[0190] Table 1
[0191]
[0192] Schematically, assuming that the side length of the original image is A, the side length of the image block to be divided is a, the original image and the image block are both square, and the compression ratio is R. This compression ratio refers to the ratio of the original image to be compressed using this scheme (equivalent to the ideal compression rate), but due to factors such as the use of the edge addition method and the actual fill rate of the compressed image, the final effective compression rate will be greater than the ideal compression ratio.
[0193] In addition, the value of the internal margin vertical scaling column refers to the target ratio used when the original image is reduced when the internal margin is used, wherein the color values of the RGB red, green and blue channels and the transparency value of the alpha channel are saved for each pixel in the original image.
[0194] On this basis, since there are a total of 4 channels, the total memory before compression refers to the amount of memory occupied by the original image, that is, the total memory before compression can be expressed as: A*A*4.
[0195] The total memory after compression consists of two parts. One is the memory occupied by the compressed image, which is equal to the product of the memory occupied by the original image and the compression ratio, and can be expressed as: A*A*4*R. The other part is the memory occupied by the index map. Since the side length of the image block is a, the total number of image blocks can be expressed as: (A / a)*(A / a). Obviously, the memory occupied by the index map can be expressed as: (A / a)*(A / a)*4. Combining these two parts, we can see that the total memory after compression = compressed image memory + index map memory = A*A*4*R + (A / a)*(A / a)*4.
[0196] Among them, the effective compression rate refers to the ratio of the total memory after compression to the total memory before compression, that is, the value of the second to last column in each row of the table is divided by the value of the third to last column to obtain the value of the last column. The effective compression rate can be expressed as: [A*A*4*R+(A / a)*(A / a)*4] / (A*A*4). It can be seen that the texture compression method provided by the embodiment of the present disclosure can bring 2 to 4 times the memory savings of texture compression.
[0197] Taking the video special effects rendering scene on the mobile terminal as an example, assuming that special effects rendering is performed on different perspectives of the hat special effects (a total of 269 images), taking a single image as an example, Figure 15 This is a comparison diagram of rendering effects before and after texture compression provided by an embodiment of the present disclosure. Figure 15 As shown, the left image 1501 is the rendering effect before compression, and its memory occupancy is 167MB. The right image 1502 is the rendering effect after compression, and its memory occupancy is 103MB. The image quality of the left image 1501 and the right image 1502 is lossless, and the effective compression ratio is 0.62, which saves a total of 38% of memory usage. This is of great rendering significance for mobile devices with very efficient memory space. When converting the original image into a compressed image, only the target image blocks are rearranged without changing the texture format. It is easily compatible with other technologies such as H264 audio and video encoding technology, and has high availability and high scalability, and can be implemented in any system platform.
[0198] Figure 16 FIG. 1 is a block diagram showing a logical structure of an image processing device according to an exemplary embodiment. Figure 16 The device includes a blocking unit 1601, a determining unit 1602 and a generating unit 1603.
[0199] The blocking unit 1601 is configured to block the original image to obtain multiple image blocks;
[0200] A determining unit 1602 is configured to determine a plurality of target image blocks among the plurality of image blocks, where the target image blocks include foreground pixels in the original image;
[0201] The generation unit 1603 is configured to generate a compressed image and index information based on the multiple target image blocks, where the compressed image is an image obtained by rearranging the multiple target image blocks, and the index information is used to indicate a position mapping relationship between the target image block in the original image and the compressed image.
[0202] The device provided by the embodiment of the present disclosure divides the original image into blocks, identifies the target image blocks in the original image, and rearranges the target image blocks to obtain a compressed image, so that the background pixels that originally accounted for a large proportion in the original image are discarded in the compressed image, and only the target image blocks containing foreground pixels are retained. At the same time, an index information is generated to indicate the position mapping relationship of the target image blocks before and after the rearrangement, which facilitates the restoration of the compressed image to the original image. Since the storage overhead of the index information is very small, the memory occupied by the image can be greatly reduced while ensuring the lossless image quality.
[0203] In some embodiments, the generating unit 1603 is configured to perform:
[0204] The multiple target image blocks are copied, and the copied multiple target image blocks are rearranged to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
[0205] In some embodiments, the generating unit 1603 is configured to perform:
[0206] Determine a first image block corresponding to each target image block, where the first image block includes the corresponding target image block and a first edge region extending outward from an edge of the target image block;
[0207] The first image blocks are rearranged to obtain the compressed image.
[0208] In some embodiments, the generating unit 1603 is configured to perform:
[0209] Based on the target ratio, the original image is reduced to obtain a first image;
[0210] In the first image, determining a plurality of second image blocks corresponding to each target image block, wherein the second image blocks include the corresponding reduced target image block and a second edge region extending outward from an edge of the reduced target image block;
[0211] The second image blocks are rearranged to obtain the compressed image; wherein the target ratio is the ratio of the size of the target image block after reduction to the size of the target image block before reduction.
[0212] In some embodiments, the generating unit 1603 is configured to perform:
[0213] For each target image block among the multiple target image blocks, determining a mapping relationship between a position coordinate of each target image block in the original image and a position coordinate of each target image block in the compressed image;
[0214] The index information is generated based on the mapping relationship of each target image block.
[0215] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image.
[0216] In some embodiments, the index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
[0217] In some embodiments, the block unit 1601 is further configured to perform:
[0218] Determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being a proportion of a target image block obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks;
[0219] selecting a target compression ratio from the plurality of compression ratios;
[0220] The step of dividing the original image into blocks to obtain the plurality of image blocks is performed using a preset image block size corresponding to the target compression rate.
[0221] Regarding the apparatus in the above embodiment, the specific manner in which each unit performs operations has been described in detail in the embodiment of the image processing method, and will not be elaborated on here.
[0222] Figure 17 FIG. 1 is a block diagram showing a logical structure of an image processing apparatus according to an exemplary embodiment. Figure 17 As shown, the device includes a first acquisition unit 1701, a second acquisition unit 1702 and a rendering unit 1703.
[0223] A first acquiring unit 1701 is configured to acquire a compressed image and index information, wherein the compressed image is an image obtained by rearranging multiple target image blocks of an original image, the target image blocks including foreground pixels in the original image, and the index information is used to indicate a position mapping relationship between the target image blocks in the original image and the compressed image;
[0224] The second acquiring unit 1702 is configured to acquire foreground pixels from a corresponding target image block in the compressed image for each image block to be rendered based on the index information;
[0225] The rendering unit 1703 is configured to render the corresponding image block based on the foreground pixels corresponding to each image block to be rendered, to obtain the original image.
[0226] The device provided by the embodiment of the present disclosure obtains a compressed image and index information, and directly restores the compressed image to the original image based on the index information. Since each target image block of the compressed image stores the original foreground pixels in the original image, the restored original image is lossless. That is, while greatly saving memory usage, the image quality of the restored original image is guaranteed to be lossless, greatly improving the texture compression effect.
[0227] In some embodiments, the second obtaining unit 1702 is configured to execute:
[0228] For each image block to be rendered, determining a target image block in the compressed image corresponding to the image block based on the index information;
[0229] The foreground pixel is read from the target image block of the compressed image.
[0230] Regarding the apparatus in the above embodiment, the specific manner in which each unit performs operations has been described in detail in the embodiment of the image processing method, and will not be elaborated on here.
[0231] Figure 18 The following is a block diagram of a terminal structure provided by an exemplary embodiment of the present disclosure. Terminal 1800 is an exemplary illustration of an electronic device, which may be a smartphone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 player (Moving Picture Experts Group Audio Layer IV), a laptop computer, or a desktop computer. Terminal 1800 may also be referred to as a user device, a portable terminal, a laptop terminal, a desktop terminal, or other similar names.
[0232] Typically, the terminal 1800 includes a processor 1801 and a memory 1802 .
[0233] The processor 1801 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 1801 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 1801 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1801 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1801 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0234] Memory 1802 may include one or more computer-readable storage media, which may be non-transitory. Memory 1802 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in memory 1802 is used to store at least one instruction, which is executed by processor 1801 to implement the image processing method provided in various embodiments of the present disclosure.
[0235] In some embodiments, terminal 1800 may optionally include a peripheral device interface 1803 and at least one peripheral device. The processor 1801, memory 1802, and peripheral device interface 1803 may be connected via a bus or signal lines. Each peripheral device may be connected to peripheral device interface 1803 via a bus, signal lines, or circuit boards. Specifically, the peripheral device may include at least one of a radio frequency circuit 1804, a touchscreen display 1805, a camera assembly 1806, an audio circuit 1807, a positioning assembly 1808, and a power supply 1809.
[0236] The peripheral device interface 1803 can be used to connect at least one I / O (Input / Output)-related peripheral device to the processor 1801 and the memory 1802. In some embodiments, the processor 1801, the memory 1802, and the peripheral device interface 1803 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1801, the memory 1802, and the peripheral device interface 1803 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.
[0237] The RF circuit 1804 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1804 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1804 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals into electrical signals. Optionally, the RF circuit 1804 includes an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The RF circuit 1804 can communicate with other terminals via at least one wireless communication protocol. Such wireless communication protocols include, but are not limited to, metropolitan area networks, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1804 may also include circuits related to NFC (Near Field Communication), which is not limited in this disclosure.
[0238] The display screen 1805 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1805 is a touch screen display, the display screen 1805 also has the ability to collect touch signals on the surface or above the surface of the display screen 1805. The touch signal can be input as a control signal to the processor 1801 for processing. At this time, the display screen 1805 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, there can be one display screen 1805, which is set on the front panel of the terminal 1800; in other embodiments, there can be at least two display screens 1805, which are respectively set on different surfaces of the terminal 1800 or in a folding design; in still other embodiments, the display screen 1805 can be a flexible display screen, which is set on the curved surface or folding surface of the terminal 1800. Even more, the display screen 1805 can be set as a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 1805 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0239] The camera assembly 1806 is used to capture images or videos. Optionally, the camera assembly 1806 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the terminal, and the rear camera is arranged on the back of the terminal. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1806 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0240] The audio circuit 1807 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals that are input into the processor 1801 for processing, or input into the radio frequency circuit 1804 to achieve voice communication. For the purpose of stereo sound collection or noise reduction, there may be multiple microphones, each located in different parts of the terminal 1800. The microphone may also be an array microphone or an omnidirectional collection microphone. The speaker is used to convert electrical signals from the processor 1801 or the radio frequency circuit 1804 into sound waves. The speaker may be a traditional thin film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert electrical signals into sound waves audible to humans, but also convert electrical signals into sound waves inaudible to humans for purposes such as distance measurement. In some embodiments, the audio circuit 1807 may also include a headphone jack.
[0241] Positioning component 1808 is used to locate the current geographic location of terminal 1800 to implement navigation or LBS (Location Based Service). Positioning component 1808 can be based on the US GPS (Global Positioning System), China's BeiDou system, Russia's Greninja system, or the European Union's Galileo system.
[0242] Power supply 1809 is used to power various components in terminal 1800. Power supply 1809 can be AC power, DC power, a disposable battery, or a rechargeable battery. When power supply 1809 includes a rechargeable battery, the rechargeable battery can support wired charging or wireless charging. The rechargeable battery can also be used to support fast charging technology.
[0243] In some embodiments, the terminal 1800 further includes one or more sensors 1810 , including but not limited to: an acceleration sensor 1811 , a gyroscope sensor 1812 , a pressure sensor 1813 , a fingerprint sensor 1814 , an optical sensor 1815 , and a proximity sensor 1816 .
[0244] The accelerometer 1811 can detect the magnitude of acceleration along the three coordinate axes of the coordinate system established by the terminal 1800. For example, the accelerometer 1811 can be used to detect the components of gravity acceleration along the three coordinate axes. The processor 1801 can control the touch screen display 1805 to display the user interface in a landscape or portrait view based on the gravity acceleration signal collected by the accelerometer 1811. The accelerometer 1811 can also be used to collect game or user motion data.
[0245] The gyroscope sensor 1812 can detect the orientation and rotation angle of the terminal 1800. It can work in conjunction with the accelerometer 1811 to collect the user's 3D movements on the terminal 1800. Based on the data collected by the gyroscope sensor 1812, the processor 1801 can implement the following functions: motion sensing (for example, changing the UI based on the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0246] The pressure sensor 1813 can be located on the side frame of the terminal 1800 and / or below the touchscreen display 1805. When located on the side frame of the terminal 1800, the pressure sensor 1813 can detect the user's gripping signal on the terminal 1800. The processor 1801 then performs left-hand or right-hand identification or shortcut operations based on the gripping signal collected by the pressure sensor 1813. When the pressure sensor 1813 is located below the touchscreen display 1805, the processor 1801 controls the operable controls on the UI based on the user's pressure on the touchscreen display 1805. Operable controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0247] The fingerprint sensor 1814 is used to collect the user's fingerprint. The processor 1801 identifies the user's identity based on the fingerprint collected by the fingerprint sensor 1814, or the fingerprint sensor 1814 identifies the user's identity based on the collected fingerprint. When the user's identity is recognized as a trusted identity, the processor 1801 authorizes the user to perform relevant sensitive operations, such as unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 1814 can be set on the front, back, or side of the terminal 1800. When a physical button or manufacturer logo is provided on the terminal 1800, the fingerprint sensor 1814 can be integrated with the physical button or manufacturer logo.
[0248] Optical sensor 1815 is used to detect ambient light intensity. In one embodiment, processor 1801 can control the display brightness of touchscreen display 1805 based on the ambient light intensity detected by optical sensor 1815. Specifically, when the ambient light intensity is high, the display brightness of touchscreen display 1805 is increased; when the ambient light intensity is low, the display brightness of touchscreen display 1805 is decreased. In another embodiment, processor 1801 can also dynamically adjust the capture parameters of camera assembly 1806 based on the ambient light intensity detected by optical sensor 1815.
[0249] Proximity sensor 1816, also known as a distance sensor, is typically located on the front panel of terminal 1800. Proximity sensor 1816 is used to detect the distance between the user and the front of terminal 1800. In one embodiment, when proximity sensor 1816 detects that the distance between the user and the front of terminal 1800 is gradually decreasing, processor 1801 controls touchscreen display 1805 to switch from the screen-on state to the screen-off state. When proximity sensor 1816 detects that the distance between the user and the front of terminal 1800 is gradually increasing, processor 1801 controls touchscreen display 1805 to switch from the screen-off state to the screen-on state.
[0250] Those skilled in the art will understand that Figure 18 The structure shown in the figure does not constitute a limitation on the terminal 1800, and the terminal 1800 may include more or fewer components than shown in the figure, or combine certain components, or adopt a different component arrangement.
[0251] Figure 19 1 is a structural diagram of a server provided in an embodiment of the present disclosure, and server 1900 is an exemplary illustration of an electronic device. The server 1900 may have relatively large differences due to different configurations or performances, and may include one or more processors (Central Processing Units, CPU) 1901 and one or more memories 1902, wherein the memory 1902 stores at least one program code, and the at least one program code is loaded and executed by the processor 1901 to implement the image processing method provided in each of the above embodiments. Of course, the server 1900 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output. The server 1900 may also include other components for implementing device functions, which will not be described here.
[0252] In an exemplary embodiment, a computer-readable storage medium including at least one instruction is further provided, such as a memory including at least one instruction. The at least one instruction can be executed by a processor in an electronic device to perform the image processing method in the above embodiment. Optionally, the computer-readable storage medium can be a non-transitory computer-readable storage medium, such as a ROM (Read-Only Memory), a RAM (Random-Access Memory), a CD-ROM (Compact Disc Read-Only Memory), a magnetic tape, a floppy disk, an optical data storage device, etc.
[0253] In an exemplary embodiment, a computer program product is further provided, including one or more instructions, which can be executed by a processor of an electronic device to implement the image processing methods provided in the above embodiments.
[0254] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the following claims.
[0255] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. An image processing method, characterized in that: include: In response to a background pixel ratio in the original image being greater than a ratio threshold, dividing the original image into blocks to obtain a plurality of image blocks; determining a plurality of target image blocks among the plurality of image blocks, the target image blocks including foreground pixels in the original image; Based on a target ratio, the original image is reduced to obtain a first image; in the first image, a second image block corresponding to each target image block is determined, wherein the second image block includes the corresponding reduced target image block and a second edge region extending outward from an edge of the reduced target image block, and the image block size of the second image is the same as the image block size of the target image block; and the second image blocks are rearranged to obtain a compressed image; wherein the target ratio is the ratio of the size of the target image block after reduction to the size of the target image block before reduction; Based on the multiple target image blocks, index information is generated, the compressed image is an image obtained by rearranging the second image blocks, the second image blocks are closely arranged in the compressed image, and the index information is used to indicate the position mapping relationship between the second image blocks in the original image and the compressed image.
2. The image processing method according to claim 1, wherein: The method further comprises: The multiple target image blocks are copied, and the copied multiple target image blocks are rearranged to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
3. The image processing method according to claim 1, wherein: The generating index information based on the multiple target image blocks includes: For each target image block among the plurality of target image blocks, determining a mapping relationship between position coordinates of each target image block in the original image and position coordinates in the compressed image; The index information is generated based on the mapping relationship of each target image block.
4. The image processing method according to claim 1, wherein: The index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image.
5. The image processing method according to claim 1, wherein: The index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
6. The image processing method according to claim 1, wherein: The method further comprises: Determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being a proportion of a target image block obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks; selecting a target compression ratio from the plurality of compression ratios; The step of dividing the original image into blocks to obtain the plurality of image blocks is performed using a preset image block size corresponding to the target compression rate.
7. An image processing method, characterized in that: include: Obtaining a compressed image and index information, wherein the compressed image is an image obtained by rearranging a plurality of second image blocks, wherein the second image blocks are image blocks corresponding to each target image block determined in the first image, the second image blocks including the corresponding reduced target image blocks and second edge regions extending outward from edges of the reduced target image blocks, the image size of the target image blocks being the same as the image block size of the second image blocks, and the first image being obtained by reducing the original image based on a target ratio; The second image blocks are closely arranged in the compressed image, the target image block includes foreground pixels in the original image, the index information is used to indicate a position mapping relationship between the second image blocks in the original image and the compressed image, and a proportion of background pixels in the original image is greater than a proportion threshold; Based on the index information, for each image block to be rendered, obtaining foreground pixels from the corresponding target image block in the compressed image; Based on the foreground pixels corresponding to each image block to be rendered, the corresponding image block is rendered to obtain the original image.
8. The method according to claim 7, characterized in that The acquiring, for each image block to be rendered, a foreground pixel from a corresponding target image block in the compressed image based on the index information comprises: For each image block to be rendered, determining a target image block in the compressed image corresponding to the image block based on the index information; The foreground pixels are read from the target image block of the compressed image.
9. An image processing device, characterized in that: include: A blocking unit is configured to, in response to a background pixel ratio in the original image being greater than a ratio threshold, block the original image to obtain a plurality of image blocks; a determining unit configured to determine a plurality of target image blocks among the plurality of image blocks, wherein the target image blocks include foreground pixels in the original image; A generating unit is configured to perform reduction of the original image based on a target ratio to obtain a first image; in the first image, determine a second image block corresponding to each target image block, the second image block including a corresponding reduced target image block and a second edge area extending outward from the edge of the reduced target image block, and the image block size of the second image is the same as the image block size of the target image block; rearrange the respective second image blocks to obtain a compressed image; wherein the target ratio is the ratio of the size of the reduced target image block to the size of the target image block before reduction; and further configured to generate index information based on the multiple target image blocks, the compressed image being an image obtained by rearranging the respective second image blocks, the second image blocks being closely arranged in the compressed image, and the index information being used to indicate a position mapping relationship between the second image blocks in the original image and the compressed image.
10. The image processing device according to claim 9, wherein The generating unit is configured to perform: The multiple target image blocks are copied, and the copied multiple target image blocks are rearranged to obtain the compressed image, wherein the size of the compressed image is smaller than the size of the original image.
11. The image processing device according to claim 9, wherein The generating unit is configured to perform: For each target image block among the plurality of target image blocks, determining a mapping relationship between position coordinates of each target image block in the original image and position coordinates in the compressed image; The index information is generated based on the mapping relationship of each target image block.
12. The image processing device according to claim 9, wherein The index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the element in the index map corresponding to the target image block stores the position coordinates of the target image block in the compressed image.
13. The image processing device according to claim 9, wherein The index information is an index map, each element in the index map corresponds one-to-one to each image block in the original image, and the elements in the index map corresponding to the target image block store the position coordinates of the target image block in the original image and the compressed image respectively.
14. The image processing device according to claim 9, wherein The chunking unit is further configured to perform: Determining multiple compression ratios based on multiple preset image block sizes, each compression ratio being a proportion of a target image block obtained by dividing the original image into blocks using the corresponding preset image block size in the corresponding multiple image blocks; selecting a target compression ratio from the plurality of compression ratios; The step of dividing the original image into blocks to obtain the plurality of image blocks is performed using a preset image block size corresponding to the target compression rate.
15. An image processing device, characterized in that: include: a first acquiring unit configured to acquire a compressed image and index information, wherein the compressed image is an image obtained by rearranging a plurality of second image blocks, wherein the second image blocks are image blocks corresponding to each target image block determined in the first image, wherein the second image blocks include the corresponding reduced target image blocks and second edge regions extending outward from edges of the reduced target image blocks, wherein the image size of the target image blocks is the same as the image block size of the second image blocks, and wherein the first image is obtained by reducing the original image based on a target ratio; The target image blocks are closely arranged in the compressed image, the target image blocks include foreground pixels in the original image, the index information is used to indicate a position mapping relationship between the second image blocks in the original image and the compressed image, and a proportion of background pixels in the original image is greater than a proportion threshold; A second acquiring unit is configured to acquire foreground pixels from a corresponding target image block in the compressed image for each image block to be rendered based on the index information; The rendering unit is configured to render the corresponding image block based on the foreground pixels corresponding to each image block to be rendered, so as to obtain the original image.
16. The device according to claim 15, characterized in that The second acquiring unit is configured to execute: For each image block to be rendered, determining a target image block in the compressed image corresponding to the image block based on the index information; The foreground pixels are read from the target image block of the compressed image.
17. An electronic device, characterized in that: include: one or more processors; one or more memories for storing the one or more processor-executable instructions; The one or more processors are configured to execute the instructions to implement the image processing method according to any one of claims 1 to 6 or claims 7 to 8.
18. A computer-readable storage medium, characterized in that When at least one instruction in the computer-readable storage medium is executed by one or more processors of an electronic device, the electronic device is enabled to perform the image processing method according to any one of claims 1 to 6 or claims 7 to 8.
19. A computer program product, characterized in that The image processing method comprises one or more instructions, wherein the one or more instructions are executed by one or more processors of an electronic device, so that the electronic device can perform the image processing method according to any one of claims 1 to 6 or claims 7 to 8.
Citation Information
Patent Citations
Out-of-order coding
CN102187655A