Image processing method, device, and computer equipment

By dividing and classifying images, discarding the transparent parts, retaining only the opaque parts and recording their information, the problem of memory waste occupied by transparent parts in texture images is solved, and the efficiency of memory and GPU usage is improved.

CN112419141BActive Publication Date: 2024-09-10SHANGHAI HODE INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010746601.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-29
Publication Date
2024-09-10
Estimated Expiration
2040-07-29

AI Technical Summary

Technical Problem

In the existing technology, when the transparency of half of the texture image is greater than 0 and the other half is completely transparent, the same memory and GPU resources are used for storage and operation, but the completely transparent part is invalid during rendering and display, resulting in a waste of memory performance.

Method used

By dividing the image to be processed into blocks, classify the transparent and opaque block pictures, discard the transparent part, keep only the opaque part, record the size, position and texture coordinates of the opaque block picture, and save them to a file for GPU rendering. .

Benefits of technology

It reduces the memory space occupied by the transparent part of the image, improves memory usage efficiency, and reduces GPU computing overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112419141B
    Figure CN112419141B
Patent Text Reader

Abstract

The present application discloses a method, device, computer equipment and readable storage medium for image processing, belonging to the field of image processing technology. The image processing method of the present application comprises: obtaining an image to be processed, and performing block processing on the image to be processed to obtain N block images, wherein N is a natural number greater than 1; classifying and processing the N block images to obtain transparent block images and opaque block images; splicing all the opaque block images to obtain an atlas; recording the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and saving the recorded data to a file in a preset format. The present application can save memory space.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, apparatus, computer equipment, and computer-readable storage medium. Background Art

[0002] In the prior art, when half of a texture image has a transparency greater than 0 and the other half has a transparency of zero, that is, it is completely transparent. We use the same amount of memory and GPU computing to store and compute these two parts. However, when rendering and displaying the completely transparent part, the result is that nothing is displayed, resulting in a waste of memory performance. Summary of the invention

[0003] In view of this, a method and apparatus for image processing, a computer device and a computer-readable storage medium are provided to solve the problem of memory performance consumption when displaying images in the prior art.

[0004] This application provides a method for processing an image, including:

[0005] Obtain a to-be-processed picture, and perform block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1;

[0006] Classify the N block images to obtain transparent block images and opaque block images;

[0007] All the opaque block images are stitched together to obtain an atlas;

[0008] Record the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and save the recorded data to a file in a preset format.

[0009] Optionally, the image processing method further includes:

[0010] Obtain the file, and determine the vertex coordinates and texture coordinates of four vertices of each opaque block image according to the data recorded in the file;

[0011] The determined vertex coordinates and texture coordinates are passed to a GPU, so that the GPU can render and restore the image to be processed according to the vertex coordinates, the texture coordinates and the atlas.

[0012] Optionally, the position of each opaque block image in the image to be processed is the first vertex coordinate of the upper left corner vertex of the opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas are the first texture coordinates of the upper left corner vertex of the opaque block image in the atlas. Determining the vertex coordinates and texture coordinates of the four vertices of each opaque block image according to the data recorded in the file includes:

[0013] Get the size of each opaque tile image and the size of the atlas;

[0014] Calculate the vertex coordinates of four vertices of each opaque block image according to the coordinates of each opaque first vertex and the size of each opaque block image;

[0015] The texture coordinates of four vertices of each opaque tile image are calculated according to each opaque first texture coordinate, the size of each opaque tile image, and the size of the atlas.

[0016] Optionally, after the step of obtaining the image to be processed and performing block processing on the image to be processed to obtain N block images, the method further includes:

[0017] The N block pictures are marked in a preset order to distinguish different block pictures.

[0018] Optionally, the classifying the N block images to obtain transparent block images and opaque block images includes:

[0019] Detect the transparency values ​​of all pixels of each block image respectively;

[0020] If the transparency values ​​of all pixels of the currently detected block image are preset values, the currently detected block image is used as a transparent block image, otherwise, the currently detected block image is used as an opaque block image.

[0021] Optionally, after the step of classifying the N block images to obtain transparent block images and opaque block images, the method further includes:

[0022] The opaque block picture is marked with the first identification information, and the transparent block picture is marked with the second identification information.

[0023] Optionally, before the step of performing block processing on the image to be processed, the step further includes:

[0024] Determine whether the image to be processed is a transparent image.

[0025] The present application also provides an image processing device, comprising:

[0026] An acquisition module is used to acquire a to-be-processed picture, and perform block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1;

[0027] A classification module, used for classifying the N block images to obtain transparent block images and opaque block images;

[0028] The stitching module is used to stitch all the opaque block images to obtain an atlas;

[0029] A recording module is used to record the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and save the recorded data to a file in a preset format.

[0030] The present application also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0031] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.

[0032] Beneficial effects of the above technical solution:

