Image compression method and device, electronic equipment and nonvolatile storage medium
By dynamically adjusting the decomposition level and quantization process of wavelet transform, the problem of poor compression effect in image compression by traditional DWT method is solved, and more efficient image compression and storage are achieved.
Patent Information
- Application Number
- CN202411899286.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2044-12-20
AI Technical Summary
In existing technologies, the traditional DWT method is too static in its selection of the number of decomposition layers, making it difficult to adapt to the diversity of image content, resulting in poor compression performance of image compression algorithms.
By obtaining the number of edges in the image, the image complexity information is determined, the number of decomposition levels of the wavelet transform is dynamically adjusted, and multi-level wavelet transform and quantization processing are performed to optimize the image compression process.
It achieves improved compression ratio while maintaining image quality, flexible compression adaptable to different image content, and optimized storage and transmission efficiency.
Smart Images

Figure CN119728971B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to an image compression method and device, electronic equipment and non-volatile storage medium. BACKGROUND
[0002] With the rapid development of digital technology, image data as an important medium for information transmission occupies an indispensable position in daily life and various industries. However, color images often have large data volume due to their rich color information and high resolution characteristics, which not only occupies a large amount of storage space, but also increases data traffic in the transmission process. Therefore, how to effectively compress image data while maintaining image quality is a major challenge in the field of digital image processing.
[0003] Discrete wavelet transform (DWT) is widely used in image compression field due to its superior time-frequency local characteristics and multi-resolution analysis capability. However, the traditional DWT method in the related art is too static in the selection of decomposition layers and is not flexible enough to adapt to the diversity of image content. This causes the compression algorithm in the related art to have poor compression effect.
[0004] At present, no effective solution has been proposed to solve the above problems. SUMMARY
[0005] The embodiments of the present application provide an image compression method, device, electronic equipment and non-volatile storage medium to at least solve the technical problem of poor compression effect of the compression algorithm in the related art.
[0006] According to an aspect of an embodiment of the present application, an image compression method is provided, comprising: obtaining a first image and determining the number of edges in the first image, and determining image complexity information of the first image according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions; determining the decomposition layer number of wavelet transform according to the image complexity information, and performing multi-level wavelet transform on each channel component of the first image according to the decomposition layer number, to obtain wavelet coefficients corresponding to the channel component; performing quantization processing on the wavelet coefficients, wherein the quantization processing is used to reduce the data volume by reducing the precision of the wavelet coefficients; performing image reconstruction according to the wavelet coefficients after the quantization processing to obtain the first image after compression.
[0007] Optionally, the acquiring the first image comprises: acquiring a second image to be compressed, wherein the second image is an image in a red-green-blue (RGB) color space; and converting the second image from the RGB color space to a luminance-chrominance (YCbCr) color space to obtain the first image, wherein the first image comprises a luminance channel component, a blue chrominance channel component, and a red chrominance channel component.
[0008] Optionally, the determining the image complexity information of the first image according to the number of edges comprises: determining a target operator, wherein the target operator is used to enhance the gray-scale transformation in the horizontal direction and / or the vertical direction of the image to detect the horizontal edges and the vertical edges in the image; performing a convolution operation on each pixel in the first image by using the target operator to obtain the edge intensity corresponding to each pixel; determining the positions of the pixels in the first image whose edge intensity exceeds a preset intensity threshold as significant edges, and counting the number of the significant edges to obtain the number of edges; and determining the proportion of the significant edges in the first image according to the number of edges, and determining the image complexity information of the first image according to the proportion.
[0009] Optionally, the performing the multi-level wavelet transform on each channel component of the first image according to the number of decomposition layers comprises: determining the number of decomposition layers according to the image complexity information of the luminance channel component of the first image and a preset proportion factor; and performing a wavelet transform on each channel component of the first image according to the number of decomposition layers to obtain the wavelet coefficients corresponding to each channel component, wherein the wavelet transform is used to decompose the image into details in different scales and directions.
[0010] Optionally, the quantizing the wavelet coefficients comprises: dividing the wavelet coefficients by a quantization factor to obtain a target multiple; rounding the target multiple to obtain a target integer corresponding to the target multiple; and determining the product of the target integer and the quantization factor as the result of the quantized wavelet coefficients.
[0011] Optionally, the performing the image reconstruction according to the quantized wavelet coefficients to obtain the compressed first image comprises: performing an inverse wavelet transform on the quantized wavelet coefficients corresponding to each channel component to obtain image data corresponding to each channel component; performing cropping on the image data corresponding to each channel component according to the image size information of the first image; and merging the cropped image data corresponding to each channel component to obtain the compressed first image.
[0012] Optionally, after obtaining the compressed first image, the method further comprises: converting the compressed first image from the YCbCr color space to the RGB color space to obtain a compressed second image.
[0013] According to another aspect of the embodiments of the present application, an image compression device is also provided, comprising: a complexity determination module configured to acquire a first image, determine the number of edges in the first image, and determine image complexity information of the first image according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions; a wavelet transform module configured to determine the decomposition level of wavelet transform according to the image complexity information, and perform multi-level wavelet transform on each channel component of the first image according to the decomposition level to obtain wavelet coefficients corresponding to the channel component; a quantization compression module configured to perform quantization processing on the wavelet coefficients, wherein the quantization processing is used to reduce the data volume by reducing the precision of the wavelet coefficients; and an image reconstruction module configured to perform image reconstruction according to the wavelet coefficients after the quantization processing to obtain the first image after compression.
[0014] According to still another aspect of the embodiments of the present application, an electronic device is also provided, comprising: a memory and a processor, the processor being configured to run a program stored in the memory, wherein the program is executed when performing the image compression method.
[0015] According to still another aspect of the embodiments of the present application, a non-volatile storage medium is also provided, comprising a stored computer program, wherein the device where the non-volatile storage medium is located performs the image compression method by running the computer program.
[0016] According to still another aspect of the embodiments of the present application, a computer program product is also provided, comprising a computer program, the computer program being executed by the processor to implement the steps of the image compression method.
[0017] In the embodiments of the present application, the first image is acquired, the number of edges in the first image is determined, and the image complexity information of the first image is determined according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions; the decomposition level of wavelet transform is determined according to the image complexity information, and multi-level wavelet transform is performed on each channel component of the first image according to the decomposition level to obtain wavelet coefficients corresponding to the channel component; quantization processing is performed on the wavelet coefficients, wherein the quantization processing is used to reduce the data volume by reducing the precision of the wavelet coefficients; and image reconstruction is performed according to the wavelet coefficients after the quantization processing to obtain the first image after compression. The color image compression method based on improved discrete wavelet transform (DWT) estimates the image complexity through a multi-scale decomposition strategy, and automatically adjusts the decomposition level of wavelet transform according to the complexity, and then reduces the redundancy of data through the quantization process to further compress the image data, so as to balance the compression efficiency and the image quality, make the compressed image have better compression ratio while ensuring the visual quality, and further solve the technical problem of poor compression effect of the compression algorithm in the related art. BRIEF DESCRIPTION OF DRAWINGS
[0018] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application. In the drawings:
[0019] Figure 1 Fig. 1 is a hardware structure block diagram of a computer terminal (or electronic device) for implementing a method for image compression according to an embodiment of the application;
[0020] Figure 2 Fig. 2 is a flowchart of a method for image compression according to an embodiment of the application;
[0021] Figure 3 Fig. 3 is a structural schematic diagram of an image compression device according to an embodiment of the application. DETAILED DESCRIPTION
[0022] In order to enable persons skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by persons skilled in the art without creative work should fall within the protection scope of the present application.
[0023] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to include only those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to the process, method, product or device.
[0024] Image compression technology is one of the cores in the field of digital image processing, aiming to reduce the amount of image data, improve the efficiency of storage and transmission, and maintain the original quality of the image as much as possible. In recent years, various image compression technologies have been developed and improved in related technologies. For example, discrete wavelet transform (DWT) is widely used in image coding due to its superior time-frequency characteristics and hierarchical structure. However, despite the existence of various efficient image compression methods, how to further improve the compression ratio while ensuring image quality remains a challenge. In particular, for image content with different complexities, how to design a flexible and efficient compression strategy to adapt to the needs of different scenarios is one of the key points of current research.
[0025] To solve the above problems, an improved DWT-based color image compression method is provided in the embodiments of the present application. First, the image is converted from the RGB color space to the YCbCr color space, and color space transformation is used to reduce color redundancy. Then, by evaluating the complexity of the image, the decomposition level of DWT is dynamically adjusted, and personalized compression is performed according to the different characteristics of the image content. In addition, a quantization processing step is introduced to optimize the storage and transmission efficiency of data. The innovation of the present application lies in providing a strategy to automatically adjust the compression parameters according to the image complexity, achieving a better balance between improving the compression efficiency and maintaining the image quality. Experimental verification shows that the present application method has excellent compression ratio and visual effect on various image samples, showing wide application potential, especially suitable for fields with high requirements on compression efficiency and image quality, such as satellite image processing, medical image storage, and online video transmission. The following will be introduced in detail.
[0026] According to the embodiments of the present application, a method embodiment of image compression 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 the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from here.
[0027] The method embodiment provided by the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 A hardware structure block diagram of a computer terminal (or electronic device) for implementing the image compression method is shown. As Figure 1As shown, the computer terminal 10 (or electronic device) can include one or more processors 102 (the processor 102 can include, but not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it can also include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. Those skilled in the art can understand that Figure 1 The structure shown is only schematic, which does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 10 can include more or fewer components than those shown in Figure 1 or have a different configuration than that shown in Figure 1 .
[0028] It should be noted that the one or more processors 102 and / or other data processing circuits described above can be referred to herein as "data processing circuits" in general. The data processing circuit can be embodied in whole or in part as software, hardware, firmware or any other combination. In addition, the data processing circuit can be a single independent processing module, or any one of the other elements incorporated into the computer terminal 10 (or electronic device) in whole or in part. As referred to in the embodiments of the present application, the data processing circuit serves as a processor to control (for example, selection of a variable resistance terminal path connected to an interface).
[0029] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the image compression method in the embodiments of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, implements the above-mentioned image compression method. The memory 104 can include a high-speed random access memory, and can also include a non-volatile memory such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 can further include a memory remotely disposed with respect to the processor 102, which can be connected to the computer terminal 10 through a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0030] The transmission device 106 is configured to receive or send data via a network. The network can include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network interface controller (NIC) that can connect to other network devices through a base station to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module that is configured to communicate with the Internet wirelessly.
[0031] The display can be a liquid crystal display (LCD) that is touch screen type, for example, which can enable a user to interact with a user interface of the computer terminal 10 (or electronic device).
[0032] In the above operating environment, the embodiments of the present application provide an image compression method, Figure 2 is a schematic diagram of a method flow of an image compression method according to the embodiments of the present application, as Figure 2 shown, the method includes the following steps:
[0033] In step S202, a first image is acquired, and the number of edges in the first image is determined, and the image complexity information of the first image is determined according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions;
[0034] In step S204, the decomposition layer number of the wavelet transform is determined according to the image complexity information, and the multi-level wavelet transform is performed on each channel component of the first image according to the decomposition layer number, to obtain the wavelet coefficients corresponding to the channel components;
[0035] In step S206, the wavelet coefficients are quantized, wherein the quantization is used to reduce the data amount by reducing the precision of the wavelet coefficients;
[0036] In step S208, the first image after compression is obtained by image reconstruction according to the wavelet coefficients after quantization.
[0037] Through the above steps, the color image compression method based on the improved discrete wavelet transform estimates the image complexity through the multi-scale decomposition strategy, and automatically adjusts the decomposition layer number of the wavelet transform according to the complexity, and then reduces the data redundancy through the quantization process to further compress the image data, so as to balance the compression efficiency and the image quality, so that the compressed image has better compression ratio while ensuring the visual quality, thereby solving the technical problem of poor compression effect of the compression algorithm in the related art.
[0038] The image compression method in steps S202 to S208 of the embodiments of the present application will be further described below.
[0039] In this embodiment, when compressing a color image, the color image is first converted from the RGB color space to the YCbCr color space. Then, the image complexity is estimated using a multi-scale decomposition strategy, and the number of wavelet transform decomposition levels is automatically adjusted based on the complexity. Afterward, data redundancy is reduced through a quantization process, further compressing the image data to obtain the compressed image. The steps in this process are described in detail below.
[0040] In the process of color image compression, the original image (i.e., the second image to be compressed) is first converted from the RGB color space to the YCbCr color space. This can better separate the brightness and chromaticity components of the image, thereby optimizing the subsequent compression steps, as follows.
[0041] In some embodiments of this application, obtaining the first image includes the following steps: obtaining a second image to be compressed, wherein the second image is an image in the RGB color space; converting the second image from the RGB color space to the YCbCr color space to obtain the first image, wherein the first image includes: a luminance channel component, a blue color difference channel component, and a red color difference channel component.
[0042] Specifically, in practical implementation, relevant libraries for image processing and mathematical calculations in Python can be introduced. The image processing library Pillow can be used to load the original RGB image (i.e., the second image) and perform color space conversion, that is, convert the color space of the image from RGB to YCbCr to obtain the first image. In the YCbCr color space, the luminance information (Y, i.e., the luminance channel component) and chrominance information (Cb and Cr, i.e., the blue and red color difference channel components) of an image can be processed separately.
[0043] For example, the following code can be used to implement the steps of this color space conversion:
[0044] # Import the required libraries
[0045] import numpy as np
[0046] import pywt
[0047] fromPIL import Image
[0048] #Use the Pillow library to convert color spaces from RGB to YCbCr
[0049] def convert_rgb_to_ycbcr(image):
[0050] return image.convert('YCbCr')”
[0051] After obtaining the first image in the YCbCr color space, a multi-scale decomposition strategy can be used to evaluate the complexity of the image. First, the number of edges in the first image is determined, and then the image complexity information of the first image is determined according to the number of edges. The specific steps are as follows.
[0052] In some embodiments of the present application, determining the image complexity information of the first image according to the number of edges includes the following steps: determining a target operator, wherein the target operator is used to enhance the gray scale transformation in the horizontal direction and / or the vertical direction of the image to detect the horizontal edges and vertical edges in the image; using the target operator to perform convolution operation on each pixel in the first image to obtain the edge intensity corresponding to each pixel; determining the position of the pixel in the first image whose edge intensity exceeds the preset intensity threshold as a significant edge, and counting the number of significant edges to obtain the number of edges; determining the proportion of significant edges in the first image according to the number of edges, and determining the image complexity information of the first image according to the proportion.
[0053] For example, the evaluation of the complexity information of the image can be realized by the following code:
[0054] “# Evaluate the complexity of the image by calculating the number of edges
[0055] def estimate_complexity(image_array):
[0056] # In this embodiment, a simple Sobel operator can be used to estimate the edge density, and a more accurate method can be used in practice
[0057] sobel_x=np.array([[-1,0,1],[-2,0,2],[-1,0,1]])
[0058] sobel_y=np.array([[-1,-2,-1],[0,0,0],[1,2,1]])
[0059] edge_x=np.abs(np.convolve(image_array,sobel_x,mode='valid'))
[0060] edge_y=np.abs(np.convolve(image_array,sobel_y,mode='valid'))
[0061] edges=np.hypot(edge_x,edge_y)
[0062] edge_density = np.sum(edges > 50) / edges.size # here the preset intensity threshold 50 can be adjusted according to actual needs
[0063] return edge_density
[0064] Specifically, the evaluation of the image complexity information can be achieved by calculating the number of edges in the first image. In this embodiment, the target operator (such as the Sobel operator) can be used to identify the edges, and the complexity can be evaluated according to the edge density, which will affect the number of wavelet transform layers in the subsequent process.
[0065] The Sobel operator is used to detect horizontal and vertical edges in the image. The edge is a place where the brightness changes significantly in the image, and usually marks the boundary between different regions. In this embodiment, the Sobel operator contains two 3x3 convolution kernels, including a horizontal edge detection kernel (Sobel_x) and a vertical edge detection kernel (Sobel_y), which are used to detect horizontal and vertical edges in the image, respectively. The Sobel operator is applied to each pixel of the image, and the edge intensity is calculated by convolution operation. The specific steps are as follows: for each pixel in the image, its neighborhood (usually a 3x3 region) is convolved with the Sobel_x and Sobel_y kernels. The convolution operation is completed by multiplying each element of the kernel with its corresponding pixel element and then summing. After convolving the image with the Sobel_x kernel, the result is a horizontal edge intensity map. After convolving the image with the Sobel_y kernel, the result is a vertical edge intensity map. The horizontal and vertical edge intensities are combined to obtain the total edge intensity map. This can usually be done by calculating the Euclidean distance of the horizontal and vertical edge intensities. In order to determine which edges are significant, a preset intensity threshold needs to be set. In the above code, this threshold is 50, but this value can be adjusted according to the image and application scenario. By comparing the edge intensity with the threshold, the significant edges are determined; by calculating the total number of significant edges and then dividing by the total number of pixel edges.size, the edge density edge_density is obtained, i.e. the proportion of significant edges in the above first image, which can be used to evaluate the complexity of the image. The higher the edge density, the more complex the image.
[0066] After that, the decomposition layer number can be automatically adjusted according to the image complexity information, and the discrete wavelet transform (DWT) is applied to the Y, Cb and Cr channels respectively according to the decomposition layer number, and multi-layer processing is performed to achieve the predetermined compression effect. The specific steps are as follows.
[0067] In some embodiments of the present application, the multi-level wavelet transform is performed on each channel component of the first image according to the number of decomposition layers, to obtain wavelet coefficients corresponding to the channel components, including the following steps: determining the number of decomposition layers according to image complexity information corresponding to a luminance channel component of the first image and a preset scale factor; performing wavelet transform on each channel component of the first image according to the number of decomposition layers, to obtain wavelet coefficients corresponding to each channel component, wherein the wavelet transform is used to decompose the image into details of different scales and directions.
[0068] For example, the wavelet transform of each channel component can be implemented by the following code:
[0069] “# Perform multi-level wavelet transform on the image
[0070] def wavelet_transform(image, levels=3):
[0071] # Convert the image to an array for processing
[0072] image_array = np.array(image)
[0073] # Get each channel
[0074] y_channel, cb_channel, cr_channel = image_array[:,:,0], image_array[:,:,1], image_array[:,:,2]
[0075] # Evaluate the complexity of the Y channel to determine the number of decomposition layers
[0076] complexity = estimate_complexity(y_channel)
[0077] # The scale factor 2 here can be adjusted as needed
[0078] levels = base_level + int(complexity*2)
[0079] # Perform wavelet transform on all channels
[0080] coeffs_y = pywt.wavedec2(y_channel, 'haar', level=levels)
[0081] coeffs_cb = pywt.wavedec2(cb_channel, 'haar', level=levels)
[0082] coeffs_cr = pywt.wavedec2(cr_channel, 'haar', level=levels)
[0083] return coeffs_y, coeffs_cb, coeffs_cr
[0084] Specifically, wavelet transform can be performed on each channel (Y, Cb, Cr) of the image according to the complexity of the first image, in particular the complexity of the luminance channel (Y channel). Wavelet transform can decompose the image into details at different scales and directions, allowing different parts of the image to be processed at different levels. According to the complexity of the image, different decomposition levels can be selected to optimize compression efficiency.
[0085] Subsequently, the obtained wavelet coefficients can be quantized to further reduce the data volume, and the specific steps are as follows.
[0086] In some embodiments of the present application, the quantization of the wavelet coefficients includes the following steps: dividing the wavelet coefficients by the quantization factor to obtain the target multiple; rounding the target multiple to obtain the target integer corresponding to the target multiple; and multiplying the target integer by the quantization factor to determine the result of the quantized wavelet coefficients.
[0087] Specifically, after wavelet transform, a series of coefficients are obtained, which represent different frequency components of the image. In order to further compress the image, the coefficients are quantized, i.e. the precision of the coefficients is reduced. Through quantization, many high-frequency coefficients may become zero, thereby reducing the data volume while preserving the main image features.
[0088] For example, the quantization of the wavelet coefficients can be implemented by the following code:
[0089] “# Quantization process, the actual quantization strategy can be adjusted
[0090] def apply_quantization(coeffs, qfactor=50):
[0091] quantized_coeffs = map(lambda x: np.round(x / qfactor)*qfactor, coeffs)
[0092] return list(quantized_coeffs)
[0093] In this embodiment, a function named apply_quantization` is defined, which takes two parameters: coeffs (a list of wavelet coefficients after wavelet transform) and qfactor (quantization factor, with a default value of 50). A lambda function is used to quantize each wavelet coefficient in coeffs, specifically by dividing the wavelet coefficient `x` by the quantization factor qfactor. Then, the np.round` function is used to round the result to the nearest integer (i.e., the target integer). This step effectively "compresses" the value of the coefficient to a multiple of the quantization factor. Finally, the rounded value is multiplied by the quantization factor qfactor to restore its original magnitude, but with reduced precision.
[0094] After that, the image is reconstructed using the quantized wavelet coefficients, and the details of each frequency and position of the image are recombined to obtain the compressed first image. The specific steps are as follows.
[0095] In some embodiments of the present application, the image reconstruction based on the quantized wavelet coefficients to obtain the compressed first image includes the following steps: performing inverse wavelet transform on the quantized wavelet coefficients corresponding to each channel component to obtain image data corresponding to each channel component; cropping the image data corresponding to each channel component according to the image size information of the first image, and merging the cropped image data corresponding to each channel component to obtain the compressed first image.
[0096] For example, image reconstruction can be implemented by the following code:
[0097] "# Merge Y, Cb, Cr channels to recombine three channels into a complete image.
[0098] def inverse_wavelet_transform(coeffs_y,coeffs_cb,coeffs_cr,image_size):
[0099] y_reconstructed=pywt.waverec2(coeffs_y,'haar')
[0100] cb_reconstructed=pywt.waverec2(coeffs_cb,'haar')
[0101] cr_reconstructed=pywt.waverec2(coeffs_cr,'haar')
[0102] # Since the reconstructed size can have a slight deviation from the original size, it needs to be cropped or padded to the original size y_reconstructed = y_reconstructed[:image_size[0],:image_size[1]]
[0103] cb_reconstructed = cb_reconstructed[:image_size[0],:image_size[1]]
[0104] cr_reconstructed = cr_reconstructed[:image_size[0],:image_size[1]]
[0105] # Stack the generated target image, which is the first image after compression, on three channels
[0106] reconstructed_image = np.stack([y_reconstructed, cb_reconstructed, cr_reconstructed], axis=-1).astype(np.uint8)
[0107] return reconstructed_image
[0108] In this embodiment, a function named inverse_wavelet_transform` is defined, which accepts four parameters: coeffs_y (wavelet coefficients for the Y channel), coeffs_cb (wavelet coefficients for the Cb channel), coeffs_cr (wavelet coefficients for the Cr channel), and image_size (the size of the original image, given in the form `(width, height)`). The inverse wavelet transform is performed on the wavelet coefficients for each channel using the pywt.waverec2` function. This function converts the wavelet coefficients back to the original image data. Since there may be a slight difference between the size of the image after the inverse wavelet transform and the original image size, the reconstructed image needs to be cropped or padded to the original size. Finally, the np.stack` function is used to stack the reconstructed images of the Y, Cb, and Cr channels along the last axis (usually the color channel axis) to generate a complete image, which is the first image after compression.
[0109] Further, after obtaining the compressed first image, the method further comprises the following steps: converting the compressed first image from the YCbCr color space to the RGB color space to obtain a compressed second image. That is, the reconstructed first image is converted from the YCbCr color space back to the original RGB color space and output to obtain the compressed second image. The whole process not only optimizes the storage and transmission efficiency, but also maintains the visual quality of the image to a certain extent.
[0110] In order to ensure the reliability of the method, the hardware scheme of the present application can use a flexible cloud host for experiment, the hardware specifications are 8-core CPU, 16GB memory, 500GB object storage cloud hard disk is mounted, the operating system is Ubuntu 20.04LTS, and the bandwidth size is 20Mbps. The software scheme of the present application is realized by writing an application program based on the Numpy library and the Pywt library of Python. In order to verify the compression effect of the algorithm in the actual environment, the experiment adopts a classical image processing picture data set, including Baboon, Lena, Peppers and Boat four pictures. The colors and patterns contained in these pictures are relatively comprehensive, and they are suitable as original images for image processing algorithms.
[0111] In order to analyze the experimental results, a Web application containing the algorithm proposed in this paper is developed in the cloud environment. The Web application runs in the cloud environment of the cloud network service, encapsulates the algorithm into a Web module, and opens an interface. The HTTP network request is called on the local computer, the local data set is transmitted to the cloud server through the interface program, and the encryption algorithm result is verified.
[0112] The test verification results of the scheme of the present application are introduced as follows.
[0113] In the implementation of the present application, in order to evaluate the performance of the color image compression method based on the improved DWT, the compression effects of the method and the traditional JPEG 2000 compression technology are compared. Each image is first converted to the YCbCr color space, and then according to the complexity of the luminance channel, a suitable wavelet transform layer is selected for DWT. After image compression, the inverse wavelet transform is reconstructed, and finally converted back to the RGB color space. In this embodiment, the peak signal-to-noise ratio (PSNR) and the structural similarity index (SSIM) are used to evaluate the image quality. The comparison of the compression results is shown in the following table.
[0114]
[0115]
[0116] The experimental results show that the method proposed in the application performs particularly well on high complexity images. On lower complexity images, such as simple natural landscapes, the improved DWT method can achieve similar compression ratios to JPEG 2000, but is more effective in maintaining higher image quality.
[0117] On the other hand, for the analysis of compression time, in addition to the above pictures, the embodiment also compares other types of pictures, such as grayscale, color images, and pictures of different image sizes and dimensions. The results of different image types, sizes and dimensions are shown in the following table.
[0118]
[0119] As can be seen from the table, the average compression time and the average decompression time are related to the size and dimension of the image, and the larger the size and dimension of the image, the longer the compression and decompression time consumed. And compared with grayscale images, the compression time will also increase due to the relatively rich colors on the color channel. But the overall compression and decompression time is also controlled within a certain range. In terms of image size, the size of the processed image is obviously smaller than the size of the original image.
[0120] The embodiment of the application dynamically adjusts the decomposition layer number of the discrete wavelet transform (DWT) by evaluating the image complexity, which is more flexible than the static decomposition strategy of the traditional method and better adapts to the diversity of image content. Through color space conversion from RGB to YCbCr, the image information is more effectively expressed, especially for the separation of luminance and chrominance information, which plays an important role in improving compression efficiency and maintaining image quality. After wavelet transform, the coefficient is quantized to effectively reduce the data volume and reduce the redundancy in storage and transmission process, which provides strong support for realizing high compression ratio.
[0121] In summary, the scheme of the application proposes a color image compression method based on improved discrete wavelet transform, which realizes personalized compression for different image contents by adding image complexity evaluation and dynamically adjusting the decomposition layer number in the compression process. The original image is converted from RGB color space to YCbCr color space, which effectively reduces color redundancy and optimizes the luminance and chrominance components of the image, further improving the compression efficiency. Through experiments, compared with traditional compression technologies such as JPEG 2000, the method of the application can provide better compression ratio while maintaining visual quality, especially when processing high complexity images. The method realizes the goal of improving compression ratio while ensuring image visual quality. The method has wide application potential and practical value in application scenarios such as satellite image processing, medical image storage, online video transmission, etc. which require efficient data storage and transmission.
[0122] Specifically, in the process of satellite image transmission and storage, due to the huge amount of image data, efficient compression technology is particularly important. The method can dynamically adjust the compression strategy according to the complexity of the image, which is suitable for optimizing the storage and transmission of satellite image data, reducing bandwidth occupation, and improving data processing speed; in the medical field, the high quality of images such as MRI and CT is the key to diagnostic accuracy. This technology can help medical institutions effectively manage and store a large amount of image data while ensuring image quality and improving access efficiency; for video live streaming and online video services, compression technology can significantly reduce data transmission time and cost. The method can dynamically adjust the compression level to adapt to the complexity of different scenes in the video, which can optimize the transmission quality and buffering speed of streaming media.
[0123] By effectively compressing image data, enterprises and service providers can reduce the required archival space while maintaining image quality, thereby directly reducing physical storage costs; compression technology can reduce the amount of data transmitted over the network, speed up data transmission, and reduce network burden, which is particularly important in cases where broadband resources are limited. Smaller data volume during data processing and transmission can reduce energy consumption, which is an environmental and cost factor that cannot be ignored for enterprises operating large data centers. The application provides a new way for personalized data processing by dynamically adjusting the compression strategy to reduce the required archival space while maintaining image quality, which meets the specific needs of different users and industries for data processing. It has certain research value in network data security protection.
[0124] According to the embodiment of the application, an embodiment of an image compression device is also provided. Figure 3 is a structural diagram of an image compression device provided by the embodiment of the application. As shown in Figure 3 , the device comprises:
[0125] The complexity determination module 30 is configured to obtain a first image, determine the number of edges in the first image, and determine the image complexity information of the first image according to the number of edges, wherein the edge is a boundary between different regions in the image;
[0126] The wavelet transform module 32 is configured to determine the decomposition layer number of wavelet transform according to the image complexity information, and perform multi-level wavelet transform on each channel component of the first image according to the decomposition layer number, to obtain the wavelet coefficients corresponding to the channel component;
[0127] The quantization compression module 34 is configured to perform quantization processing on the wavelet coefficients, wherein the quantization processing is used to reduce the data volume by reducing the precision of the wavelet coefficients.
[0128] The image reconstruction module 36 is configured to reconstruct the image according to the quantized wavelet coefficients to obtain the compressed first image.
[0129] Optionally, the obtaining the first image comprises: obtaining a second image to be compressed, wherein the second image is an image in a red, green, and blue (RGB) color space; and converting the second image from the RGB color space to a luminance and chrominance (YCbCr) color space to obtain the first image, wherein the first image comprises a luminance channel component, a blue chrominance channel component, and a red chrominance channel component.
[0130] Optionally, the determining the image complexity information of the first image according to the number of edges comprises: determining a target operator, wherein the target operator is configured to enhance the gray level transformation in the horizontal direction and / or the vertical direction of the image to detect the horizontal edges and the vertical edges in the image; performing a convolution operation on each pixel in the first image by using the target operator to obtain the edge intensity corresponding to each pixel; determining the positions of the pixels with the edge intensity exceeding a preset intensity threshold in the first image as significant edges, and counting the number of the significant edges to obtain the number of edges; and determining the proportion of the significant edges in the first image according to the number of edges, and determining the image complexity information of the first image according to the proportion.
[0131] Optionally, the performing the multi-level wavelet transform on each channel component of the first image according to the number of decomposition layers comprises: determining the number of decomposition layers according to the image complexity information of the luminance channel component of the first image and a preset proportion factor; and performing the wavelet transform on each channel component of the first image according to the number of decomposition layers to obtain the wavelet coefficients corresponding to each channel component, wherein the wavelet transform is configured to decompose the image into details in different scales and directions.
[0132] Optionally, the quantizing the wavelet coefficients comprises: dividing the wavelet coefficients by a quantization factor to obtain a target multiple; rounding the target multiple to obtain a target integer corresponding to the target multiple; and determining the product of the target integer and the quantization factor as the result of the quantization of the wavelet coefficients.
[0133] Optionally, the reconstructing the image according to the quantized wavelet coefficients to obtain the compressed first image comprises: performing an inverse wavelet transform on the quantized wavelet coefficients corresponding to each channel component to obtain image data corresponding to each channel component; performing cropping on the image data corresponding to each channel component according to the image size information of the first image; and merging the image data corresponding to each channel component after the cropping to obtain the compressed first image.
[0134] Optionally, after obtaining the compressed first image, the method further includes: converting the compressed first image from a YCbCr color space to an RGB color space to obtain a compressed second image.
[0135] It should be noted that each module in the image compression device described above can be a program module (for example, a program instruction set for implementing a certain specific function) or a hardware module. For the latter, it can be in the form of a processor, or the functions of the modules are implemented by a processor.
[0136] It should be noted that the image compression device provided in the embodiment can be used to execute the image compression method shown in the embodiment, and the related explanations of the image compression method are also applicable to the embodiments of the present application, and will not be described here. Figure 2
[0137] The embodiments of the present application also provide a non-volatile storage medium, which includes a stored computer program. A device in which the non-volatile storage medium is located executes the following image compression method by running the computer program: obtaining a first image, determining the number of edges in the first image, and determining image complexity information of the first image according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions; determining the decomposition layer number of wavelet transform according to the image complexity information, and performing multi-level wavelet transform on each channel component of the first image according to the decomposition layer number to obtain wavelet coefficients corresponding to the channel component; performing quantization processing on the wavelet coefficients, wherein the quantization processing is used to reduce the accuracy of the wavelet coefficients to reduce the data volume; and performing image reconstruction according to the wavelet coefficients after the quantization processing to obtain a compressed first image.
[0138] The embodiments of the present application also provide a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the image compression method described in the embodiments of the present application are implemented: obtaining a first image, determining the number of edges in the first image, and determining image complexity information of the first image according to the number of edges, wherein the edge is a place in the image that identifies the boundary between different regions; determining the decomposition layer number of wavelet transform according to the image complexity information, and performing multi-level wavelet transform on each channel component of the first image according to the decomposition layer number to obtain wavelet coefficients corresponding to the channel component; performing quantization processing on the wavelet coefficients, wherein the quantization processing is used to reduce the accuracy of the wavelet coefficients to reduce the data volume; and performing image reconstruction according to the wavelet coefficients after the quantization processing to obtain a compressed first image.
[0139] The above sequence numbers of the embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0140] In the above-described embodiments of the present application, the description of each embodiment focuses on different aspects, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0141] In several embodiments provided in the present application, it should be understood that the disclosed technical contents can be implemented by other ways. Among them, the above-described device embodiments are only schematic, for example, the division of the units can be a logical function division, and actual implementation can have another division way, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or modules shown or discussed can be indirect coupling or communication connection through some interfaces, units or modules, which can be electrical or other forms.
[0142] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, that is, they can be located in one place, or they can be distributed to multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0143] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The above integrated unit can be realized in the form of hardware or in the form of software functional unit.
[0144] The integrated unit, if realized in the form of software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the essential part or all or part of the technical solutions that make contributions to the prior art can be embodied in the form of software product, which is stored in a storage medium and includes a plurality of instructions to make a computer device (which can be a personal computer, a server or a network device, etc.) execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic or optical disk and various program code storage media.
[0145] The above merely describes the preferred embodiments of the present application, and it should be pointed out that, for those skilled in the art, some improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. An image compression method characterized by, include: Acquiring a first image and determining the number of edges in the first image, and determining the image complexity information of the first image based on the number of edges, includes: determining a target operator, wherein the target operator is used to enhance the grayscale transformation in the horizontal and / or vertical directions of the image to detect horizontal and vertical edges in the image; using the target operator to perform a convolution operation on each pixel in the first image to obtain the edge intensity corresponding to each pixel; determining the positions of pixels in the first image whose edge intensity exceeds a preset intensity threshold as salient edges, and counting the number of salient edges to obtain the number of edges; determining the proportion of salient edges in the first image based on the number of edges, and determining the image complexity information of the first image based on the proportion, wherein the edge is a place in the image that marks the boundary between different regions; Based on the image complexity information, the number of decomposition levels of the wavelet transform is determined, and multi-level wavelet transform is performed on each channel component of the first image according to the number of decomposition levels to obtain the wavelet coefficients corresponding to the channel components. The wavelet coefficients are quantized, wherein the quantization process is used to reduce the amount of data by reducing the precision of the wavelet coefficients; The image is reconstructed based on the wavelet coefficients after the quantization process to obtain the first image after compression.
2. The image compression method of claim 1, wherein, Obtaining the first image includes: Obtain the second image to be compressed, wherein the second image is an image in the RGB color space; The second image is converted from the RGB color space to the YCbCr color space to obtain the first image, wherein the first image includes: a luminance channel component, a blue color difference channel component, and a red color difference channel component.
3. The image compression method according to claim 1, characterized in that, Performing multi-level wavelet transform on each channel component of the first image according to the decomposition level, the wavelet coefficients corresponding to the channel components are obtained as follows: The number of decomposition layers is determined based on the image complexity information corresponding to the brightness channel components of the first image and a preset scaling factor. According to the decomposition level, wavelet transform is performed on each of the channel components of the first image to obtain the wavelet coefficients corresponding to each channel component. The wavelet transform is used to decompose the image into details of different scales and directions.
4. The image compression method according to claim 3, characterized in that, Quantization of the wavelet coefficients includes: Divide the wavelet coefficients by the quantization factor to obtain the target multiple; The target multiple is rounded to obtain the target integer corresponding to the target multiple. The product of the target integer and the quantization factor is determined as the result of the wavelet coefficients after quantization.
5. The image compression method according to claim 4, characterized in that, Based on the wavelet coefficients after quantization, image reconstruction is performed to obtain the compressed first image, which includes: Perform inverse wavelet transform on the wavelet coefficients of each channel component after quantization to obtain the image data corresponding to each channel component. Based on the image size information of the first image, the image data corresponding to the channel components are cropped, and the image data corresponding to each of the cropped channel components are merged to obtain the compressed first image.
6. The image compression method according to claim 5, characterized in that, After obtaining the compressed first image, the method further includes: The compressed first image is converted from the YCbCr color space to the RGB color space to obtain the compressed second image.
7. An image compression device, characterized in that, include: A complexity determination module is used to acquire a first image, determine the number of edges in the first image, and determine the image complexity information of the first image based on the number of edges. This includes: determining a target operator, wherein the target operator is used to enhance grayscale transformation in the horizontal and / or vertical directions of the image to detect horizontal and vertical edges in the image; using the target operator to perform a convolution operation on each pixel in the first image to obtain the edge intensity corresponding to each pixel; determining the positions of pixels in the first image whose edge intensity exceeds a preset intensity threshold as salient edges, and counting the number of salient edges to obtain the edge count; determining the proportion of salient edges in the first image based on the edge count, and determining the image complexity information of the first image based on the proportion, wherein the edge is a boundary in the image that marks the boundary between different regions. The wavelet transform module is used to determine the number of decomposition levels of the wavelet transform based on the image complexity information, and to perform multi-level wavelet transform on each channel component of the first image according to the number of decomposition levels to obtain the wavelet coefficients corresponding to the channel components. A quantization compression module is used to quantize the wavelet coefficients, wherein the quantization process is used to reduce the amount of data by reducing the precision of the wavelet coefficients; The image reconstruction module is used to reconstruct the image based on the wavelet coefficients after the quantization process, and obtain the compressed first image.
8. An electronic device, characterized in that, include: A memory and a processor, the processor being configured to run a program stored in the memory, wherein the program, when running, performs the image compression method according to any one of claims 1 to 6.
9. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored computer program, wherein the device containing the non-volatile storage medium executes the image compression method according to any one of claims 1 to 6 by running the computer program.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the image compression method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image compression method and device and electronic equipment
CN109996078A
Compressed sensing method for adaptive multi-scale block size of image
CN117478905A