Method, device, storage medium and electronic device for compressing image
By performing feature analysis and adaptive compression processing on the maps in the three-dimensional mobile game industry, the problem of poor image compression quality in traditional technology is solved, and efficient and lossless image compression effect is achieved, reducing production costs and the risk of output errors.
Patent Information
- Application Number
- CN202110897433.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-05
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-08-05
AI Technical Summary
When the existing technology compresses the maps in the three-dimensional mobile game industry, there is a problem of poor image compression quality. The errors generated by traditional algorithms will lead to visual differences, and the compression process is cumbersome and prone to errors, which increases the risk of production costs and output errors.
By analyzing the image features of the to-compressed image, a compression method corresponding to the to-compressed image is determined, and the compression method is used to compress the compressed image to obtain a target image. This method includes steps such as image sampling, feature extraction, scaling processing, channel splitting and merging, and format conversion to ensure that the compression method is adapted to image features and improve compression quality.
The technical effect of improving the image compression quality is achieved, the problem of poor image compression quality in the prior art is solved, the cost of image compression is saved, and the efficiency of image compression is improved.
Smart Images

Figure CN113706640B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a method, device, storage medium and electronic equipment for compressing an image. Background Art
[0002] In the production of video games, the material representation of 3D models often relies on a large number of texture images containing different information. During the production of art assets, due to varying requirements for texture accuracy, the output and processing procedures for different types of textures often differ. For example, traditional compression and sampling algorithms for intrinsic color maps produce hue deviations that are imperceptible to the human eye. However, for normal maps used to calculate lighting angles, the errors produced by traditional algorithms can produce noticeable visual differences after data parsing and lighting calculations. Therefore, to ensure the quality of normal map compression results, modifying the normal map size often requires a high-poly model baking low-poly model output process. For large-scale games, these tedious and single-step texturing operations not only incur significant production costs, but also increase the risk of output errors due to the instability of manual operations.
[0003] With the development of the industry and the advancement of hardware equipment, people's demand for 3D rendering quality is getting higher and higher. High-precision texture, efficient and lossless compression solutions have become a technical problem that needs to be solved urgently in the 3D mobile game industry.
[0004] Currently, the following two methods are commonly used in related technologies to compress textures:
[0005] Method 1: Use a lossless format (such as TGA, TIFF, etc.) to store texture images, and use Photoshop to modify the size of a large number of textures.
[0006] Method 2: Follow the traditional normal baking process and use sculpting software such as Zbrush to bake the high-poly normal information into the low-poly map. Then use other software to convert the output normal map into a different format.
[0007] Although both of the above methods can achieve texture compression processing, in method one, images in lossless formats such as TGA are larger in size, which increases the size of the game package. Moreover, compared with the DDS format, lossless formats such as TGA are less efficient in loading, parsing, and reading. Therefore, method one also has problems such as slow image loading. In addition, there is no unified design and maintenance standard for image processing based on PS actions. Compression requirements are usually obtained temporarily, and related logic is temporarily written, which not only leads to additional labor costs, but also makes it difficult to guarantee the efficiency and quality of the output.
[0008] In the second method, the process of compressing images is cumbersome. If the number of maps to be processed is huge, relying solely on manual operation by art production personnel to complete the output is prone to errors in the complex mechanized operation. Such errors are random and irregular, and therefore difficult to detect. Therefore, the use of the second method for image compression has the problem of low output efficiency and the inability to guarantee the quality of image compression.
[0009] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0010] Embodiments of the present invention provide a method, apparatus, storage medium, and electronic device for compressing an image, so as to at least solve the technical problem of poor image compression quality in the prior art when compressing an image.
[0011] According to one aspect of an embodiment of the present invention, a method for compressing an image is provided, comprising: acquiring an image to be compressed; analyzing image features of the image to be compressed and determining a compression method corresponding to the image to be compressed; and compressing the image to be compressed using the compression method to obtain a target image.
[0012] Furthermore, the method for compressing an image also includes: performing image sampling on the image to be compressed to obtain a first image; performing feature extraction on the first image to obtain image features corresponding to the image to be compressed, wherein the image features include at least: the file name corresponding to the image to be compressed, the pixel format corresponding to the image to be compressed, and the image mode corresponding to the image to be compressed; and determining the compression method corresponding to the image to be compressed based on the image features.
[0013] Furthermore, the method for compressing an image also includes: after extracting features of the first image to obtain image features corresponding to the image to be compressed, detecting whether the first image contains a transparent channel according to the pixel format to obtain a first detection result, wherein the transparent channel is used to store at least transparency information and grayscale information in the first image; and scaling the first image according to the first detection result to obtain a second image.
[0014] Furthermore, the method for compressing an image also includes: when it is detected that the first image contains a transparent channel, performing channel splitting processing on the first image to obtain a third image and a fourth image, wherein the third image is an image containing a transparent channel and the fourth image is an image containing color information; scaling the third image and the fourth image respectively to obtain a scaled third image and a scaled fourth image; and merging the scaled third image and the scaled fourth image to obtain a second image.
[0015] Furthermore, the image compression method further includes: when it is detected that the first image does not contain a transparent channel, scaling the first image to obtain a second image.
[0016] Furthermore, the method for compressing an image also includes: before scaling the first image according to the first detection result to obtain the second image, comparing the image size corresponding to the first image with the preset size to obtain a comparison result; receiving a control instruction fed back by the target object based on the comparison result; and adjusting the size of the first image according to the control instruction.
[0017] Furthermore, the image compressing method further includes: performing format conversion on the image to be compressed to obtain a sixth image, wherein the sixth image includes image information contained in the image to be compressed; and compressing the sixth image using a compression method to obtain a target image.
[0018] Furthermore, the method for compressing an image also includes: before compressing the sixth image using a compression method to obtain a target image, detecting whether the image information corresponding to the image to be compressed includes preset data and / or a transparent channel to obtain a second detection result, wherein the preset data is the image data after compression processing; and determining whether to compress the sixth image using a compression method based on the second detection result.
[0019] Furthermore, the method for compressing an image also includes: when the compression method is the first compression method, if the image information contains preset data but does not include a transparent channel and a compression identifier prohibiting compression of the sixth image, the first compression method is used to compress the sixth image; if the image information does not contain the preset data but includes a transparent channel or a compression identifier, a warning message is generated.
[0020] Furthermore, the method for compressing an image also includes: when the compression method is the second compression method, if the image information contains preset data and a transparent channel, but does not include a compression identifier prohibiting compression of the sixth image, the second compression method is used to compress the sixth image; if the image information does not contain the preset data and the transparent channel, but includes a compression identifier, a warning message is generated.
[0021] Furthermore, the method for compressing an image further includes: when the compression method is the third compression method, compressing the sixth image using the third compression method.
[0022] Furthermore, the method for compressing an image also includes: controlling the main thread to distribute tasks to multiple sub-threads, wherein the multiple sub-threads include at least a first sub-thread, and the first sub-thread is used to analyze, convert the format of, and compress the image to be compressed; controlling the listening thread to listen to the first sub-thread, obtain an abnormal result, and feed back the abnormal result to the interface control thread of the graphical user interface, so that the graphical user interface displays the abnormal result.
[0023] Furthermore, the method for compressing an image further includes: obtaining parameters to be adjusted corresponding to the image to be compressed; adjusting the parameters to be adjusted to obtain adjusted parameters; and compressing the image to be compressed based on the adjusted parameters to obtain a target image.
[0024] Furthermore, the method for compressing an image further includes: obtaining an operation record of the target object on a preset system, wherein the preset system is used to perform compression processing on the image to be compressed; and storing the operation record.
[0025] According to another aspect of an embodiment of the present invention, a method for compressing an image is also provided, including: selecting an image to be compressed on an interactive interface, and selecting at least one adjustment parameter; calling a sampling function to perform sampling processing on the image to be compressed to obtain a sampling result; based on the sampling result and at least one adjustment parameter, determining a compression method corresponding to the image to be compressed; and using the compression method to compress the image to be compressed to obtain a target image.
[0026] According to another aspect of an embodiment of the present invention, a device for compressing an image is also provided, including: an acquisition module for acquiring an image to be compressed; an analysis module for analyzing image features of the image to be compressed and determining a compression method corresponding to the image to be compressed; and a compression module for compressing the image to be compressed using the compression method to obtain a target image.
[0027] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned method for compressing an image when running.
[0028] According to another aspect of an embodiment of the present invention, an electronic device is also provided, which includes one or more processors; a storage device for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the above-mentioned method of compressing images when running.
[0029] In an embodiment of the present invention, an image is compressed using a compression method corresponding to the image to be compressed. After obtaining the image to be compressed, the image features of the image to be compressed are analyzed to determine the compression method corresponding to the image to be compressed, and the image to be compressed is compressed using the compression method to obtain a target image.
[0030] In the above process, the compression method is determined by the image features of the image to be compressed. Therefore, this compression method is the optimal compression strategy for the image to be compressed. Using this compression method for compressing the image to be compressed can ensure image compression quality. Furthermore, in the above process, the compression method can be determined by simply analyzing the features of the image to be compressed. This compression method can then be directly used to compress the image to be compressed, eliminating the need for complex process modifications. This not only reduces image compression costs but also improves image compression efficiency.
[0031] It can be seen that the solution provided by this application achieves the purpose of image compression processing, thereby realizing the technical effect of improving the image compression quality, and further solving the technical problem of poor image compression quality when compressing images in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0033] Figure 1 is a flow chart of a method for compressing an image according to an embodiment of the present invention;
[0034] Figure 2 is a schematic diagram of an optional image to be compressed according to an embodiment of the present invention;
[0035] Figure 3 is a schematic diagram of an optional target image according to an embodiment of the present invention;
[0036] Figure 4 is a schematic diagram of an optional target image according to an embodiment of the present invention;
[0037] Figure 5 is a flow chart of an optional method for compressing an image according to an embodiment of the present invention;
[0038] Figure 6 is a schematic diagram of an optional graphical interface according to an embodiment of the present invention;
[0039] Figure 7 is a schematic structural diagram of an optional preset system according to an embodiment of the present invention;
[0040] Figure 8 is a flow chart of a method for compressing an image according to an embodiment of the present invention;
[0041] Figure 9 FIG. 4 is a schematic diagram of a device for compressing an image according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0043] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0044] According to an embodiment of the present invention, an embodiment of a method for compressing an image is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0045] In addition, it should be noted that in this embodiment, the electronic device is used to compress the image to be compressed, that is, the electronic device is the executor of the method provided in this embodiment, wherein the electronic device can be but is not limited to a desktop computer, a laptop computer, a smart tablet, a smart phone, etc.
[0046] Figure 1 FIG. 1 is a flow chart of a method for compressing an image according to an embodiment of the present invention. Figure 1 As shown, the method includes the following steps:
[0047] Step S102: Obtain the image to be compressed.
[0048] In step S102, the image to be compressed may be, but is not limited to, a texture image in a game scene, which may be used to create materials for a virtual three-dimensional model in the game scene. The texture image may be, but is not limited to, a DDS (DirectDraw Surface) texture. Optionally, the DDS texture may be a mixed texture, a normal map, or an intrinsic color map.
[0049] In an optional embodiment, the user may input the image to be compressed into the electronic device through an input unit (eg, a scanner) of the electronic device, so that the electronic device performs compression processing on the image to be compressed.
[0050] In another optional embodiment, the electronic device receives a control instruction input by the user and obtains the image to be compressed from a preset storage area according to the control instruction. For example, the user inputs a storage address where the image to be compressed is stored into the electronic device, and the electronic device obtains the image to be compressed from the storage address.
[0051] Step S104 : analyzing the image features of the image to be compressed and determining a compression method corresponding to the image to be compressed.
[0052] In step S104, the image features of the image to be compressed include at least: the file name corresponding to the image to be compressed, the pixel format corresponding to the image to be compressed, and the image mode corresponding to the image to be compressed, wherein the type of map corresponding to the image to be compressed is determined based on the uniquely identifiable keyword contained in the file name corresponding to the image to be compressed. For example, if it is detected that the file name of the image to be compressed contains "_m", it can be determined that the image to be compressed is a mixed map; for another example, if it is detected that the file name of the image to be compressed contains "_n", it can be determined that the image to be compressed is a normal map; for another example, if it is detected that the file name of the image to be compressed contains "_d", it can be determined that the image to be compressed is an intrinsic color map. In addition, the pixel format corresponding to the above-mentioned image to be compressed represents the compression format corresponding to the original image, including but not limited to DXT1 format, DXT5 format, and R8G8B8A8 format; the above-mentioned image mode represents the channel information corresponding to the image to be compressed, for example, the original image includes color channels (for example, RGB channels) and transparency channels (for example, Alpha channels).
[0053] As can be seen from the above, by analyzing the image to be compressed, the electronic device can determine the corresponding texture type of the image to be compressed, the compression format of the original image, and the channel information. By analyzing the above image features, the electronic device can compress the image to be compressed in a certain manner.
[0054] It should be noted that different images to be compressed correspond to different image features. Determining the compression method of the image to be compressed based on the analysis of the image features can make the compression method more suitable for the image to be compressed, so that using this compression method to compress the image to be compressed can improve the image compression quality.
[0055] Step S106: compress the image to be compressed using a compression method to obtain a target image.
[0056] Optional, Figure 2 is the image to be compressed, Figure 3 and Figure 4 Both are target images obtained after compressing the image to be compressed. The size of the image to be compressed is 2048*2048. The image to be compressed contains 7 character textures and 212 engineering textures. The character textures are 60.0MB in total, and the engineering textures are 1.18GB in total. Figure 3 It is the result of adjusting the size of the image to be compressed to 1024*1024 and then compressing the resized image to be compressed. Figure 3 The 7 character textures total 14.4MB, the 212 engineering textures total 0.44GB, the compression rate is 37.3%, and the processing efficiency is 17 seconds. Figure 4 The result of resizing the image to be compressed to 512*512 and then compressing the resized image is obtained. Figure 4 In the file, 7 character textures total 3.54MB, 212 engineering textures total 0.12GB, the compression rate is 10.1%, and the processing efficiency is 16 seconds.
[0057] Depend on Figure 2-Figure 4 It can be seen that for images of different sizes to be compressed, using the same compression method, the file size of the target image obtained is different, and the compression rate is also different, but the fidelity of the target image is not reduced, that is, the solution provided by this application can ensure the image compression quality.
[0058] Based on the scheme defined in the above steps S102 to S106, it can be known that in an embodiment of the present invention, a method of performing image compression using a compression method corresponding to the image to be compressed is adopted. After obtaining the image to be compressed, the image features of the image to be compressed are analyzed to determine the compression method corresponding to the image to be compressed, and the compression method is used to compress the image to be compressed to obtain the target image.
[0059] It's easy to note that in the above process, the compression method is determined by the image features of the image to be compressed. Therefore, this compression method is the optimal compression strategy for the image to be compressed, and using this compression method to compress the image can ensure image compression quality. Furthermore, in the above process, the compression method can be determined by simply analyzing the features of the image to be compressed, and then the image can be compressed directly using this compression method, eliminating the need to modify cumbersome process steps. This not only saves image compression costs but also improves image compression efficiency.
[0060] It can be seen that the solution provided by this application achieves the purpose of image compression processing, thereby realizing the technical effect of improving the image compression quality, and further solving the technical problem of poor image compression quality when compressing images in the prior art.
[0061] In an optional embodiment, after acquiring the image to be compressed, the electronic device analyzes image features of the image to be compressed to determine a compression method corresponding to the image to be compressed. Specifically, the electronic device samples the image to be compressed to obtain a first image, extracts features of the first image to obtain image features corresponding to the image to be compressed, and then determines a compression method corresponding to the image to be compressed based on the image features.
[0062] Optional, Figure 5 A flow chart of an optional method for compressing an image is shown. Figure 5 As can be seen, the electronic device first samples the image to be compressed. The electronic device can use PIL (Python Image Library) to sample the image to be compressed. PIL can implement image processing functions for the compressed image, such as resizing and rotating the image to be compressed, converting the format of the compressed image, and performing color field space conversion, interpolation, and filtering on the compressed image.
[0063] Furthermore, after extracting features from the first image to obtain image features corresponding to the image to be compressed, the electronic device detects whether the first image includes a transparent channel based on the pixel format, obtains a first detection result, and scales the first image based on the first detection result to obtain a second image. The transparent channel is used to store at least transparency information and grayscale information in the first image, and the grayscale information may include, but is not limited to, self-luminous intensity information, roughness information, and metallicity information.
[0064] Optionally, when it is detected that the first image contains a transparent channel, the first image is subjected to channel splitting processing to obtain a third image and a fourth image, and the third image and the fourth image are respectively scaled to obtain a scaled third image and a scaled fourth image, and then the scaled third image and the scaled fourth image are merged to obtain a second image. The third image is an image containing a transparent channel, and the fourth image is an image containing color information.
[0065] When it is detected that the first image does not include a transparent channel, scaling processing is performed on the first image to obtain a second image.
[0066] Optional, in Figure 5 In the process, after sampling the image to be compressed and obtaining the first image, the electronic device scales the size of the first image. Since the traditional scaling algorithm will crop the pixel values of the color channels (e.g., RGB channels) in the first image according to the transparent channel (e.g., Alpha channel), and use the transparent channel as a mask, that is, multiplying the data corresponding to the color channel with the data corresponding to the transparent channel, the values corresponding to the color channels of the final output image are inconsistent with the values corresponding to the color channels of the original image (i.e., the image to be compressed), which leads to the problem of distortion of the compressed image compared with the original image. Therefore, before scaling the first image, it is necessary to determine whether the first image contains a transparent channel (i.e., Figure 5 If the first image contains a transparent channel, the first image is split into an RGB object (i.e., the fourth image) and an A object (i.e., the third image). The two images are then scaled to obtain a scaled fourth image and a scaled third image. Humming filtering can be used in this process to reduce noise. The two scaled images are then merged.
[0067] In addition, when it is detected that the first image does not contain a transparent channel, the first image is directly scaled without making any judgment.
[0068] In an optional embodiment, before scaling the first image based on the first detection result to obtain the second image, the electronic device compares the image size corresponding to the first image with a preset size to obtain a comparison result, receives a control instruction fed back by the target object based on the comparison result, and then adjusts the size of the first image based on the control instruction. The target object is the user operating the electronic device, that is, in this application, the user can choose to enlarge or reduce the first image, or prohibit the user from adjusting the size of the first image based on the comparison result displayed by the electronic device.
[0069] It should be noted that in actual applications, the user can determine the target size to which the first image should be adjusted based on experience. In addition, in order to prevent the user from operating the electronic device incorrectly, before scaling the first image, the electronic device needs to compare the image size of the first image with the target size, so that when the first image is scaled from a small size to a large size, a warning message can be recorded and the processing flow of the image can be skipped, thereby avoiding the generation of redundant and meaningless large-sized images, such as Figure 5 As shown, the size of the original map is compared with the target size.
[0070] For example, a preset texture directory stores multiple images of different sizes to be compressed. The user needs to compress a 2k image to a size of 1024*1024, while the texture directory contains a 512*512 image. If PIL is called directly to scale the image, the 512*512 image will be incorrectly enlarged to 1024*1024. Therefore, before scaling the image, a size comparison is required to prevent user errors.
[0071] In addition, it should be noted that in the process of scaling the first image, the first image can be scaled into an equilateral rectangle, that is, the second image obtained after scaling the first image is a square, thereby avoiding display problems such as sampling deviation or uneven blur.
[0072] In an optional embodiment, after scaling the first image to obtain the second image, feature extraction is performed on the second image to obtain image features of the image to be compressed. A compression method corresponding to the image to be compressed is determined based on the image features. The electronic device then compresses the image to be compressed using the compression method to obtain a target image. Specifically, the electronic device converts the format of the image to be compressed to obtain a sixth image, and compresses the sixth image using the compression method to obtain the target image. The sixth image includes image information contained in the image to be compressed.
[0073] It should be noted that the image format of the sixth image is an undistorted texture format, such as Figure 5 As shown, the electronic device converts the image to be compressed into a lossless format image and temporarily stores the image converted into the lossless format. For example, the image format of the sixth image can be, but is not limited to, TGA format, TIFF format, etc. After obtaining the sixth image, the electronic device temporarily stores the sixth image.
[0074] In addition, it should be noted that storing the image to be compressed as an image in a lossless format and then compressing the image in the lossless format can avoid the problem of reducing the image compression quality caused by compressing the image in a lossy format.
[0075] In an optional embodiment, before compressing the sixth image to obtain the target image, the electronic device detects whether the image information corresponding to the image to be compressed includes preset data and / or a transparent channel, obtains a second detection result, and determines whether to compress the sixth image based on the second detection result. The preset data is the compressed image data.
[0076] Optionally, after storing the image to be compressed as a lossless format image, the electronic device uses the Python operating system interface to call the TexConv function, uses the compression strategy to convert the scaled image temporarily stored in the lossless format into the corresponding DDS texture file, and releases (or deletes) the temporary file.
[0077] Optionally, when the compression method is the first compression method, if the image information contains preset data but does not include a transparent channel and a compression identifier prohibiting compression of the sixth image, the first compression method is used to compress the sixth image; if the image information does not contain preset data but includes a transparent channel or a compression identifier, a warning message is generated.
[0078] It should be noted that the first compression method mentioned above can be DXT1. The image to be compressed in this format usually stores texture maps that have compressed data and do not contain transparent channels. Therefore, in practical applications, Figure 5 As shown, the electronic device needs to make the following judgments:
[0079] The electronic device detects whether there is a transparent channel in the image to be compressed. If so, the problem is recorded and a warning message is generated. If not, the electronic device detects whether there is an identification mark (i.e., the above-mentioned compression mark) in the image to be compressed that is not desired to be compressed. If so, the electronic device records the problem and issues a warning message to the user to remind the user that the format may cause the quality of the image to be compressed to be damaged. If the image to be compressed does not have the above-mentioned problem, the format of the temporarily stored lossless image file is converted according to the DXT1 format to obtain the target image (i.e., the DDS image).
[0080] Optionally, when the compression method is the second compression method, if the image information contains preset data and a transparent channel, but does not include a compression identifier prohibiting compression of the sixth image, the second compression method is used to compress the sixth image; if the image information does not contain preset data and a transparent channel, but includes a compression identifier, a warning message is generated.
[0081] It should be noted that the second compression method can be DXT5. The image to be compressed in this format usually stores compressed data and a texture map containing a transparent channel. Therefore, in practical applications, Figure 5As shown, the electronic device needs to make the following judgments:
[0082] The electronic device detects whether there are identification marks (i.e., the compression marks) in the image to be compressed that are not desired to be compressed. If so, the electronic device records the problem and issues a warning message to the user to remind the user that the format may cause the quality of the compressed image to be damaged. If the image to be compressed does not have the above-mentioned problem, the electronic device converts the format of the temporarily stored lossless image file according to the DXT5 format to obtain the target image (i.e., the DDS image).
[0083] Optionally, when the compression method is the third compression method, the third compression method is used to compress the sixth image.
[0084] It should be noted that the third compression method can be R8G8B8A8. The image to be compressed in this format usually stores lossless texture maps. Therefore, in practical applications, Figure 5 As shown, the electronic device does not need to perform the logical judgment of the above problem, and directly performs format conversion to obtain the target image (ie, DDS image).
[0085] In an optional embodiment, in order to improve the processing efficiency of compressed images, in this embodiment, the electronic device uses a multi-threaded approach to execute the image compression process. Optionally, in this application, the electronic device can use a combination of graphical interactive design and multi-threaded functions to implement a graphical multi-threaded processing process to reduce the high threshold problem of existing compression methods and improve the execution efficiency of image compression, including but not limited to the functions provided by the Pyside2 module and the native threading module.
[0086] Specifically, the electronic device controls a main thread to distribute tasks to multiple sub-threads, controls a listening thread to listen to a first sub-thread, obtains an abnormal result, and feeds the abnormal result back to an interface control thread of a graphical user interface, so that the graphical user interface displays the abnormal result. The multiple sub-threads include at least the first sub-thread, which is used to analyze, convert the format of, and compress the image to be compressed.
[0087] It should be noted that the multi-threaded design provided in this embodiment is based on the user's perspective. After the processing process starts, it responds to the user's cancellation operation in real time through precise thread management, so as to stop the loss in time when the user makes an erroneous operation. The multi-threading uses the thread pool management method, that is, a main thread controls the distribution of tasks. After the child thread completes the processing of a single image, it activates the main thread and calls the main thread's dispatch function. The main thread decides to distribute subtasks or recycle subthreads based on the remaining capacity of the task pool, and returns processing results and warning logs and other information, thereby realizing an efficient process closed loop in the logic of thread management to ensure the processing speed of the method.
[0088] For example, in Figure 5 In the flowchart shown, the electronic device first determines whether the parameters to be adjusted exposed by the user to the electronic device are valid. If the parameters to be adjusted are invalid, the electronic device does not compress the image to be compressed; if the parameters to be adjusted are valid, the electronic device creates a management main thread and thread pool. The electronic device then creates a child thread, which records anomalies generated during the image compression process and skips the task in which the anomaly occurs. In addition, after converting the lossless format image to a DDS image, the child thread running the image compression task is released and the temporarily stored image is deleted. At the same time, the main thread calls the task pool margin from the management thread. If the task pool margin is empty, the child thread is released and the log of the output compressed image is compiled.
[0089] In addition, in the above process, if the electronic device receives a termination operation input by the user, the main thread stops and recycles all sub-threads.
[0090] In addition, it should be noted that the electronic device is able to respond to program execution exceptions, including but not limited to read and write errors of temporary images, permission errors, multi-thread conflict errors, etc.
[0091] In an optional embodiment, the electronic device obtains the parameters to be adjusted corresponding to the image to be compressed, adjusts the parameters to be adjusted to obtain the adjusted parameters, and then compresses the image to be compressed based on the adjusted parameters to obtain the target image.
[0092] Optionally, the above parameters to be adjusted can be but are not limited to Figure 6 The graphical interface shown shows the "target size", "keyword", "filter", "number of threads", "input format", "output format" and currently executable operations.
[0093] It should be noted that the graphical interactive design starts from the user's perspective, exposing the most critical adjustable parameters (and the above-mentioned parameters to be adjusted), and simplifying the user's operation complexity in a combination of graphics and text; with the form of a log window and progress bar, it intuitively presents records, statistics, warnings, operation records and other information to the user, and during the processing process, the most noteworthy information is filtered out, presented in real time and highlighted.
[0094] In another optional embodiment, the electronic device may further obtain and store the target object's operation record on a preset system, wherein the preset system is used to compress the image to be compressed.
[0095] Optionally, the target object may be a user, and the preset system may be a system for compressing images to be compressed, which may include an electronic device. Furthermore, the electronic device may record the user's usage habits and store user operations in the form of files, including but not limited to recording information such as the file directory selected during the last use, sampler type, number of threads, keywords, or target size.
[0096] Optional, Figure 7 The schematic diagram of the structure of the above preset system is shown. Figure 7 It can be seen that the system includes a graphical interface, a management thread (i.e., the main thread), an execution thread (i.e., the child thread), a policy decision model, and an image processing module, wherein the graphical interface can display "target size", "keyword", "filter" (i.e., sampling algorithm), "number of threads", "input format", "output format" and currently executable operations, such as updating the progress bar, starting execution, and terminating the thread. The management thread can manage the thread pool and the task pool, and can obtain the next task and update the task pool. The execution thread can process the image and temporarily store the processed image. The execution thread calls the policy decision module in the policy library to realize the image specification judgment, compression format judgment, and exception handling, etc., and calls the image processing method in the image processing module to realize the layering, image scaling, image loading, and image storage of the image.
[0097] As can be seen from the above, the solution provided by this embodiment is to crop the image to be compressed into equilateral polygons according to the target size preset by the user, and distinguish the image types by naming; the image to be compressed is parsed by an intelligent compression solution, and the optimal compression strategy is automatically selected based on the parsed data; the Python third-party library PIL and the native system function call TexConv technology are used to complete the resampling, scaling, compression and storage of the image to be compressed; and the execution efficiency is optimized by combining Pyside2 and Python's native multi-threaded module with the processing flow. This solves the problems of poor stability, impaired compression quality and low efficiency in image compression. The solution provided by this embodiment is particularly suitable for situations where a large number of multi-type DDS maps are mixed and the compression quality requirements are high.
[0098] According to an embodiment of the present invention, a method embodiment for compressing an image is also provided, wherein: Figure 8 FIG. 1 is a flow chart of a method for compressing an image according to an embodiment of the present invention. Figure 8 As shown, the method includes the following steps:
[0099] Step S802: Select an image to be compressed on the interactive interface, and select at least one adjustment parameter.
[0100] Optionally, the interactive interface can be Figure 6 The graphical interface shown in FIG, the user can select the image to be compressed by the image selection control corresponding to the "target folder" in the graphical interface, wherein the image to be compressed is stored in Figure 6 The address shown in the text box.
[0101] In addition, the adjustment parameters of the above formula can be but are not limited to Figure 6 The "target size", "keyword", "filter" (i.e. sampling algorithm), "number of threads", "input format" and "output format" corresponding to the image to be compressed.
[0102] It should be noted that after reading the image to be compressed, the electronic device performs an analysis operation on the image to be compressed to obtain adjustment parameters corresponding to the image to be compressed, and displays the values corresponding to the adjustment parameters on the interactive interface.
[0103] Step S804: calling a sampling function to perform sampling processing on the image to be compressed to obtain a sampling result.
[0104] In step S804, the electronic device may use sampling functions in the Python Image Library (PIL) to sample the image to be compressed. PIL can implement image processing functions for the image to be compressed, such as resizing the image to be compressed, rotating the image to be compressed, converting the format of the image to be compressed, and performing color field space conversion, interpolation, and filtering on the image to be compressed.
[0105] Optionally, after the electronic device samples the image to be compressed, it can obtain a sampling result containing the image features of the image to be compressed, wherein the image features of the image to be compressed include at least: the file name corresponding to the image to be compressed, the pixel format corresponding to the image to be compressed, and the image mode corresponding to the image to be compressed. The type of map corresponding to the image to be compressed is determined based on the uniquely identifiable keyword contained in the file name corresponding to the image to be compressed. For example, if it is detected that the file name of the image to be compressed contains "_m", it can be determined that the image to be compressed is a mixed map; for another example, if it is detected that the file name of the image to be compressed contains "_n", it can be determined that the image to be compressed is a normal map; for another example, if it is detected that the file name of the image to be compressed contains "_d", it can be determined that the image to be compressed is an intrinsic color map. In addition, the pixel format corresponding to the above-mentioned image to be compressed represents the compression format corresponding to the original image, including but not limited to DXT1 format, DXT5 format, and R8G8B8A8 format; the above-mentioned image mode represents the channel information corresponding to the image to be compressed, for example, the original image includes color channels (for example, RGB channels) and transparent channels (Alpha channels).
[0106] Step S806: Determine a compression method corresponding to the image to be compressed based on the sampling result and at least one adjustment parameter.
[0107] In step S806, the electronic device analyzes the sampling results to determine the texture type corresponding to the image to be compressed, the compression format corresponding to the original image, and channel information. The electronic device analyzes the above image features and adjustment parameters to determine the compression method for compressing the image to be compressed.
[0108] It should be noted that different images to be compressed have different corresponding image features. Analyzing these features and adjusting parameters to determine the compression method for the image to be compressed can make the compression method more suitable for the image to be compressed, thereby improving image compression quality. Furthermore, users can adjust the target size and output format of the compressed image, as well as the filters and number of threads used during the compression process, increasing the flexibility of image compression.
[0109] Step S808: compress the image to be compressed using a compression method to obtain a target image.
[0110] Optional, Figure 2 is the image to be compressed, Figure 3 and Figure 4 Both are target images obtained after compressing the image to be compressed. The size of the image to be compressed is 2048*2048. The image to be compressed contains 7 character textures and 212 engineering textures. The character textures are 60.0MB in total, and the engineering textures are 1.18GB in total. Figure 3 It is the result of adjusting the size of the image to be compressed to 1024*1024 and then compressing the resized image to be compressed. Figure 3 The 7 character textures total 14.4MB, the 212 engineering textures total 0.44GB, the compression rate is 37.3%, and the processing efficiency is 17 seconds. Figure 4 The result of resizing the image to be compressed to 512*512 and then compressing the resized image is obtained. Figure 4 In the file, 7 character textures total 3.54MB, 212 engineering textures total 0.12GB, the compression rate is 10.1%, and the processing efficiency is 16 seconds.
[0111] Depend on Figure 2-Figure 4It can be seen that for images of different sizes to be compressed, using the same compression method, the file size of the target image obtained is different, and the compression rate is also different, but the fidelity of the target image is not reduced, that is, the solution provided by this application can ensure the image compression quality.
[0112] In an embodiment of the present invention, an image is compressed using a compression method corresponding to the image to be compressed. The image to be compressed and at least one adjustment parameter are selected on an interactive interface. Then, a sampling function is called to perform sampling processing on the image to be compressed to obtain a sampling result. Based on the sampling result and at least one adjustment parameter, a compression method corresponding to the image to be compressed is determined. Finally, the compression method is used to compress the image to be compressed to obtain a target image.
[0113] In the above process, the compression method is determined by the image features of the image to be compressed. Therefore, this compression method is the optimal compression strategy for the image to be compressed. Using this compression method for compressing the image to be compressed can ensure image compression quality. Furthermore, in the above process, the compression method can be determined by simply analyzing the features of the image to be compressed. This compression method can then be directly used to compress the image to be compressed, eliminating the need for complex process modifications. This not only reduces image compression costs but also improves image compression efficiency.
[0114] It can be seen that the solution provided by this application achieves the purpose of image compression processing, thereby realizing the technical effect of improving the image compression quality, and further solving the technical problem of poor image compression quality when compressing images in the prior art.
[0115] It should be noted that the process of compressing the image to be compressed has been described in detail in the above embodiment and will not be repeated here.
[0116] According to an embodiment of the present invention, there is also provided an embodiment of a device for compressing an image, wherein: Figure 9 is a schematic diagram of an apparatus for compressing an image according to an embodiment of the present invention, such as Figure 9 As shown, the device includes: an acquisition module 901, an analysis module 903 and a compression module 905.
[0117] The acquisition module 901 is used to acquire the image to be compressed;
[0118] An analysis module 903 is used to analyze the image features of the image to be compressed and determine a compression method corresponding to the image to be compressed;
[0119] The compression module 905 is used to compress the image to be compressed in a compression manner to obtain a target image.
[0120] It should be noted that the above-mentioned acquisition module 901, analysis module 903 and compression module 905 correspond to steps S102 to S106 in the above-mentioned embodiment. The examples and application scenarios implemented by the three modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment.
[0121] Optionally, the analysis module includes: a sampling module, an extraction module, and a first determination module. The sampling module is configured to perform image sampling on the image to be compressed to obtain a first image; the extraction module is configured to perform feature extraction on the first image to obtain image features corresponding to the image to be compressed, wherein the image features include at least: the file name corresponding to the image to be compressed, the pixel format corresponding to the image to be compressed, and the image mode corresponding to the image to be compressed; and the first determination module is configured to determine the compression method corresponding to the image to be compressed based on the image features.
[0122] Optionally, the image compression apparatus further includes: a first detection module and a first processing module. The first detection module is configured to, after extracting features from the first image to obtain image features corresponding to the image to be compressed, detect whether the first image contains a transparent channel based on the pixel format to obtain a first detection result, wherein the transparent channel is configured to store at least transparency information and grayscale information in the first image; and the first processing module is configured to scale the first image based on the first detection result to obtain a second image.
[0123] Optionally, the first processing module includes: a splitting module, a second processing module, and a merging module. The splitting module is configured to, upon detecting that the first image contains a transparent channel, perform channel splitting processing on the first image to obtain a third image and a fourth image, wherein the third image is an image containing a transparent channel and the fourth image is an image containing color information; the second processing module is configured to perform scaling processing on the third image and the fourth image, respectively, to obtain a scaled third image and a scaled fourth image; and the merging module is configured to merge the scaled third image and the scaled fourth image to obtain a second image.
[0124] Optionally, the first processing module includes: a third processing module, configured to perform scaling processing on the first image to obtain a second image when it is detected that the first image does not contain a transparent channel.
[0125] Optionally, the image compression device further includes: a comparison module, a receiving module, and a first adjustment module. The comparison module is configured to compare the image size of the first image with a preset size before scaling the first image based on the first detection result to obtain a second image, thereby obtaining a comparison result. The receiving module is configured to receive a control instruction fed back by the target object based on the comparison result. The first adjustment module is configured to adjust the size of the first image based on the control instruction.
[0126] Optionally, the compression module includes: a conversion module and a fourth processing module. The conversion module is configured to convert the format of the image to be compressed to obtain a sixth image, wherein the sixth image includes image information contained in the image to be compressed; and the fourth processing module is configured to compress the sixth image using a compression method to obtain a target image.
[0127] Optionally, the image compression apparatus further includes: a second detection module and a third determination module. The second detection module is configured to detect whether the image information corresponding to the image to be compressed includes preset data and / or a transparent channel before compressing the sixth image using the compression method to obtain the target image, thereby obtaining a second detection result, wherein the preset data is the compressed image data; and the third determination module is configured to determine whether to compress the sixth image using the compression method based on the second detection result.
[0128] Optionally, the third determination module includes: a fifth processing module and a first generation module. The fifth processing module is configured to, when the compression method is the first compression method, compress the sixth image using the first compression method if the image information includes preset data but does not include a transparent channel or a compression flag prohibiting compression of the sixth image; and the first generation module is configured to generate a warning message if the image information does not include the preset data but includes a transparent channel or a compression flag.
[0129] Optionally, the third determination module includes: a sixth processing module and a second generation module. The sixth processing module is configured to, when the compression method is the second compression method, compress the sixth image using the second compression method if the image information includes preset data and a transparent channel but does not include a compression identifier prohibiting compression of the sixth image; and the second generation module is configured to generate a warning message if the image information does not include the preset data and the transparent channel but includes the compression identifier.
[0130] Optionally, the third determining module includes: a seventh processing module, configured to compress the sixth image using the third compression method when the compression method is the third compression method.
[0131] Optionally, the image compression apparatus further includes: a first control module and a second control module. The first control module is configured to control a main thread to distribute tasks to multiple sub-threads, wherein the multiple sub-threads include at least a first sub-thread, and the first sub-thread is configured to analyze, convert the format of, and compress the image to be compressed; and the second control module is configured to control a monitoring thread to monitor the first sub-thread, obtain an abnormal result, and feed the abnormal result back to an interface control thread of a graphical user interface, so that the graphical user interface displays the abnormal result.
[0132] Optionally, the image compression apparatus further includes: a first acquisition module, a second adjustment module, and an eighth processing module. The first acquisition module is configured to acquire parameters to be adjusted corresponding to the image to be compressed; the second adjustment module is configured to adjust the parameters to be adjusted to obtain adjusted parameters; and the eighth processing module is configured to compress the image to be compressed based on the adjusted parameters to obtain a target image.
[0133] Optionally, the image compression apparatus further includes: a second acquisition module and a storage module. The second acquisition module is used to acquire the target object's operation record on a preset system, wherein the preset system is used to compress the image to be compressed; and the storage module is used to store the operation record.
[0134] According to another aspect of an embodiment of the present invention, a storage medium is provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned method for compressing an image when running.
[0135] According to another aspect of an embodiment of the present invention, an electronic device is also provided, which includes one or more processors; a storage device for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the above-mentioned method of compressing images when running.
[0136] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0137] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0138] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0139] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0140] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0141] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.
[0142] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A method for compressing an image, characterized in that: include: Obtain the image to be compressed; Performing image sampling on the image to be compressed to obtain a first image; Performing feature extraction on the first image to obtain image features corresponding to the first image; Detecting whether the first image includes a transparent channel according to an image feature corresponding to the first image, and obtaining a first detection result; Scaling the first image according to a preset scaling strategy and the first detection result to obtain a second image, wherein the preset scaling strategy is used to perform channel splitting, scaling, and merging on the first image when the first image contains the transparent channel, or to perform scaling on the first image when the first image does not contain the transparent channel; performing feature extraction on the second image to obtain image features corresponding to the second image; determining a compression method corresponding to the image to be compressed according to an image feature corresponding to the second image; The image to be compressed is compressed using the compression method to obtain a target image.
2. The method according to claim 1, characterized in that: The image features corresponding to the first image include at least: a file name corresponding to the image to be compressed, a pixel format corresponding to the image to be compressed, and an image mode corresponding to the image to be compressed.
3. The method according to claim 2, characterized in that The transparent channel is used to store at least transparency information and grayscale information in the first image.
4. The method according to claim 3, characterized in that Scaling the first image according to a preset scaling strategy and the first detection result to obtain a second image includes: In the case where it is detected that the first image contains the transparent channel, performing channel splitting processing on the first image to obtain a third image and a fourth image, wherein the third image is an image containing the transparent channel, and the fourth image is an image containing color information; Scaling the third image and the fourth image respectively to obtain a scaled third image and a scaled fourth image; The scaled third image and the scaled fourth image are combined to obtain the second image.
5. The method according to claim 3, characterized in that: Scaling the first image according to a preset scaling strategy and the first detection result to obtain a second image includes: When it is detected that the first image does not contain the transparent channel, scaling is performed on the first image to obtain the second image.
6. The method according to claim 3, characterized in that: Before scaling the first image according to the preset scaling strategy and the first detection result to obtain the second image, the method further includes: Comparing the image size corresponding to the first image with a preset size to obtain a comparison result; receiving a control instruction fed back by the target object according to the comparison result; The size of the first image is adjusted according to the control instruction.
7. The method according to claim 1, characterized in that The method of compressing the image to be compressed by using the compression method to obtain a target image includes: Performing format conversion on the image to be compressed to obtain a sixth image, wherein the sixth image includes image information contained in the image to be compressed; The sixth image is compressed using the compression method to obtain the target image.
8. The method according to claim 7, characterized in that Before compressing the sixth image in the compression mode to obtain the target image, the method further includes: Detecting whether the image information corresponding to the image to be compressed includes preset data and / or a transparent channel to obtain a second detection result, wherein the preset data is image data after compression processing; Determine whether to use the compression method to compress the sixth image according to the second detection result.
9. The method according to claim 8, characterized in that Determining whether to use the compression method to compress the sixth image according to the second detection result includes: In the case where the compression method is the first compression method, if the image information includes the preset data but does not include the transparent channel and the compression mark for prohibiting compression of the sixth image, the first compression method is used to compress the sixth image; If the image information does not contain the preset data, including the transparent channel or the compression identifier, a warning message is generated.
10. The method according to claim 8, characterized in that Determining whether to use the compression method to compress the sixth image according to the second detection result includes: In the case where the compression mode is the second compression mode, if the image information includes the preset data and the transparent channel but does not include a compression mark for prohibiting compression of the sixth image, the second compression mode is used to compress the sixth image; If the image information does not include the preset data and the transparent channel, including the compression identifier, a warning message is generated.
11. The method according to claim 8, characterized in that Determining whether to use the compression method to compress the sixth image according to the second detection result includes: When the compression method is the third compression method, the third compression method is used to compress the sixth image.
12. The method according to claim 7, characterized in that The method further comprises: Controlling the main thread to distribute tasks to multiple sub-threads, wherein the multiple sub-threads include at least a first sub-thread, and the first sub-thread is used to analyze, convert the format of, and compress the image to be compressed; The monitoring thread is controlled to monitor the first sub-thread to obtain an abnormal result, and the abnormal result is fed back to the interface control thread of the graphical user interface so that the graphical user interface displays the abnormal result.
13. The method according to claim 1, characterized in that The method further comprises: Obtaining the parameters to be adjusted corresponding to the image to be compressed; Adjusting the parameter to be adjusted to obtain an adjusted parameter; The image to be compressed is compressed based on the adjusted parameters to obtain the target image.
14. The method according to claim 1, characterized in that The method further comprises: Acquiring an operation record of a target object on a preset system, wherein the preset system is used to compress the image to be compressed; The operation record is stored.
15. A method for compressing an image, characterized in that: include: Selecting an image to be compressed and at least one adjustment parameter on the interactive interface; Calling a sampling function to perform sampling processing on the image to be compressed to obtain a sampling result; Determining a compression method corresponding to the image to be compressed based on the sampling result and the at least one adjustment parameter; Using the compression method to compress the image to be compressed to obtain a target image; The method of determining the compression method corresponding to the image to be compressed based on the sampling result and the at least one adjustment parameter includes: performing feature extraction on the sampling result to obtain image features corresponding to the sampling result; detecting whether the sampling result includes a transparent channel according to the image features corresponding to the sampling result to obtain a first detection result; performing scaling processing on the sampling result according to a preset scaling strategy and the first detection result to obtain a second image, wherein the preset scaling strategy is used to perform channel splitting processing, scaling processing and merging processing on the sampling result when the sampling result includes the transparent channel, or to perform scaling processing on the sampling result when the sampling result does not include the transparent channel; performing feature extraction on the second image to obtain image features corresponding to the second image; and determining the compression method corresponding to the image to be compressed according to the image features corresponding to the second image and the at least one adjustment parameter.
16. A device for compressing an image, characterized in that: include: An acquisition module, used for acquiring an image to be compressed; A sampling module, used for performing image sampling on the image to be compressed to obtain a first image; An extraction module, used to extract features from the first image to obtain image features corresponding to the first image; A first detection module, configured to detect whether the first image contains a transparent channel according to an image feature corresponding to the first image, and obtain a first detection result; a first processing module, configured to perform scaling processing on the first image according to a preset scaling strategy and the first detection result to obtain a second image, wherein the preset scaling strategy is used to perform channel splitting processing, scaling processing, and merging processing on the first image when the first image contains the transparent channel, or to perform scaling processing on the first image when the first image does not contain the transparent channel; A feature extraction module, used to extract features from the second image to obtain image features corresponding to the second image; An analysis module, used to determine a compression method corresponding to the image to be compressed according to an image feature corresponding to the second image; The compression module is used to compress the image to be compressed using the compression method to obtain a target image.
17. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method for compressing an image as claimed in any one of claims 1 to 15 when executed.
18. An electronic device, characterized in that: The electronic device comprises one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the method for compressing images described in any one of claims 1 to 15 when run.
Citation Information
Patent Citations
Image compression method and device based on Unity 3D, computer device and storage medium
CN110189384A