[0033] In the technical scheme, by obtaining a picture to be processed and performing block processing on the picture to be processed, N block pictures are obtained, wherein N is a natural number greater than 1; the N block pictures are classified and processed to obtain transparent block pictures and opaque block pictures; all the opaque block pictures are spliced ​​to obtain an atlas; the size of the atlas, the size of each opaque block picture, the position of each opaque block picture in the picture to be processed, and the texture coordinates of each opaque block picture in the atlas are recorded, and the recorded data is saved in a file of a preset format. This embodiment can reduce the memory space occupied by the transparent part of the picture by discarding the transparent block picture when the picture to be processed contains the transparent block picture, and only retaining the opaque block picture. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 A framework diagram of an embodiment of a system framework diagram for image processing described in this application;

[0035] Figure 2A flowchart of an embodiment of the image processing method described in this application;

[0036] Figure 3 This is a schematic diagram of the image to be processed in this application;

[0037] Figure 4 A detailed flow chart of the steps of classifying the N block images to obtain transparent block images and opaque block images for this application;

[0038] Figure 5 is a schematic diagram of the atlas in this application;

[0039] Figure 6 A flowchart of another embodiment of the image processing method described in the present application;

[0040] Figure 7 A detailed flow chart of the steps of determining the vertex coordinates and texture coordinates of the four vertices of each opaque block image according to the data recorded in the file for the present application;

[0041] Figure 8 This is a schematic diagram of the image to be processed restored in this application;

[0042] Fig. 9 A module diagram of an embodiment of the image processing device described in the present application;

[0043] Fig.10 A schematic diagram of the hardware structure of a computer device for executing the image processing method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0044] The advantages of the present application are further described below in conjunction with the accompanying drawings and specific embodiments.

[0045] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0046] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0047] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0048] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.

[0049] Please refer to Figure 1 , Figure 1 : is a schematic diagram showing the application environment of the image processing method according to an embodiment of the present application. In an exemplary embodiment, the system of the application environment may include a user terminal 10 and a background server 20. Among them, the user terminal 10 forms a wireless or wired connection with the background server 20, and the user terminal 10 has a corresponding application client or web client. Among them, the user terminal 10 can be a PC, a mobile phone, an iPAD, a tablet computer, a laptop computer, a personal digital assistant, etc. The background server 20 can be a rack server, a blade server, a tower server or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc.

[0050] Figure 2 The flowchart of the image processing method according to the first embodiment of the present application is schematically shown. The method is applied in a computer device, and it can be understood that the flowchart in the embodiment of the method is not used to limit the order of executing the steps.

[0051] like Figure 2 As shown, the image processing method includes steps S20 to S22, wherein:

[0052] Step S20, obtaining a to-be-processed picture, and performing block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1;

[0053] Specifically, when the image to be processed is processed in blocks, the number of blocks can be determined according to the size of the image to be processed and the size of the block images. For example, if the size of the image to be processed is a 1024*1024 pixel image and the size of the block image is a 128*128 pixel image, then when the image to be processed is processed in blocks, it can be divided into (1024*1024) / (128*128)=64 block images.

[0054] It should be noted that when the to-be-processed picture is processed in blocks, the sizes of different block pictures may be the same or different, and the shapes of the block pictures may be square or rectangular. In this embodiment, the obtained block pictures are preferably small block pictures of the same size and shape.

[0055] In a specific example, a picture to be processed with a size of 1024*1024 pixels can be divided into the following Figure 3 The 64 tile images shown.

[0056] In an exemplary embodiment, after obtaining the image to be processed, in order to avoid the image to be processed being processed in blocks when the image to be processed is not a transparent image, resulting in the waste of computing resources. In this embodiment, before the image to be processed is processed in blocks, it can be determined whether the image to be processed is a transparent image. Wherein, the transparent image is an image whose transparency values ​​of all pixels of the image are preset values. The preset value is a value representing that the pixel is a transparent pixel. For example, when the transparency value of the pixel is zero, it represents that the pixel is a transparent pixel. When the transparency value of the pixel is non-zero, it represents that the pixel is a non-transparent pixel, and the preset value is zero. That is to say, when it is determined that the transparency values ​​of all pixels of the image to be processed are zero, it can be determined that the image to be processed is a transparent image; when it is determined that the transparency values ​​of all pixels of the image to be processed are non-zero, it can be determined that the image to be processed is a non-transparent image. In this embodiment, when it is determined that the image to be processed is a non-transparent image, there is no need to perform subsequent operations of processing the image in blocks.

[0057] In an exemplary embodiment, after the image is processed into blocks, in order to facilitate the distinction between different block images, after the step of obtaining the image to be processed and processing the image to be processed into blocks to obtain N block images, the step further includes:

[0058] The N block pictures are marked in a preset order to distinguish different block pictures.

[0059] Specifically, the preset order is pre-set, for example, the preset order is from left to right and from top to bottom, that is, when marking all the block pictures, they are first marked from left to right and then from top to bottom.

[0060] In this embodiment, when marking the block images, they can be marked in an auto-incremental manner according to the number of blocks. For example, Figure 3The picture to be processed is divided into 64 small blocks as shown, and each block picture can be marked as 001, 002, 003..., 064 in order from left to right and from top to bottom.

[0061] Step S21, classifying the N block images to obtain transparent block images and opaque block images.

[0062] Specifically, a transparent block image refers to a block image in which the transparency values ​​of all pixels included in the block image are equal to a preset value, for example, the transparency values ​​are all 0. An opaque block image refers to a block image in which there are pixels whose transparency values ​​are not equal to the preset value, for example, there are pixels whose transparency values ​​are not 0.

[0063] In an exemplary embodiment, referring to Figure 4 , the classifying and processing the N block images to obtain transparent block images and opaque block images includes:

[0064] Step S40: detecting the transparency values ​​of all pixels of each block image respectively.

[0065] Specifically, the values ​​in the alpha channel (α channel) of all pixels of each block image can be detected respectively, wherein the value in the α channel represents the transparency and translucency of an image. Generally speaking, when the value in the α channel is 0, it indicates that the pixel is a transparent pixel, and when the value in the α channel is non-zero, it indicates that the pixel is a non-transparent pixel.

[0066] It should be noted that if the image is composed entirely of transparent pixels, when such an image is displayed, the user will not be able to see the image composed of transparent pixels at all.

[0067] Step S41, if the transparency values ​​of all pixels of the currently detected block image are preset values, the currently detected block image is used as a transparent block image, otherwise, the currently detected block image is used as an opaque block image.

[0068] Specifically, the preset value is a value representing that the pixel is a transparent pixel, for example, the preset value is 0.

[0069] In one embodiment, when detecting the transparency of all pixels of the currently detected block image, a row scanning or column scanning method can be used to detect the pixels of the currently detected block image. If it is found during the detection process that the transparency value of the existing pixel is not a preset value, there is no need to scan other pixel points, and the current block image to be detected is used as an opaque block image; if during the detection process, no pixel point is found whose transparency value is not a preset value until all pixel points are scanned, that is, the transparency values ​​of all pixel points are the preset values, then the current block image to be detected is used as a transparent block image.

[0070] In this embodiment, after the detection of the current block picture is completed, other block pictures are continuously detected according to the detection method until the detection of all block pictures is completed.

[0071] In this embodiment, by detecting the transparency values ​​of all pixels of each block image, the classification of N block images can be accurately achieved.

[0072] In an exemplary embodiment, after obtaining the transparent block pictures and the opaque block pictures, in order to enable the computer device to accurately distinguish the classified transparent block pictures and the opaque block pictures, the classifying process of the N block pictures to obtain the transparent block pictures and the opaque block pictures further includes:

[0073] The opaque block picture is marked with the first identification information, and the transparent block picture is marked with the second identification information.

[0074] Specifically, the first identification information and the second identification information are preset, for example, the first preset identification information is "0" and the second identification information is "1".

[0075] Step S22, stitching all the opaque block images to obtain an atlas.

[0076] Specifically, after all the block images are classified, the transparent block images can be discarded, and the opaque block images are retained, and then the opaque block images are reassembled to form a new image, that is, to form the atlas.

[0077] In an exemplary embodiment, when stitching all the images, the opaque images can be spliced ​​randomly, or a splicing method can be pre-specified, and after all the opaque block images are obtained, the atlas is spliced ​​according to the specified splicing method. In this embodiment, the splicing method of the opaque images is not limited.

[0078] For example, Figure 3 Taking the picture shown in FIG. 1 as the picture to be processed as an example, after the picture to be processed is divided and classified, 28 block pictures can be obtained, and the 28 block pictures are re-joined in a 6-column 5-row joint mode, and the following can be obtained: Figure 5 The atlas shown.

[0079] In the embodiment of the present invention, opaque block images are spliced ​​to obtain an atlas, rather than a single opaque block image is saved separately, so that Draw Calls can be reduced when the images are subsequently submitted to the GPU for rendering. In Unity (a client engine for creating 3D games), each time the engine prepares data and notifies the GPU is called a Draw Call, and the fewer the number, the better.

[0080] Step S23, recording the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and saving the recorded data to a file in a preset format.

[0081] Specifically, the atlas is Figure 5 Taking the picture shown as an example, the size of the atlas can be recorded as (768*640), and the size of each opaque block picture can be recorded as (128,128).

[0082] In one embodiment, when recording the position of each opaque block image in the image to be processed, only the position of one of the four vertices (upper left vertex, lower left vertex, upper right vertex, and lower right vertex) of the opaque block image in the image to be processed may be recorded. For example, the position of the upper left vertex of the opaque block image in the image to be processed is recorded. For example, the opaque block image is marked as Figure 3 In another embodiment, when recording the position of each opaque block image in the image to be processed, only the positions of two or more of the four vertices of the opaque block image in the image to be processed may be recorded, for example, the positions of the upper left corner vertex and the upper right corner vertex of the opaque block image in the image to be processed may be recorded. For example, the opaque block image is marked as Figure 3 For the block image marked as 002, it can be recorded that the position of the upper left corner vertex of the block image in the to-be-processed image is (128, 0), and the position of the upper right corner vertex in the to-be-processed image is (256, 0).

[0083] In one embodiment, when recording the texture coordinates of each opaque block image in the atlas, only the texture coordinates of one of the four vertices (upper left vertex, lower left vertex, upper right vertex, lower right vertex) of the opaque block image in the atlas can be recorded, for example, the position of the upper left vertex of the opaque block image in the image to be processed is recorded. For example, the opaque block image is marked as Figure 3 For a block image marked as 002, the texture coordinates of the upper left corner vertex of the block image in the atlas can be recorded as (0, 1). In another embodiment, when recording the texture coordinates of each opaque block image in the atlas, only the texture coordinates of two or more of the four vertices of the opaque block image in the atlas can be recorded, for example, the texture coordinates of the upper left corner vertex and the upper right corner vertex of the opaque block image in the atlas are recorded.

[0084] In this embodiment, the preset format is preferably a json format.

[0085] This embodiment obtains a picture to be processed, and performs block processing on the picture to be processed to obtain N block pictures, wherein N is a natural number greater than 1; classifies the N block pictures to obtain transparent block pictures and opaque block pictures; splices all the opaque block pictures to obtain an atlas; records the size of the atlas, the size of each opaque block picture, the position of each opaque block picture in the picture to be processed, and the texture coordinates of each opaque block picture in the atlas, and saves the recorded data to a file in a preset format. This embodiment discards the transparent block picture when the picture to be processed contains a transparent block picture, and only retains the opaque block picture, thereby reducing the memory space occupied by the transparent part of the picture.

[0086] In an exemplary embodiment, referring to Figure 6 , the image processing method includes steps S60-S65.

[0087] Step S60, obtaining a to-be-processed picture, and performing block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1;

[0088] Step S61, classifying the N block images to obtain transparent block images and opaque block images;

[0089] Step S62, stitching all the opaque block images to obtain an atlas;

[0090] Step S63, recording the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and saving the recorded data to a file in a preset format.

[0091] Specifically, steps S60-S63 are the same as the above steps S20-S23 and are not described in detail in this embodiment.

[0092] Step S64, obtaining the file, and determining the vertex coordinates and texture coordinates of four vertices of each opaque block image according to the data recorded in the file.

[0093] Specifically, in order to save storage space, the file generally only stores the vertex coordinates and texture coordinates of one vertex or two of the four vertices of each opaque block image.

[0094] However, in order to render the opaque block image, the GPU (Graphics Processing Unit) needs to obtain the vertex coordinates and texture coordinates of the four vertices of the opaque block image. Therefore, in this embodiment, after obtaining the file, it is necessary to determine the vertex coordinates and texture coordinates of the four vertices of each opaque block image based on the information recorded in the file.

[0095] In an exemplary embodiment, referring to Figure 7 , when the position of each opaque block image in the image to be processed is the first vertex coordinate of the upper left corner vertex of the opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas are the first texture coordinates of the upper left corner vertex of the opaque block image in the atlas, the vertex coordinates and texture coordinates of the four vertices of each opaque block image are determined according to the data recorded in the file, including:

[0096] Step S70, obtaining the size of each opaque block image and the size of the atlas;

[0097] Step S71, calculating the vertex coordinates of four vertices of each opaque block image according to the coordinates of each opaque first vertex and the size of each opaque block image;

[0098] Step S72, calculating the texture coordinates of four vertices of each opaque block image according to each opaque first texture coordinate, the size of each opaque block image and the size of the atlas.

[0099] Specifically, the opaque block images are Figure 3 For example, the size of the 002 block image can be obtained as 128*128, and the coordinates of the upper left corner vertex of the 002 block image in the first vertex of the image to be processed are (128,0). According to mathematical rules, the coordinates of the four vertices of the 002 block image are: the vertex coordinates of the upper left vertex (128,0), the vertex coordinates of the upper right vertex (256,0), the vertex coordinates of the lower left vertex (128,128), and the vertex coordinates of the lower right vertex (256,128). In addition, for the 002 block image, the size of the 002 block image can be obtained as 128*128, and the size of the atlas is 768*640, so the texture coordinate (UV) span of the 002 block image can be calculated: U = (128 / 768) = 0.166667, V = (128 / 640) = 0.2. For the 002 block image, the texture coordinates of the upper left vertex can also be obtained as (0,1). According to mathematical rules, the texture coordinates of the four vertices of the 002 block image are: the texture coordinates of the upper left vertex are (0,1), the texture coordinates of the upper right vertex are (0.166667,1), the texture coordinates of the lower left vertex are (0,0.8), and the texture coordinates of the lower right vertex are (0.166667,0.8).

[0100] For other block images in the atlas, the vertex coordinates and texture coordinates of the four vertices of the other block images can be calculated in a similar manner as described above, which will not be repeated in this embodiment.

[0101] In this embodiment, the texture coordinates and vertex coordinates of each opaque image are restored by the data recorded in the file, so that the GPU can subsequently render and display it according to the texture coordinates and vertex coordinates of the opaque image without calculating the vertex coordinates and texture coordinates of the transparent image, thereby reducing the computational overhead of the texture at runtime without affecting the display result.

[0102] Step S65, passing the determined vertex coordinates and texture coordinates to a GPU, so that the GPU can render and restore the image to be processed according to the vertex coordinates, the texture coordinates and the atlas.

[0103] Specifically, after obtaining the texture coordinates and vertex coordinates of each opaque image, the GPU can render each opaque image in the correct position according to the atlas, thereby restoring the image to be processed. In an exemplary embodiment, the restored image to be processed is as follows: Figure 8 shown.

[0104] It should be noted that when the atlas is not a picture in a texture format, the atlas needs to be converted into an atlas in a texture format first.

[0105] The embodiment of the present invention only renders opaque block images, thereby reducing the memory size and computing overhead of the texture at runtime without affecting the display result.

[0106] Fig. 9 A block diagram of an image processing device according to an embodiment of the present application is schematically shown, and the image processing device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the video processing system in the storage medium than the program itself. The following description will specifically introduce the functions of each program module of this embodiment.

[0107] like Fig. 9 As shown, the image processing device 900 may include an acquisition module 901, a classification module 902, a splicing module 903 and a recording module 904, wherein:

[0108] The acquisition module 901 is used to acquire a to-be-processed picture, and perform block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1;

[0109] Specifically, when the image to be processed is processed in blocks, the number of blocks can be determined according to the size of the image to be processed and the size of the block images. For example, if the size of the image to be processed is a 1024*1024 pixel image and the size of the block image is a 128*128 pixel image, then when the image to be processed is processed in blocks, it can be divided into (1024*1024) / (128*128)=64 block images.

[0110] It should be noted that when the to-be-processed picture is processed in blocks, the sizes of different block pictures may be the same or different, and the shapes of the block pictures may be square or rectangular. In this embodiment, the obtained block pictures are preferably small block pictures of the same size and shape.

[0111] In a specific example, a picture to be processed with a size of 1024*1024 pixels can be divided into the following Figure 3 The 64 tile images shown.

[0112] In an exemplary embodiment, after obtaining the image to be processed, in order to avoid the image to be processed being processed in blocks when the image to be processed is not a transparent image, resulting in a waste of computing resources. In this embodiment, before the image to be processed is processed in blocks, it can be determined whether the image to be processed is a transparent image. The transparent image is an image in which the transparency values ​​of all pixels of the image are preset values. The preset value is a value representing that the pixel is a transparent pixel. For example, when the transparency value of the pixel is zero, it represents that the pixel is a transparent pixel. When the transparency value of the pixel is non-zero, it represents that the pixel is a non-transparent pixel. The preset value is zero. In other words, when it is determined that the transparency values ​​of all pixels of the image to be processed are zero, it can be determined that the image to be processed is a transparent image; when it is determined that the transparency values ​​of all pixels of the image to be processed are non-zero, it can be determined that the image to be processed is a non-transparent image. In this embodiment, when it is determined that the image to be processed is a non-transparent image, there is no need to perform subsequent operations of processing the image in blocks.

[0113] In an exemplary embodiment, after the image is processed into blocks, in order to facilitate the distinction between different block images, the image processing device 900 further includes: a marking module.

[0114] The marking module is used to mark the N block pictures according to a preset order to distinguish different block pictures.

[0115] Specifically, the preset order is pre-set, for example, the preset order is from left to right and from top to bottom, that is, when marking all the block pictures, they are first marked from left to right and then from top to bottom.

[0116] In this embodiment, when marking the block images, they can be marked in an auto-incremental manner according to the number of blocks. For example, Figure 3 The picture to be processed is divided into 64 small blocks as shown, and each block picture can be marked as 001, 002, 003..., 064 in order from left to right and from top to bottom.

[0117] The classification module 902 is used to classify the N block images to obtain transparent block images and opaque block images.

[0118] Specifically, a transparent block image refers to a block image in which the transparency values ​​of all pixels included in the block image are equal to a preset value, for example, the transparency values ​​are all 0. An opaque block image refers to a block image in which there are pixels whose transparency values ​​are not equal to the preset value, for example, there are pixels whose transparency values ​​are not 0.

[0119] In an exemplary implementation, the classification module 902 is further configured to detect transparency values ​​of all pixels of each block image.

[0120] Specifically, the values ​​in the alpha channel (α channel) of all pixels of each block image can be detected respectively, wherein the value in the α channel represents the transparency and translucency of an image. Generally speaking, when the value in the α channel is 0, it indicates that the pixel is a transparent pixel, and when the value in the α channel is non-zero, it indicates that the pixel is a non-transparent pixel.

[0121] It should be noted that if the image is composed entirely of transparent pixels, when such an image is displayed, the user will not be able to see the image composed of transparent pixels at all.

[0122] The classification module 902 is also used to treat the currently detected block image as a transparent block image if the transparency values ​​of all pixels of the currently detected block image are preset values, otherwise, treat the currently detected block image as an opaque block image.

[0123] Specifically, the preset value is a value representing that the pixel is a transparent pixel, for example, the preset value is 0.

[0124] In one embodiment, when detecting the transparency of all pixels of the currently detected block image, a row scanning or column scanning method can be used to detect the pixels of the currently detected block image. If it is found during the detection process that the transparency value of the existing pixel is not a preset value, there is no need to scan other pixel points, and the current block image to be detected is used as an opaque block image; if during the detection process, no pixel point is found whose transparency value is not a preset value until all pixel points are scanned, that is, the transparency values ​​of all pixel points are the preset values, then the current block image to be detected is used as a transparent block image.

[0125] In this embodiment, after the detection of the current block picture is completed, other block pictures are continuously detected according to the detection method until the detection of all block pictures is completed.

[0126] In this embodiment, by detecting the transparency values ​​of all pixels of each block image, the classification of N block images can be accurately achieved.

[0127] In an exemplary embodiment, after obtaining the transparent block pictures and the opaque block pictures, in order to enable the computer device to accurately distinguish the classified transparent block pictures and the opaque block pictures, the classifying process of the N block pictures to obtain the transparent block pictures and the opaque block pictures further includes:

[0128] The opaque block picture is marked with the first identification information, and the transparent block picture is marked with the second identification information.

[0129] Specifically, the first identification information and the second identification information are preset, for example, the first preset identification information is "0" and the second identification information is "1".

[0130] The stitching module 903 is used to stitch all the opaque block images to obtain an atlas.

[0131] Specifically, after all the block images are classified, the transparent block images can be discarded, and the opaque block images are retained, and then the opaque block images are reassembled to form a new image, that is, to form the atlas.

[0132] In an exemplary embodiment, when stitching all the images, the opaque images can be spliced ​​randomly, or a splicing method can be pre-specified, and after all the opaque block images are obtained, the atlas is spliced ​​according to the specified splicing method. In this embodiment, the splicing method of the opaque images is not limited.

[0133] For example, Figure 3 Taking the picture shown in FIG. 1 as the picture to be processed as an example, after the picture to be processed is divided and classified, 28 block pictures can be obtained, and the 28 block pictures are re-joined in a 6-column 5-row joint mode, and the following can be obtained: Figure 5 The atlas shown.

[0134] In the embodiment of the present invention, opaque block images are spliced ​​to obtain an atlas, rather than a single opaque block image is saved separately, so that Draw Calls can be reduced when the images are subsequently submitted to the GPU for rendering. In Unity (a client engine for creating 3D games), each time the engine prepares data and notifies the GPU is called a Draw Call, and the fewer the number, the better.

[0135] A recording module is used to record the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and save the recorded data to a file in a preset format.

[0136] Specifically, the atlas is Figure 5 Taking the picture shown as an example, the size of the atlas can be recorded as (768*640), and the size of each opaque block picture can be recorded as (128,128).

[0137] In one embodiment, when recording the position of each opaque block image in the image to be processed, only the position of one of the four vertices (upper left vertex, lower left vertex, upper right vertex, and lower right vertex) of the opaque block image in the image to be processed may be recorded. For example, the position of the upper left vertex of the opaque block image in the image to be processed is recorded. For example, the opaque block image is marked as Figure 3 In another embodiment, when recording the position of each opaque block image in the image to be processed, only the positions of two or more of the four vertices of the opaque block image in the image to be processed may be recorded, for example, the positions of the upper left corner vertex and the upper right corner vertex of the opaque block image in the image to be processed may be recorded. For example, the opaque block image is marked as Figure 3 For the block image marked as 002, it can be recorded that the position of the upper left corner vertex of the block image in the to-be-processed image is (128, 0), and the position of the upper right corner vertex in the to-be-processed image is (256, 0).

[0138] In one embodiment, when recording the texture coordinates of each opaque block image in the atlas, only the texture coordinates of one of the four vertices (upper left vertex, lower left vertex, upper right vertex, lower right vertex) of the opaque block image in the atlas can be recorded, for example, the position of the upper left vertex of the opaque block image in the image to be processed is recorded. For example, the opaque block image is marked as Figure 3For a block image marked as 002, the texture coordinates of the upper left corner vertex of the block image in the atlas can be recorded as (0, 1). In another embodiment, when recording the texture coordinates of each opaque block image in the atlas, only the texture coordinates of two or more of the four vertices of the opaque block image in the atlas can be recorded, for example, the texture coordinates of the upper left corner vertex and the upper right corner vertex of the opaque block image in the atlas are recorded.

[0139] In this embodiment, the preset format is preferably a json format.

[0140] This embodiment obtains a picture to be processed, and performs block processing on the picture to be processed to obtain N block pictures, wherein N is a natural number greater than 1; classifies the N block pictures to obtain transparent block pictures and opaque block pictures; splices all the opaque block pictures to obtain an atlas; records the size of the atlas, the size of each opaque block picture, the position of each opaque block picture in the picture to be processed, and the texture coordinates of each opaque block picture in the atlas, and saves the recorded data to a file in a preset format. This embodiment discards the transparent block picture when the picture to be processed contains a transparent block picture, and only retains the opaque block picture, thereby reducing the memory space occupied by the transparent part of the picture.

[0141] In an exemplary implementation, the image processing device 900 further includes: a file acquisition module and a determination module.

[0142] The file acquisition module is used to acquire the file and determine the vertex coordinates and texture coordinates of the four vertices of each opaque block image according to the data recorded in the file.

[0143] Specifically, in order to save storage space, the file generally only stores the vertex coordinates and texture coordinates of one vertex or two of the four vertices of each opaque block image.

[0144] However, in order to render the opaque block image, the GPU (Graphics Processing Unit) needs to obtain the vertex coordinates and texture coordinates of the four vertices of the opaque block image. Therefore, in this embodiment, after obtaining the file, it is necessary to determine the vertex coordinates and texture coordinates of the four vertices of each opaque block image based on the information recorded in the file.

[0145] In an exemplary embodiment, when the position of each opaque block image in the image to be processed is the first vertex coordinate of the upper left corner vertex of the opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas are the first texture coordinates of the upper left corner vertex of the opaque block image in the atlas, the file acquisition module is also used to obtain the size of each opaque block image and the size of the atlas; calculate the vertex coordinates of the four vertices of each opaque block image according to each opaque first vertex coordinate and the size of each opaque block image; calculate the texture coordinates of the four vertices of each opaque block image according to each opaque first texture coordinate, the size of each opaque block image and the size of the atlas.

[0146] Specifically, the opaque block images are Figure 3 For example, the size of the 002 block image can be obtained as 128*128, and the coordinates of the upper left corner vertex of the 002 block image in the first vertex of the image to be processed are (128,0). According to mathematical rules, the coordinates of the four vertices of the 002 block image are: the vertex coordinates of the upper left vertex (128,0), the vertex coordinates of the upper right vertex (256,0), the vertex coordinates of the lower left vertex (128,128), and the vertex coordinates of the lower right vertex (256,128). In addition, for the 002 block image, the size of the 002 block image can be obtained as 128*128, and the size of the atlas is 768*640, so the texture coordinate (UV) span of the 002 block image can be calculated: U = (128 / 768) = 0.166667, V = (128 / 640) = 0.2. For the 002 block image, the texture coordinates of the upper left vertex can also be obtained as (0,1). According to mathematical rules, the texture coordinates of the four vertices of the 002 block image are: the texture coordinates of the upper left vertex are (0,1), the texture coordinates of the upper right vertex are (0.166667,1), the texture coordinates of the lower left vertex are (0,0.8), and the texture coordinates of the lower right vertex are (0.166667,0.8).

[0147] For other block images in the atlas, the vertex coordinates and texture coordinates of the four vertices of the other block images can be calculated in a similar manner as described above, which will not be repeated in this embodiment.

[0148] In this embodiment, the texture coordinates and vertex coordinates of each opaque image are restored by the data recorded in the file, so that the GPU can subsequently render and display it according to the texture coordinates and vertex coordinates of the opaque image without calculating the vertex coordinates and texture coordinates of the transparent image, thereby reducing the computational overhead of the texture at runtime without affecting the display result.

[0149] The determination module is used to transfer the determined vertex coordinates and texture coordinates to the GPU, so that the GPU can render and restore the image to be processed according to the vertex coordinates, the texture coordinates and the atlas.

[0150] The determined vertex coordinates and texture coordinates are passed to a GPU, so that the GPU can render and restore the image to be processed according to the vertex coordinates, the texture coordinates and the atlas.

[0151] Specifically, after obtaining the texture coordinates and vertex coordinates of each opaque image, the GPU can render each opaque image in the correct position according to the atlas, thereby restoring the image to be processed. In an exemplary embodiment, the restored image to be processed is as follows: Figure 8 shown.

[0152] It should be noted that when the atlas is not a picture in a texture format, the atlas needs to be converted into an atlas in a texture format first.

[0153] The embodiment of the present invention only renders opaque block images, thereby reducing the memory size and computing overhead of the texture at runtime without affecting the display result.

[0154] Fig.10 The schematic diagram of the hardware architecture of a computer device suitable for implementing the image processing method according to the fourth embodiment of the present application is shown schematically. In this embodiment, the computer device 10 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. For example, it can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a rack server, a blade server, a tower server or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Fig.10 As shown, the computer device 10 includes at least but is not limited to: a memory 910, a processor 920, and a network interface 930 which can communicate with each other through a system bus. Among them:

[0155] The memory 910 includes at least one type of computer-readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 910 can be an internal storage module of the computer device 10, such as a hard disk or memory of the computer device 10. In other embodiments, the memory 910 can also be an external storage device of the computer device 10, such as a plug-in hard disk equipped on the computer device 10, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card (FlashCard), etc. Of course, the memory 910 can also include both the internal storage module of the computer device 10 and its external storage device. In this embodiment, the memory 910 is generally used to store the operating system and various application software installed on the computer device 10, such as the program code of the image processing method, etc. In addition, the memory 910 can also be used to temporarily store various types of data that have been output or are to be output.

[0156] In some embodiments, the processor 920 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 920 is generally used to control the overall operation of the computer device 10, such as performing control and processing related to data interaction or communication with the computer device 10. In this embodiment, the processor 920 is used to run the program code stored in the memory 910 or process data.

[0157] The network interface 930 may include a wireless network interface or a wired network interface, and the network interface 930 is generally used to establish a communication link between the computer device 10 and other computer devices. For example, the network interface 930 is used to connect the computer device 10 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10 and the external terminal. The network can be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.

[0158] It should be pointed out that Fig.10 Only a computer device having components 910 to 930 is shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0159] In this embodiment, the image processing method stored in the memory 910 can also be divided into one or more program modules and executed by one or more processors (processor 920 in this embodiment) to complete the present application.

[0160] This embodiment further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the image processing method in the embodiment are implemented.

[0161] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, referred to as SMC), a secure digital (Secure Digital, referred to as SD) card, a flash card, etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store an operating system and various application software installed on the computer device, such as the program code of the image processing method in the embodiment, etc. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.

[0162] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, and optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.

[0163] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for processing an image, characterized in that: include: Obtain a to-be-processed picture, and perform block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1; Classify the N block images to obtain transparent block images and opaque block images; All the opaque block images are stitched together to obtain an atlas; Record the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and save the recorded data to a file in a preset format, wherein: The position of each opaque block image in the image to be processed is the first vertex coordinate of the upper left corner vertex of the opaque block image in the image to be processed, and the texture coordinate of each opaque block image in the atlas is the first texture coordinate of the upper left corner vertex of the opaque block image in the atlas; The method further comprises: The file is obtained, and vertex coordinates and texture coordinates of four vertices of each opaque block image are determined according to the data recorded in the file.

2. The image processing method according to claim 1, characterized in that: The image processing method further includes: The determined vertex coordinates and texture coordinates are passed to a GPU, so that the GPU can render and restore the image to be processed according to the vertex coordinates, the texture coordinates and the atlas.

3. The image processing method according to claim 1, characterized in that: Determining the vertex coordinates and texture coordinates of four vertices of each opaque block image according to the data recorded in the file includes: Get the size of each opaque tile image and the size of the atlas; Calculate the vertex coordinates of four vertices of each opaque block image according to the coordinates of each opaque first vertex and the size of each opaque block image; The texture coordinates of four vertices of each opaque tile image are calculated according to each opaque first texture coordinate, the size of each opaque tile image, and the size of the atlas.

4. The image processing method according to claim 1, characterized in that: After the step of obtaining the image to be processed and performing block processing on the image to be processed to obtain N block images, the method further includes: The N block pictures are marked in a preset order to distinguish different block pictures.

5. The image processing method according to claim 1, characterized in that: The classifying and processing the N block images to obtain transparent block images and opaque block images includes: Detect the transparency values ​​of all pixels of each block image respectively; If the transparency values ​​of all pixels of the currently detected block image are preset values, the currently detected block image is used as a transparent block image, otherwise, the currently detected block image is used as an opaque block image.

6. The image processing method according to claim 4, characterized in that: After the step of classifying the N block images to obtain transparent block images and opaque block images, the method further includes: The opaque block picture is marked with the first identification information, and the transparent block picture is marked with the second identification information.

7. The image processing method according to any one of claims 1 to 6, characterized in that: Before the step of dividing the image to be processed into blocks, the method further includes: Determine whether the image to be processed is a transparent image.

8. A picture processing device, characterized in that: include: An acquisition module is used to acquire a to-be-processed picture, and perform block processing on the to-be-processed picture to obtain N block pictures, where N is a natural number greater than 1; A classification module, used for classifying the N block images to obtain transparent block images and opaque block images; The stitching module is used to stitch all the opaque block images to obtain an atlas; A recording module is used to record the size of the atlas, the size of each opaque block image, the position of each opaque block image in the image to be processed, and the texture coordinates of each opaque block image in the atlas, and save the recorded data to a file in a preset format, wherein: The position of each opaque block image in the image to be processed is the first vertex coordinate of the upper left corner vertex of the opaque block image in the image to be processed, and the texture coordinate of each opaque block image in the atlas is the first texture coordinate of the upper left corner vertex of the opaque block image in the atlas; The device also includes: The file acquisition module is used to acquire the file and determine the vertex coordinates and texture coordinates of the four vertices of each opaque block image according to the data recorded in the file.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the image processing method according to any one of claims 1 to 7 when executing the computer program.

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

11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the image processing method according to any one of claims 1 to 7 are implemented.