[go: up one dir, main page]

CN117011396A - Image compression method, device, electronic equipment and storage medium - Google Patents

Image compression method, device, electronic equipment and storage medium Download PDF

Info

Publication number
CN117011396A
CN117011396A CN202211176241.2A CN202211176241A CN117011396A CN 117011396 A CN117011396 A CN 117011396A CN 202211176241 A CN202211176241 A CN 202211176241A CN 117011396 A CN117011396 A CN 117011396A
Authority
CN
China
Prior art keywords
image
compression
result
sub
image block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211176241.2A
Other languages
Chinese (zh)
Inventor
师洪亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202211176241.2A priority Critical patent/CN117011396A/en
Publication of CN117011396A publication Critical patent/CN117011396A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T9/00Image coding
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/25Determination of region of interest [ROI] or a volume of interest [VOI]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/20Image preprocessing
    • G06V10/26Segmentation of patterns in the image field; Cutting or merging of image elements to establish the pattern region, e.g. clustering-based techniques; Detection of occlusion

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The application discloses an image compression method, an image compression device, electronic equipment and a storage medium. The embodiment of the application can be applied to various scenes such as cloud technology, artificial intelligence, intelligent traffic, auxiliary driving and the like, and the method comprises the following steps: dividing the image to be compressed to obtain a first sub-image comprising the target object and a second sub-image not comprising the target object; compressing the first sub-image through a first compression quantization table, and compressing the second sub-image through a second compression quantization table to obtain a first compression result and a second compression result; and obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result. According to the method, low-loss or lossless compression of the first sub-image and high-loss compression of the second sub-image are realized, so that the obtained final compression result occupies less storage space, and meanwhile, the information of the target object can be well reserved, and the restored image quality is improved.

Description

Image compression method, device, electronic equipment and storage medium
Technical Field
The present application relates to the field of internet information processing technologies, and in particular, to an image compression method, an image compression device, an electronic device, and a storage medium.
Background
Image compression refers to a technique of representing an original image pixel matrix with a smaller number of bytes. In order to save the storage space of the image and improve the transmission efficiency of the image, the image needs to be compressed to obtain a compression result, and the compression result is decompressed to restore the image when the image is actually used or displayed.
Currently, in order to improve the transmission efficiency of an image, a compression process may be performed on an image to be compressed by using a higher compression ratio, so as to obtain a compression result. However, the compression result obtained in this way loses much information, resulting in a restored image according to the compression result losing much information, and thus resulting in a reduced image of poor quality.
Disclosure of Invention
In view of the above, the embodiments of the present application provide an image compression method, an image compression device, an electronic device, and a storage medium.
In a first aspect, an embodiment of the present application provides an image compression method, including: dividing the image to be compressed to obtain a first sub-image comprising the target object and a second sub-image not comprising the target object; compressing the first sub-image through a first compression quantization table to obtain a first compression result; compressing the second sub-image through a second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table; and obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
In a second aspect, an embodiment of the present application provides an image compression apparatus, including: the segmentation module is used for carrying out segmentation processing on the image to be compressed to obtain a first sub-image comprising the target object and a second sub-image not comprising the target object; the first compression module is used for compressing the first sub-image through the first compression quantization table to obtain a first compression result; the second compression module is used for carrying out compression processing on the second sub-image through a second compression quantization table to obtain a second compression result, and the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table; the result obtaining module is used for obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
Optionally, the segmentation module is further configured to perform target object detection on the image to be compressed to obtain a detection frame for selecting the target object; sampling the image to be compressed to obtain a sampled image; and determining a first sub-image and a second sub-image in the sampled image according to the detection frame.
Optionally, the segmentation module is further configured to segment the sampled image to obtain a plurality of image blocks with preset sizes; acquiring and summarizing an image block with an intersection with a detection frame as a first sub-image; and acquiring and summarizing the image blocks which do not have intersection with the detection frame as a second sub-image.
Optionally, the segmentation module is further configured to perform format conversion processing on the image to be compressed if the image to be compressed is not the image in the target format, so as to obtain a format converted image; and sampling the format conversion image to obtain a sampling image.
Optionally, the segmentation module is further configured to perform luminance full-sampling processing on the format conversion image to obtain a luminance sampling image; performing chroma downsampling processing on the format conversion image to obtain a chroma sampling image; and summarizing the brightness sampling image and the chromaticity sampling image to obtain a sampling image.
Optionally, the first sub-image includes a plurality of image blocks of a preset size; the first compression module is further used for calculating a difference value between a pixel value of each pixel point in each image block and a preset numerical value, and the difference value is used as an intermediate value of the pixel point; performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block; and compressing the discrete result of each image block through the first compression quantization table to obtain a first compression result.
Optionally, the discrete result of each image block includes a discrete value corresponding to each pixel point in the image block; the first compression module is further used for rounding the discrete value of each pixel point in each image block to obtain a rounding discrete result corresponding to each image block; compressing the rounded discrete result of each image block through a first compression quantization table to obtain an intermediate result corresponding to each image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each image block; and compressing the digital sequence of each image block to obtain a first compression result.
Optionally, the first compression module is further configured to determine a direct current coefficient and an alternating current coefficient from the digital sequence of each image block; carrying out compression coding on the direct current coefficients corresponding to the image blocks to obtain a direct current coding result; compression coding is carried out on the alternating current coefficient of each image block, and an alternating current coding result is obtained; and obtaining a first compression result according to the direct current coding result and the alternating current coding result.
Optionally, the plurality of image blocks are arranged in a target order; the first compression module is further used for acquiring a direct current coefficient of a first image block in the plurality of image blocks as a target value of the first image block; calculating the difference between the DC coefficient of each image block and the DC coefficient of the image block before the image block as the target value of the image block; and coding the target values of the image blocks by a variable length integer coding algorithm to obtain a direct current coding result.
Optionally, the first compression module is further configured to encode the ac coefficient of each image block by using a run-length encoding algorithm, so as to obtain an image block ac encoding result corresponding to each image block; and summarizing the image block alternating current coding results of each of the plurality of image blocks to obtain an alternating current coding result.
Optionally, the first compression module is further configured to encode the ac coefficient of each image block by using a run-length encoding algorithm, so as to obtain an intermediate encoding result corresponding to each image block; and coding the intermediate coding result of each image block through a variable length integer coding algorithm to obtain an image block alternating current coding result corresponding to each image block.
Optionally, the first compression module is further configured to perform huffman coding on the dc coding result to obtain a dc huffman coding table; carrying out Huffman coding on the alternating current coding result to obtain an alternating current Huffman coding table; and obtaining a first compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
In a third aspect, an embodiment of the present application provides an electronic device, including a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the methods described above.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium having program code stored therein, wherein the program code, when executed by a processor, performs the method described above.
In a fifth aspect, embodiments of the present application provide a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer readable storage medium and executes the computer instructions to cause the electronic device to perform the method described above.
According to the image compression method, the device, the electronic equipment and the storage medium, the first sub-image is compressed through the first compression quantization table to obtain the first compression result, the second sub-image is compressed through the second compression quantization table with the compression ratio larger than that of the first compression quantization table to obtain the second compression result, low-loss or lossless compression of the first sub-image including the target object is achieved, high-loss compression of the second sub-image not including the target object is achieved, the obtained final compression result occupies less storage space, meanwhile, information of the target object can be well reserved, and therefore when the image is restored according to the final compression result, the restored image retains more complete data information of the target object, and further the restored image quality is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic diagram of an application scenario shown according to an embodiment of the present application;
FIG. 2 is a flow chart illustrating an image compression method according to one embodiment of the present application;
FIG. 3 is a flow chart showing an image compression method according to still another embodiment of the present application;
FIG. 4 is a schematic diagram of a detection frame in an embodiment of the application;
FIG. 5 is a schematic diagram of different sampling formats in an embodiment of the present application;
FIG. 6 is a flow chart illustrating an image compression method according to still another embodiment of the present application;
fig. 7 is a flowchart of an image compression method according to still another embodiment of the present application;
fig. 8 is a flowchart illustrating an image compression method according to still another embodiment of the present application;
FIG. 9 is a schematic diagram of an image to be compressed in accordance with an embodiment of the present application;
fig. 10 is a flowchart showing a compression process of an image to be compressed in the embodiment of the present application;
FIG. 11 is a schematic diagram showing decompression results corresponding to the image to be compressed in FIG. 9;
fig. 12 is a block diagram showing an image compression apparatus according to an embodiment of the present application;
fig. 13 shows a block diagram of an electronic device for performing an image compression method according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the application, are within the scope of the application in accordance with embodiments of the present application.
In the following description, the terms "first", "second", and the like are merely used to distinguish between similar objects and do not represent a particular ordering of the objects, it being understood that the "first", "second", or the like may be interchanged with one another, if permitted, to enable embodiments of the application described herein to be practiced otherwise than as illustrated or described herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
It should be noted that: references herein to "a plurality" means two or more. "and/or" describes an association relationship of an association object, meaning that there may be three relationships, e.g., a and/or B may represent: a exists alone, A and B exist together, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.
Cloud technology (Cloud technology) refers to a hosting technology for integrating hardware, software, network and other series resources in a wide area network or a local area network to realize calculation, storage, processing and sharing of data.
Cloud technology (Cloud technology) is based on the general terms of network technology, information technology, integration technology, management platform technology, application technology and the like applied by Cloud computing business models, and can form a resource pool, so that the Cloud computing business model is flexible and convenient as required. Cloud computing technology will become an important support. Background services of technical networking systems require a large amount of computing, storage resources, such as video websites, picture-like websites, and more portals. Along with the high development and application of the internet industry, each article possibly has an own identification mark in the future, the identification mark needs to be transmitted to a background system for logic processing, data with different levels can be processed separately, and various industry data needs strong system rear shield support and can be realized only through cloud computing.
Cloud storage (cloud storage) is a new concept that extends and develops in the concept of cloud computing, and a distributed cloud storage system (hereinafter referred to as a storage system for short) refers to a storage system that integrates a large number of storage devices (storage devices are also referred to as storage nodes) of various types in a network to work cooperatively through application software or application interfaces through functions such as cluster application, grid technology, and a distributed storage file system, so as to provide data storage and service access functions for the outside.
At present, the storage method of the storage system is as follows: when creating logical volumes, each logical volume is allocated a physical storage space, which may be a disk composition of a certain storage device or of several storage devices. The client stores data on a certain logical volume, that is, the data is stored on a file system, the file system divides the data into a plurality of parts, each part is an object, the object not only contains the data but also contains additional information such as a data Identification (ID) and the like, the file system writes each object into a physical storage space of the logical volume, and the file system records storage position information of each object, so that when the client requests to access the data, the file system can enable the client to access the data according to the storage position information of each object.
The process of allocating physical storage space for the logical volume by the storage system specifically includes: physical storage space is divided into stripes in advance according to the set of capacity measures for objects stored on a logical volume (which measures tend to have a large margin with respect to the capacity of the object actually to be stored) and redundant array of independent disks (RAID, redundant Array of Independent Disk), and a logical volume can be understood as a stripe, whereby physical storage space is allocated for the logical volume.
Fig. 1 is a schematic diagram of an application scenario shown according to an embodiment of the present application. As shown in fig. 1, the application scenario includes a terminal 101 and a server 102, where the terminal 101 and the server 102 are communicatively connected through a wired network or a wireless network.
The terminal 101 may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart home appliance, a vehicle-mounted terminal, an aircraft, a wearable device terminal, a virtual reality device, a smart camera, and other terminal devices capable of displaying pages, or running other applications (e.g., an instant messaging application, a shopping application, a search application, a game application, a forum application, a map traffic application, etc.) capable of calling a page display application.
The server 102 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs (Content Delivery Network, content delivery networks), basic cloud computing services such as big data and artificial intelligent platforms, and the like. The server 102 may be configured to provide services for applications running on the terminal 101.
The terminal 101 may obtain an image to be compressed through an internal or external camera, perform the image compression method of the present application on the image to be compressed to obtain a final compression result, send the final compression result to the server 102, and decompress the final compression result by the server 102 to obtain a decompressed result, so as to obtain the required information through the decompressed result obtained by the server 102.
Referring to fig. 2, fig. 2 is a flowchart of an image compression method according to an embodiment of the present application, where the method may be applied to an electronic device, and the electronic device may be the terminal 101 in fig. 1, and the method includes:
s110, dividing the image to be compressed to obtain a first sub-image including the target object and a second sub-image not including the target object.
The image to be compressed in the application can be an image which needs to be compressed, can be an image acquired by the electronic equipment in real time, and can also be an image acquired by the electronic equipment from other equipment. For example, when the electronic device is an electronic eye of a highway, the electronic eye acquires a video stream in real time, and takes each frame of the video stream as an image to be compressed; for another example, when the electronic device is a personal computer, the electronic device obtains an image captured by the camera (a camera built in the electronic device or an externally hung camera) as an image to be compressed.
The target object may refer to a person, a vehicle, a house, or the like, for example, when the electronic device is an electronic eye, the target object may be a vehicle, and when the electronic device is a personal computer, the target object may be a person, a house, or the like. The user can determine the target object based on the requirements and the actual application scene.
The segmentation process may refer to the segmentation of the image to be compressed into a first sub-image comprising the target object and a second sub-image not comprising the target object. For example, the target object is a vehicle, the region including the vehicle in the image to be compressed is used as a first sub-image, and the region not including the target object in the image to be compressed is used as a second sub-image.
As an implementation manner, the image to be compressed may be segmented by a semantic segmentation model to obtain the first sub-image and the second sub-image, the semantic segmentation model may be obtained by training a neural network model according to a sample image including the target object, and the semantic segmentation model may also be a general model such as DeeLab V3, FCN, UNet, segNet, and the like.
As another embodiment, the image to be compressed may be processed by the target object detection model corresponding to the target object, so as to obtain a detection frame output by the target object detection model, wherein an area inside the detection frame of the image to be compressed is used as a first sub-image, and an area outside the detection frame of the image to be compressed is used as a second sub-image.
S120, compressing the first sub-image through the first compression quantization table to obtain a first compression result.
S130, performing compression processing on the second sub-image through a second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table.
The compression quantization table may refer to a matrix for performing compression processing on an image, and the first compression quantization table and the second compression quantization table may be determined by a user from a plurality of compression quantization tables defined by an algorithm according to requirements, where the compression quantization tables defined by the algorithm may be preset compression quantization tables in editing software such as PhotoShop.
The compression ratio refers to the ratio of the file size before compression to the file size after compression, for example, the file size before compression is 100M, and the file size after compression is 10M, and the compression ratio is 100/10=10.
And the first sub-image is compressed through the first compression quantization table to obtain a compressed first compression result, the second sub-image is compressed through the second compression quantization table to obtain a second compression result, and the low-loss or lossless compression of the first sub-image is realized and the high-loss compression of the second sub-image is realized because the compression ratio corresponding to the first compression quantization table is smaller than the compression ratio corresponding to the second compression quantization table, so that the data volume of the second compression result corresponding to the second sub-image is greatly reduced.
As an embodiment, the first sub-image may be divided into small blocks matched with the first compression quantization table, each small block is compressed by the first compression quantization table, and all the small blocks are traversed to obtain the first compression result, where the small block matched with the first compression quantization table is the same size as the first compression quantization table, for example, the first compression quantization table is a matrix of 8×8, and the small block matched with the first compression quantization table is also 8×8 (the product of the number of pixels in the width direction and the number of pixels in the height direction).
Similarly, the second sub-image may be divided into small blocks matched with the second compression quantization table, each small block is compressed by the second compression quantization table, and all the small blocks are traversed to obtain the second compression result, where the small blocks matched with the second compression quantization table are the same size as the second compression quantization table, for example, the second compression quantization table is a matrix of 4×4, and the small blocks matched with the second compression quantization table are also of 4×4 (the product of the number of pixels in the width direction and the number of pixels in the height direction).
When the first sub-image is an RGB format image, the first compression quantization table may include a first compression quantization table corresponding to an R pixel, a G pixel, and a B pixel, respectively, the pixel values of the R pixel of the first sub-image may be compressed by the first compression quantization table corresponding to the R pixel to obtain an R pixel compression result, the pixel values of the G pixel of the first sub-image may be compressed by the first compression quantization table corresponding to the G pixel to obtain a G pixel compression result, the pixel values of the B pixel of the first sub-image may be compressed by the first compression quantization table corresponding to the B pixel to obtain a B pixel compression result, and the R pixel compression result, the G pixel compression result, and the B pixel compression result may be summarized to obtain a first compression result.
Similarly, when the second sub-image is an RGB format image, the second compression quantization table may include a second compression quantization table corresponding to an R pixel, a G pixel, and a B pixel, and the pixel values of the R pixel of the second sub-image may be compressed by the second compression quantization table corresponding to the R pixel to obtain an R pixel compression result, the pixel values of the G pixel of the second sub-image may be compressed by the second compression quantization table corresponding to the G pixel to obtain a G pixel compression result, and the pixel values of the B pixel of the second sub-image may be compressed by the second compression quantization table corresponding to the B pixel to obtain a B pixel compression result, and the R pixel compression result, the G pixel compression result, and the B pixel compression result may be summarized to obtain a second compression result.
When the first sub-image is an image in YUV format, the first compression quantization table may include a first compression quantization table corresponding to a luminance component (Y component) image and a chrominance component (UV component) image, the luminance component image of the first sub-image may be compressed by the first compression quantization table corresponding to the luminance component image to obtain a luminance component compression result, the chrominance component image of the first sub-image may be compressed by the first compression quantization table corresponding to the chrominance component image to obtain a chrominance component compression result, and the luminance component compression result and the chrominance component compression result may be summarized to obtain the first compression result.
In the present embodiment, the first compression quantization table Q of the luminance component image in the first compression quantization table Y First compression quantization table Q of chrominance component image C The following may be possible:
similarly, when the second sub-image is an image in YUV format, the second compression quantization table may include a second compression quantization table corresponding to the luminance component (Y component) image and the chrominance component (UV component) image, and the luminance component image of the second sub-image may be compressed by the second compression quantization table corresponding to the luminance component image to obtain a luminance component compression result, and the chrominance component image of the second sub-image may be compressed by the second compression quantization table corresponding to the chrominance component image to obtain a chrominance component compression result, and the luminance component compression result and the chrominance component compression result may be summarized to obtain a second compression result.
And S140, obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
After the first compression result and the second compression result are obtained, the first compression result and the second compression result are summarized, and a final compression result is obtained.
When the image to be compressed comprises a plurality of images, an image identifier can be corresponding to each image to be compressed, and the final compression result corresponding to the image to be compressed can be identified through the image identifier so as to distinguish the final compression results corresponding to the plurality of images to be compressed. The image identifier may be information such as an image number.
The obtained first compression result and second compression result may refer to compressed data, which is not an image, but is in the form of data, and the final compression result corresponding to the first compression result and the second compression result may be sent to the server, so that the server decompresses the final compression result to obtain a decompression result, where the decompression result may refer to a compressed image corresponding to the image to be compressed. The decompression may be performed by reversing the final compression result according to the method of the present application, to obtain a recovered decompression result.
In this embodiment, the first sub-image is compressed by the first compression quantization table to obtain a first compression result, and the second sub-image is compressed by the second compression quantization table with a compression ratio greater than that of the first compression quantization table to obtain a second compression result, so that low-loss or lossless compression of the first sub-image including the target object is realized, and high-loss compression of the second sub-image not including the target object is realized, so that the obtained final compression result occupies less storage space, and meanwhile, the information of the target object can be better retained, so that when the image is restored according to the final compression result, the restored image retains the more complete data information of the target object, and further the restored image quality is improved.
Referring to fig. 3, fig. 3 is a flowchart illustrating an image compression method according to another embodiment of the present application, where the method may be applied to an electronic device, and the electronic device may be the terminal 101 in fig. 1, and the method includes:
s210, detecting a target object of the image to be compressed to obtain a detection frame for selecting the target object.
The image to be compressed can be processed through the target object detection model corresponding to the target object to obtain a detection frame output by the target object detection model, and the region selected by the detection frame is also called an ROI (region of interest ). As shown in fig. 4, when the target object is a vehicle, the output detection frame selects the vehicle.
The target object detection model may be a YOLOX model, which is an improvement of the YOLO model, and uses an anchor-free characteristic, both the detection effect and the inference speed are high.
Currently, the sliding window method of image object detection is simple and easy to understand, but the window changing with the object size performs global searching from left to right and from top to bottom on the image, which results in low efficiency. In order to increase the search speed on the basis of a sliding window detector, a selective search method (selective search method) is proposed, the main idea of which is that regions in an image where targets exist have similarity and continuity, and extraction of candidate regions is performed in a sub-region merging manner based on this idea to determine targets. Then, a region-based convolutional neural network (region-based convolutional neural network, R-CNN) is proposed to extract candidate regions by adopting a selective search method, so that more and more students propose new detection models on the basis of continuously improving a method for determining targets.
The detection precision and the detection speed are important standards for judging whether the image target detection model is good or bad. The image target detection model based on the candidate region, although being first-qualified in terms of detection accuracy, has the main disadvantage of low image detection efficiency. In order to solve the defect, a YOLO (you only look once) detection model is provided, the model abstracts image target detection into regression problem, and the bounding box and the category of the target of interest are directly predicted through one-time detection of the complete picture, so that the troublesome operation of dividing the detection task into two steps in the R-CNN series is avoided, and the problem of low detection efficiency of the previous image target detection model is solved. The detection network divides the input picture into s multiplied by s grids, each grid is only responsible for the target of the grid where the detection center falls, category information of the grid and confidence degrees of a plurality of boundary boxes and each boundary box are predicted, boundary boxes with lower confidence degrees are filtered through setting a threshold value, and then NMS processing is carried out on the reserved boundary boxes to determine a final detection result. YOLO replaces the candidate region method of the previous image target detection model with regression, and the detection speed reaches 45f/s on the basis of meeting the real-time requirement.
However, the detection capability is still limited because YOLO only selects the bounding box with the highest confidence as the final output in the detection process, i.e. only one object is detected at most by each grid. The problem is not solved, and a method for dynamically selecting a feature layer based on an anchor-free is provided, which mainly builds an FSAF (feature selective anchor-free) module on the basis of Retinonet, namely builds an anchor-free branch which can allocate a target to a proper characteristic level for each level of features, so that a target frame can perform encoding and decoding operations on any feature layer through the anchor-free branch. The FSAF can output the prediction result in parallel with the parallel operation of the branch based on the anchor, so that the robustness of RetinaNet is effectively improved, and the limitation of selecting a feature layer according to a candidate frame in the traditional network based on anchor frame detection is solved.
It should be noted that, the target object detection model may be specific to an image to be compressed in RGB format, if the image to be compressed is not an image in RGB format, the image to be compressed may be converted into an image in RGB format, and then the converted result is input into the target object detection model to obtain the detection frame.
S220, sampling the image to be compressed to obtain a sampled image.
The sampling of the image to be compressed may mean that, when the image to be compressed is an image in a target format, the image to be compressed is subjected to luminance sampling and chrominance sampling to obtain a luminance sampling image and a chrominance sampling image, and the luminance sampling image and the chrominance sampling image are summarized to obtain a sampling image, that is, the sampling image includes the luminance sampling image and the chrominance sampling image. The target format may refer to a YUV format, the image in the target format generally refers to an image in a JPEG format, JPEG (Joint Photographic Experts Group) refers to a joint photographic experts group, and various multimedia compression transmission standards are formulated. The JPEG in the application refers to an image compression algorithm proposed by the expert group.
Sampling the image to be compressed may also mean that if the image to be compressed is not an image in the target format, format conversion processing is performed on the image to be compressed to obtain a format conversion image; and sampling the format conversion image to obtain a sampling image. The format conversion image is an image in a YUV format, and the sampling processing of the format conversion image may refer to performing luminance sampling and chrominance sampling on the format conversion image to obtain a luminance sampling image and a chrominance sampling image, and summarizing the luminance sampling image and the chrominance sampling image to obtain a sampling image.
As one embodiment, the brightness of the format conversion image is fully sampled to obtain a brightness sampling image; performing chroma downsampling processing on the format conversion image to obtain a chroma sampling image; and summarizing the brightness sampling image and the chromaticity sampling image to obtain a sampling image.
Since the human eye is more sensitive to the luminance signal (Y) than to the chrominance signal (UV), the luminance signal is fully sampled, the chrominance signal is downsampled, and the resulting effect on the human eye is small, and data compression is achieved by downsampling the chrominance signal.
Y in the usual sampling format: u: v is 4:4:4, 4:2:2, or 4:2:0, wherein Y: u: v is Y, U for 4:4:4 samples and V is all samples, as indicated by a in FIG. 5, each pixel samples Y, U and V, where solid dots refer to sampling Y and hollow dots refer to sampling UV; y: u: v is 4:2:2 is downsampling, the UV sampling ratio is 1/2 of Y, as shown in b in FIG. 5, each pixel samples Y, every other pixel, and UV is sampled; y: u: v is 4:2:0 is downsampling, the UV sampling ratio is 1/4 of Y, and as shown in c in FIG. 5, each pixel samples Y, and the average UV value of every four pixels is taken as a UV sampling value. Note that Y: u: v is 4:2:0, and instead of V not sampling, UV alternately samples.
S230, determining a first sub-image and a second sub-image in the sampling image according to the detection frame.
In this embodiment, the sampling image includes a luminance sampling image and a chrominance sampling image, the first sub-image includes a first luminance sub-image and a first chrominance sub-image, and the second sub-image includes a second luminance sub-image and a second chrominance sub-image. Determining a first brightness sub-image and a second brightness sub-image in the brightness sampling image according to the detection frame; according to the detection frame, a first chrominance sub-image and a second chrominance sub-image are determined in the chrominance sample image.
As an embodiment, S230 may include: dividing the sampled image to obtain a plurality of image blocks with preset sizes; acquiring and summarizing an image block with an intersection with a detection frame as a first sub-image; and acquiring and summarizing the image blocks which do not have intersection with the detection frame as a second sub-image. The preset size may be a size matching the compression quantization table, for example, the first compression quantization table and the second compression quantization table are each an 8×8 matrix, and the preset size is 8×8.
The sampled image comprises a luminance sampled image and a chrominance sampled image, the first sub-image comprises a first luminance sub-image and a first chrominance sub-image, and the second sub-image comprises a second luminance sub-image and a second chrominance sub-image.
Dividing the brightness sampling image to obtain a plurality of image blocks with preset sizes, taking the image blocks as a plurality of brightness image blocks, and acquiring and summarizing the brightness image blocks with intersections with the detection frame to be taken as a first brightness sub-image; and acquiring and summarizing the brightness image blocks which do not have intersection with the detection frame as a second brightness sub-image.
Dividing the chroma sampling image to obtain a plurality of image blocks with preset sizes, taking the image blocks as a plurality of chroma image blocks, and acquiring and summarizing the chroma image blocks with intersections with the detection frame as a first chroma sub-image; and acquiring and summarizing the chrominance image blocks which do not have intersection with the detection frame as a second chrominance sub-image.
S240, compressing the first sub-image through a first compression quantization table to obtain a first compression result; and carrying out compression processing on the second sub-image through a second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table.
In this embodiment, the first sub-image includes a first luminance sub-image and a first chrominance sub-image, and compression processing is performed on a plurality of luminance image blocks in the first luminance sub-image through a first compression quantization table to obtain compression results corresponding to each luminance image block in the first luminance sub-image, and the compression results corresponding to each luminance image block in the first luminance sub-image are summarized to obtain a first luminance compression result; compressing a plurality of color image blocks in a first color sub-image through a first compression quantization table to obtain compression results corresponding to each color image block in the first color sub-image, and summarizing the compression results corresponding to each color image block in the first color sub-image to obtain a first color compression result; and then summarizing the first brightness compression result and the first color compression result to obtain a first compression result.
Similarly, the second sub-image comprises a second brightness sub-image and a second chromaticity sub-image, a plurality of brightness image blocks in the second brightness sub-image are compressed through a second compression quantization table to obtain compression results corresponding to the brightness image blocks in the second brightness sub-image, and the compression results corresponding to the brightness image blocks in the second brightness sub-image are summarized to obtain a second brightness compression result; compressing a plurality of chromaticity image blocks in a second chromaticity sub-image through a second compression quantization table to obtain respective compression results of the chromaticity image blocks in the second chromaticity sub-image, and summarizing the respective compression results of the chromaticity image blocks in the second chromaticity sub-image to obtain a second chromaticity compression result; and then summarizing the second brightness compression result and the second chromaticity compression result to obtain a second compression result.
S250, obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
The description of S250 refers to the description of S140 above, and will not be repeated.
In this embodiment, the target object is detected on the image to be compressed, so that a detection frame with higher accuracy can be determined, so that the accuracy of the first sub-image corresponding to the ROI determined according to the detection frame is higher. Meanwhile, the image to be compressed is sampled and processed to obtain a sampled image, so that the data compression of the image to be compressed is realized, and the occupied storage space and bandwidth of a final compression result are reduced.
Referring to fig. 6, fig. 6 shows a flowchart of an image compression method according to still another embodiment of the present application, where the method may be applied to an electronic device, and the electronic device may be the terminal 101 in fig. 1, and the method includes:
s301, dividing the image to be compressed to obtain a first sub-image including the target object and a second sub-image not including the target object.
The description of S301 refers to the description of S101 above, and will not be repeated here.
S302, calculating the difference value between the pixel value of each pixel point in each image block and a preset numerical value to serve as the intermediate value of the pixel point.
In this embodiment, the first sub-image includes a first luminance sub-image and a first chrominance sub-image, and the first luminance sub-image and the first chrominance sub-image each include a plurality of image blocks of a preset size.
For each image block (also called a brightness image block) corresponding to the first brightness sub-image, taking the difference value between the pixel value of each pixel point in the image block and a preset numerical value as the intermediate value of the pixel point; and aiming at each image block corresponding to the first chrominance sub-image, taking the difference value between the pixel value of each pixel point in the image block and a preset numerical value as the intermediate value of the pixel point. Wherein the predetermined value may be 128.
For example, each luminance image block in the first luminance sub-image has a size of 8×8, and pixel values in one luminance image block are as follows:
taking the difference value between the pixel value of each pixel point in the brightness image block and the preset value as the intermediate value of the pixel point, and obtaining the corresponding result of the brightness image block as follows:
s303, performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block.
For each brightness image block corresponding to the first brightness sub-image, performing discrete cosine transform processing on the intermediate value of each pixel point in the brightness image block to obtain a discrete result of the pixel point, and summarizing the discrete results of each pixel point in the brightness image block to obtain a discrete result of the brightness image block; and aiming at each chromaticity image block corresponding to the first chromaticity sub-image, performing discrete cosine transform processing on the intermediate value of each pixel point in the chromaticity image block to obtain a discrete result of the pixel point, and summarizing the discrete results of each pixel point in the chromaticity image block to obtain the discrete result of the chromaticity image block.
The discrete cosine transform process can refer to the following formula:
Wherein F (u, v) is the discrete result of the pixel point (u, v), u is the abscissa of the pixel point, v is the ordinate of the pixel point, N is the side length of the preset size, for example, the preset size is 8×8, N is 8, and the output 8×8 matrix F is the discrete result of the image block.
For example, the intermediate value of each pixel point in one of the luminance image blocks in the first luminance sub-image is as follows:
discrete cosine transform processing is carried out on the obtained product, and the obtained result is as follows:
s304, compressing the discrete result of each image block through a first compression quantization table to obtain a first compression result.
The first sub-image comprises a first brightness sub-image and a first color sub-image, discrete results of a plurality of brightness image blocks in the first brightness sub-image are compressed through a first compression quantization table to obtain compression results corresponding to each brightness image block in the first brightness sub-image, and the compression results corresponding to each brightness image block in the first brightness sub-image are summarized to obtain a first brightness compression result; compressing a plurality of chromaticity image blocks in a first chromaticity sub-image through a first compression quantization table to obtain compression results corresponding to each chromaticity image block in the first chromaticity sub-image, and summarizing the compression results corresponding to each chromaticity image block in the first chromaticity sub-image to obtain a first chromaticity compression result; and then summarizing the first brightness compression result and the first color compression result to obtain a first compression result.
As one embodiment, the discrete result of each image block includes a discrete value corresponding to each pixel point in the image block; s304 may include: rounding the discrete value of each pixel point in each image block to obtain a rounding discrete result corresponding to each image block; compressing the rounded discrete result of each image block through a first compression quantization table to obtain an intermediate result corresponding to each image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each image block; and compressing the digital sequence of each image block to obtain a first compression result. The preset scan ordering algorithm may be a Zigzag scan ordering algorithm.
For the first brightness sub-image, rounding the discrete value of each pixel point in each brightness image block included in the first brightness sub-image to obtain a rounding discrete result corresponding to each brightness image block; compressing the rounded discrete result of each brightness image block through a first compression quantization table to obtain an intermediate result corresponding to each brightness image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each brightness image block; and compressing the digital sequence of each brightness image block to obtain a first brightness compression result.
For a first chromaticity sub-image, rounding the discrete value of each pixel point in each chromaticity image block included in the first chromaticity sub-image to obtain a rounding discrete result corresponding to each chromaticity image block; compressing the rounded discrete result of each chromaticity image block through a first compression quantization table to obtain an intermediate result corresponding to each chromaticity image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each chromaticity image block; and compressing the digital sequence of each chromaticity image block to obtain a first chromaticity compression result. And then summarizing the first brightness compression result and the first chrominance compression result to obtain a first compression result.
Compressing the rounded discrete result of each image block through the first compression quantization table may mean that each rounded discrete result of each image block is made a quotient with a value corresponding to the rounded discrete result in the first compression quantization table, and the quotient is rounded down to obtain an intermediate result of the rounded discrete result, and the intermediate results of the rounded discrete results in the image block are summarized to obtain an intermediate result of the image block.
For example, the discrete result for one of the luminance image blocks in the first luminance sub-image is as follows:
and rounding down the discrete result of the brightness image block to obtain a rounded discrete result of the brightness image block as follows:
the first compression quantization table corresponding to the luminance image block is as follows:
compressing the rounded discrete result of the brightness image block through the first compression quantization table, and obtaining the intermediate result of the brightness image block as follows:
scanning and sorting the intermediate result of the brightness image block by using a Zigzag scanning and sorting algorithm to obtain a digital sequence, the number sequences are-26, 3, 0, -3, -2, -6, 2, -4, 1, -3, 1, 5 1, 2, -1, -1, 2, 0, -1, 0 1, 2, -1, -1, 2, 0 0, -1, 0.
S305, performing compression processing on the second sub-image through the second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than the compression ratio corresponding to the second compression quantization table.
S306, obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
The descriptions of S350 and S360 refer to the descriptions of S103 and S104 above, and are not repeated here.
In this embodiment, the pixel value is encoded through discrete cosine change processing, the discrete result after the discrete cosine change processing is rounded, and the rounded discrete result after the rounding is compressed through the first compression quantization table, so as to obtain an intermediate result, thereby realizing the compression of the pixel value, reducing the data volume of the intermediate result, reducing the data volume of the first compression result obtained according to the intermediate result, and improving the data compression effect.
Referring to fig. 7, fig. 7 shows a flowchart of an image compression method according to still another embodiment of the present application, where the method may be applied to an electronic device, and the electronic device may be the terminal 101 in fig. 1, and the method includes:
s401, dividing the image to be compressed to obtain a first sub-image including the target object and a second sub-image not including the target object.
S402, calculating a difference value between a pixel value of each pixel point in each image block and a preset numerical value to serve as an intermediate value of the pixel point.
S403, performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block.
S404, rounding the discrete value of each pixel point in each image block to obtain a rounding discrete result corresponding to each image block; compressing the rounded discrete result of each image block through a first compression quantization table to obtain an intermediate result corresponding to each image block; and carrying out scanning sequencing on each number in each intermediate result through a preset scanning sequencing algorithm to obtain a number sequence corresponding to each image block.
The descriptions of S401 to S404 refer to the descriptions of S301 to S304 above, and are not repeated here.
S405, determining a direct current coefficient and an alternating current coefficient from the digital sequence of each image block.
The first digit in the sequence of digits of an image block (luminance image block or chrominance image block) may be referred to as the Direct Current (DC) Direct Current coefficient, and the other digits as alternating Current (Alternating Current, AC) coefficients.
S406, performing compression coding on the direct current coefficients corresponding to the image blocks to obtain a direct current coding result.
And aiming at each first sub-image, including a first brightness sub-image and a first chromaticity sub-image, performing compression coding on the direct current coefficients corresponding to a plurality of brightness image blocks in the first brightness sub-image to obtain a brightness direct current coding result, performing compression coding on the direct current coefficients corresponding to a plurality of chromaticity image blocks in the first chromaticity sub-image to obtain a chromaticity direct current coding result, and summarizing the brightness direct current coding result and the chromaticity direct current coding result to obtain a direct current coding result.
As an embodiment, the plurality of image blocks are arranged in the target order, S406 may include: acquiring a direct current coefficient of a first image block in a plurality of image blocks as a target value of the first image block; calculating the difference between the DC coefficient of each image block and the DC coefficient of the image block before the image block as the target value of the image block; and coding the target values of the image blocks by a variable length integer coding algorithm to obtain a direct current coding result.
The target sequence may refer to a left-to-right sequential arrangement of positions of each image block of each row in the first sub-image, and a top-to-bottom sequential arrangement of image blocks of multiple rows, that is, for the first luminance sub-image, the target sequence is a left-to-right sequential arrangement of positions of each image block of each row in the first luminance sub-image, and a top-to-bottom sequential arrangement of image blocks of multiple rows; for the first chrominance sub-image, the target sequence is that the positions of each chrominance image block of each row in the first chrominance sub-image are arranged in sequence from left to right, and the chrominance image blocks of a plurality of rows are arranged in sequence from top to bottom.
For example, the first luminance sub-image includes 7 luminance image blocks divided into 3 rows in total, the target order is that each row is arranged from top to bottom, the plurality of luminance image blocks in each row are arranged from left to right, the four luminance image blocks of the first row are respectively a first luminance image block, a second luminance image block, a third luminance image block and a fourth luminance image block, and the three luminance image blocks of the second row are respectively a fifth luminance image block, a sixth luminance image block and a seventh luminance image block.
Each image block in each first brightness sub-image is a brightness image block, and the direct current coefficient of the first brightness image block is obtained from a plurality of brightness image blocks and used as the target value of the first brightness image block; calculating the difference between the brightness image block and the direct current coefficient of the brightness image block before the brightness image block as the target value of the brightness image block; and coding the target values of the multiple brightness image blocks through a variable length integer coding algorithm to obtain a brightness direct current coding result.
Similarly, each image block in each first chrominance sub-image is a chrominance image block, and the direct current coefficient of the first chrominance image block is obtained from a plurality of chrominance image blocks and is used as a target value of the first chrominance image block; calculating the difference between the direct current coefficients of the chrominance image block and the previous chrominance image block of the chrominance image block as a target value of the chrominance image block; and coding the target values of the image blocks of each chromaticity by a variable length integer coding algorithm to obtain a chromaticity direct current coding result.
In the present embodiment, a coding table (VLI) of a variable length integer coding algorithm refers to table 1, and table 1 is as follows:
TABLE 1
The order of the numbers in the actual stored values is also 0, for example, the actual stored value corresponding to the number 2 of the group 2 is 10, and is indicated as (3).
For example, if the dc coefficient of a certain 8×8 luminance block is 15 and the dc coefficient of the previous 8×8 luminance block is 12, the difference between the two is 3, and by looking up the VLI, it can be found that the integer 3 is located in the 2 nd group of the VLI table, and thus, the form of (2) (3) can be written, and the form of the dc encoding result can also be called as an intermediate format of the dc coefficient.
S407, performing compression coding on the alternating current coefficient of each image block to obtain an alternating current coding result.
And aiming at a plurality of alternating coefficients of each image block, carrying out compression coding on the alternating coefficients to obtain an alternating coding result of the image block, traversing all the image blocks, and obtaining an alternating coding result of the first sub-image.
For each first sub-image comprising a first brightness sub-image and a first chrominance sub-image, carrying out compression coding on alternating current coefficients corresponding to a plurality of brightness image blocks in the first brightness sub-image to obtain an alternating current coding result, carrying out compression coding on alternating current coefficients corresponding to a plurality of chrominance image blocks in the first chrominance sub-image to obtain a chrominance alternating current coding result, and summarizing the brightness alternating current coding result and the chrominance alternating current coding result to obtain an alternating current coding result.
As an embodiment, S407 may include: coding the alternating current coefficient of each image block through a run coding algorithm to obtain an image block alternating current coding result corresponding to each image block; and summarizing the image block alternating current coding results of each of the plurality of image blocks to obtain an alternating current coding result. The coding method comprises the steps of coding alternating current coefficients of each image block through a run coding algorithm to obtain an image block alternating current coding result corresponding to each image block, wherein the method comprises the following steps: coding the alternating current coefficient of each image block through a run coding algorithm to obtain an intermediate coding result corresponding to each image block; and coding the intermediate coding result of each image block through a variable length integer coding algorithm to obtain an image block alternating current coding result corresponding to each image block.
Each image block in each first brightness sub-image is a brightness image block, and alternating current coefficients of each brightness image block are coded through a journey coding algorithm to obtain an intermediate coding result corresponding to each brightness image block; coding the intermediate coding result of each brightness image block through a variable length integer coding algorithm to obtain a brightness image block alternating current coding result corresponding to each brightness image block; and summarizing the brightness image block alternating current coding results of each of the plurality of brightness image blocks in the first brightness sub-image to obtain brightness alternating current coding results.
Similarly, each image block in each first chrominance sub-image is a chrominance image block, and alternating current coefficients of each chrominance image block are encoded through a run-length encoding algorithm to obtain an intermediate encoding result corresponding to each chrominance image block; coding the intermediate coding result of each chromaticity image block through a variable length integer coding algorithm to obtain a chromaticity image block alternating current coding result corresponding to each chromaticity image block; and summarizing the chroma image block alternating current coding results of each of the plurality of chroma image blocks in the first chroma sub-image to obtain a chroma alternating current coding result.
The ac coefficient of each image block (luminance image block or chrominance image block) contains a number of coefficients with 0 values, and by means of run-length encoding (Run Length Coding, RLC), consecutive characters repeated in a string can be replaced by two bytes constituting a data pair (M, N), where M is the number of consecutive 0's between two non-zero ac coefficients (M is also called run-length), and N is the value of the next non-zero ac coefficient.
For example, according to a number sequence of an image block, the determined ac coefficient is determined as the following character string: 57,45,0,0,0,0,23,0, -30, -8,0,0,1,000..after RLC treatment, the following forms will be presented: (0,57); (0, 45); (4, 23); (1, -30); (0, -8); (2, 1); (0,0). Note that if the number of consecutive 0 s between the dc coefficients exceeds 16, 16 consecutive 0 s are represented by one extension byte (15, 0).
After the alternating current coefficient of each image block (brightness image block or chromaticity image block) is coded, an intermediate coding result of the image block is obtained, and then the intermediate coding result of each image block is coded by a variable length integer coding algorithm, so that an image block alternating current coding result corresponding to each image block is obtained.
For example, the intermediate encoding result of one image block is: (0,57); (0, 45); (4, 23); (1, -30); (0, -8); (2, 1); (0, 0), the intermediate encoding result is encoded according to the aforementioned VLI table, resulting in an image block ac encoding result, e.g. in the form of (0,57) can be written as (0, 6), 57, (0, 45) can be written as (0, 6), 45, (1, -30) can be written as (1, 5), -30, such image block ac encoding result also being referred to as an intermediate format of ac coefficients.
S408, obtaining a first compression result according to the direct current coding result and the alternating current coding result.
And after the direct current coding result and the alternating current coding result of the first sub-image are obtained, summarizing the direct current coding result and the alternating current coding result to obtain a first compression result.
The first sub-image comprises a first brightness sub-image and a first chrominance sub-image, a brightness direct current coding result of the first brightness sub-image and a chrominance direct current coding result of the first chrominance sub-image are determined according to the method, a brightness alternating current coding result of the first brightness sub-image and a chrominance alternating current coding result of the first chrominance sub-image are determined, and the brightness direct current coding result of the first brightness sub-image, the chrominance direct current coding result of the first chrominance sub-image, the brightness alternating current coding result of the first brightness sub-image and the chrominance alternating current coding result of the first chrominance sub-image are summarized to obtain a first compression result.
As an embodiment, S408 may include: carrying out Huffman coding on the direct current coding result to obtain a direct current Huffman coding table; carrying out Huffman coding on the alternating current coding result to obtain an alternating current Huffman coding table; and obtaining a first compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
The obtained direct current coding result comprises a brightness direct current coding result and a chrominance direct current coding result, the obtained alternating current coding result comprises a brightness alternating current coding result and a chrominance alternating current coding result, the corresponding direct current Huffman coding table comprises a brightness direct current Huffman coding table and a chrominance direct current Huffman coding table, and the corresponding alternating current Huffman coding table comprises a brightness alternating current Huffman coding table and a chrominance alternating current Huffman coding table.
Respectively carrying out Huffman coding on a luminance direct current coding result of the first luminance sub-image, a chrominance direct current coding result of the first chrominance sub-image, a luminance alternating current coding result of the first luminance sub-image and a chrominance alternating current coding result of the first chrominance sub-image to obtain a luminance direct current Huffman coding table, a chrominance direct current Huffman coding table, a luminance alternating current Huffman coding table and a chrominance alternating current Huffman coding table, and summarizing the luminance direct current Huffman coding table, the chrominance direct current Huffman coding table, the luminance alternating current Huffman coding table and the chrominance alternating current Huffman coding table to obtain a first compression result.
S409, performing compression processing on the second sub-image through the second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than the compression ratio corresponding to the second compression quantization table.
And S410, obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
The descriptions of S409-S410 refer to the descriptions of S103-S104 above, and are not repeated here.
In this embodiment, the variable-length integer coding algorithm and the run-length coding algorithm are used to code the ac coefficient and the dc coefficient corresponding to the first sub-image, so that the data size after coding is reduced, and thus the data size of the obtained first compression result is smaller, and further the data size of the obtained final compression result is smaller, and the compression effect is improved.
Referring to fig. 8, fig. 8 is a flowchart of an image compression method according to an embodiment of the present application, where the method may be applied to an electronic device, and the electronic device may be the terminal 101 in fig. 1, and the method includes:
s501, segmentation processing is carried out on the image to be compressed, and a first sub-image including the target object and a second sub-image not including the target object are obtained.
S502, compressing the first sub-image through a first compression quantization table to obtain a first compression result.
The descriptions of S501-S502 refer to the descriptions of S401-S408 above, and are not repeated here.
S503, calculating the difference value between the pixel value of each pixel point in each image block and a preset numerical value to be used as the intermediate value of the pixel point.
In this embodiment, the second sub-image includes a second luminance sub-image and a second chrominance sub-image, each of which includes a plurality of image blocks of a preset size.
Taking a plurality of image blocks included in the second brightness sub-image as a plurality of brightness image blocks, and taking the difference value between the pixel value of each pixel point in each brightness image block and a preset numerical value as the intermediate value of the pixel point; and taking a plurality of image blocks included in the second chromaticity sub-image as a plurality of chromaticity image blocks, and taking the difference value between the pixel value of each pixel point in each chromaticity image block and a preset numerical value as the intermediate value of the pixel point.
S504, performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block.
For each brightness image block corresponding to the second brightness sub-image, performing discrete cosine transform processing on the intermediate value of each pixel point in the brightness image block to obtain a discrete result of the pixel point, and summarizing the discrete results of each pixel point in the brightness image block to obtain a discrete result of the brightness image block; and aiming at each chromaticity image block corresponding to the second chromaticity sub-image, performing discrete cosine transform processing on the intermediate value of each pixel point in the chromaticity image block to obtain a discrete result of the pixel point, and summarizing the discrete results of each pixel point in the chromaticity image block to obtain the discrete result of the chromaticity image block.
S505, rounding the discrete value of each pixel point in each image block to obtain a rounding discrete result corresponding to each image block; compressing the rounded discrete result of each image block through a second compression quantization table to obtain an intermediate result corresponding to each image block; and carrying out scanning sequencing on each number in each intermediate result through a preset scanning sequencing algorithm to obtain a number sequence corresponding to each image block.
For the second brightness sub-image, rounding the discrete value of each pixel point in each brightness image block included in the second brightness sub-image to obtain a rounding discrete result corresponding to each brightness image block; compressing the rounded discrete result of each brightness image block through a second compression quantization table to obtain an intermediate result corresponding to each brightness image block; and carrying out scanning sequencing on each number in each intermediate result through a preset scanning sequencing algorithm to obtain a number sequence corresponding to each brightness image block, and carrying out compression processing on the number sequence of each brightness image block to obtain a second brightness compression result.
For the second chromaticity sub-image, rounding the discrete value of each pixel point in the process of carrying out the second chromaticity sub-image to obtain a rounding discrete result corresponding to each chromaticity image block; compressing the rounded discrete result of each chromaticity image block through a second compression quantization table to obtain an intermediate result corresponding to each chromaticity image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each chromaticity image block; and compressing the digital sequence of each chromaticity image block to obtain a second chromaticity compression result. And summarizing the second brightness compression result and the second chromaticity compression result to obtain a second compression result.
Compressing the rounded discrete result of each image block through the second compression quantization table may mean that each rounded discrete result of each image block is made to be a quotient with a value corresponding to the rounded discrete result in the second compression quantization table, the quotient is rounded down to obtain an intermediate result of the rounded discrete result of the image block, and the intermediate results of the rounded discrete results in the image block are summarized to obtain an intermediate result of the image block.
S506, determining a direct current coefficient and an alternating current coefficient from the digital sequence of each image block.
The first digit in the sequence of digits of an image block (luminance image block or chrominance image block) may be taken as the dc coefficient and the other digits as ac coefficients.
S507, performing compression coding on the direct current coefficients corresponding to the image blocks to obtain a direct current coding result.
And aiming at each second sub-image, including a second brightness sub-image and a second chromaticity sub-image, performing compression coding on the direct current coefficients corresponding to a plurality of brightness image blocks in the second brightness sub-image to obtain a brightness direct current coding result, performing compression coding on the direct current coefficients corresponding to a plurality of chromaticity image blocks in the second chromaticity sub-image to obtain a chromaticity direct current coding result, and summarizing the brightness direct current coding result and the chromaticity direct current coding result to obtain a direct current coding result.
As an embodiment, the plurality of image blocks are arranged in the target order, S507 may include: acquiring a direct current coefficient of a second image block in the plurality of image blocks as a target value of the second image block; calculating the difference between the DC coefficient of each image block and the DC coefficient of the image block before the image block as the target value of the image block; and coding the target values of the image blocks by a variable length integer coding algorithm to obtain a direct current coding result.
The target sequence may refer to a left-to-right sequential arrangement of positions of each image block of each row in the second sub-image, and a top-to-bottom sequential arrangement of image blocks of multiple rows, that is, for the second luminance sub-image, the target sequence is a left-to-right sequential arrangement of positions of each image block of each row in the second luminance sub-image, and the multiple rows of luminance image blocks are sequentially arranged from top to bottom; for the second chrominance sub-image, the target sequence is that the positions of each chrominance image block of each row in the second chrominance sub-image are arranged in sequence from left to right, and the chrominance image blocks of a plurality of rows are arranged in sequence from top to bottom.
For example, the second luminance sub-image includes 7 luminance image blocks, which are divided into 3 rows in total, the target order is that the luminance image blocks in each row are arranged from top to bottom, the four luminance image blocks in the second row are respectively the second luminance image block, the third luminance image block and the fourth luminance image block, and the three luminance image blocks in the second row are respectively the fifth luminance image block, the sixth luminance image block and the seventh luminance image block.
Each image block in each second brightness sub-image is a brightness image block, and the direct current coefficient of the second brightness image block is obtained from a plurality of brightness image blocks and used as the target value of the second brightness image block; calculating the difference between the brightness image block and the direct current coefficient of the brightness image block before the brightness image block as the target value of the brightness image block; and coding the target values of the multiple brightness image blocks through a variable length integer coding algorithm to obtain a brightness direct current coding result.
Similarly, each image block in each second chrominance sub-image is a chrominance image block, and the direct current coefficient of the second chrominance image block is obtained from a plurality of chrominance image blocks and is used as a target value of the second chrominance image block; calculating the difference between the direct current coefficients of the chrominance image block and the previous chrominance image block of the chrominance image block as a target value of the chrominance image block; and coding the target values of the image blocks of each chromaticity by a variable length integer coding algorithm to obtain a chromaticity direct current coding result.
S508, performing compression coding on the alternating current coefficient of each image block to obtain an alternating current coding result.
And aiming at a plurality of alternating coefficients of each image block, carrying out compression coding on the alternating coefficients to obtain an alternating coding result of the image block, traversing all the image blocks, and obtaining an alternating coding result of a second sub-image.
And aiming at each second sub-image comprising a second brightness sub-image and a second chromaticity sub-image, carrying out compression coding on alternating current coefficients corresponding to a plurality of brightness image blocks in the second brightness sub-image to obtain a brightness alternating current coding result, carrying out compression coding on alternating current coefficients corresponding to a plurality of chromaticity image blocks in the second chromaticity sub-image to obtain a chromaticity alternating current coding result, and summarizing the brightness alternating current coding result and the chromaticity alternating current coding result to obtain an alternating current coding result.
As an embodiment, S508 may include: coding the alternating current coefficient of each image block through a run coding algorithm to obtain an image block alternating current coding result corresponding to each image block; and summarizing the image block alternating current coding results of each of the plurality of image blocks to obtain an alternating current coding result. The coding method comprises the steps of coding alternating current coefficients of each image block through a run coding algorithm to obtain an image block alternating current coding result corresponding to each image block, wherein the method comprises the following steps: coding the alternating current coefficient of each image block through a run coding algorithm to obtain an intermediate coding result corresponding to each image block; and coding the intermediate coding result of each image block through a variable length integer coding algorithm to obtain an image block alternating current coding result corresponding to each image block.
Each image block in each second brightness sub-image is a brightness image block, and alternating current coefficients of each brightness image block are coded through a journey coding algorithm to obtain an intermediate coding result corresponding to each brightness image block; coding the intermediate coding result of each brightness image block through a variable length integer coding algorithm to obtain a brightness image block alternating current coding result corresponding to each brightness image block; and summarizing the brightness image block alternating current coding results of each of the plurality of brightness image blocks in the second brightness sub-image to obtain the brightness alternating current coding result.
Similarly, each image block in each second chrominance sub-image is a chrominance image block, and alternating current coefficients of each chrominance image block are encoded through a run-length encoding algorithm to obtain an intermediate encoding result corresponding to each chrominance image block; coding the intermediate coding result of each chromaticity image block through a variable length integer coding algorithm to obtain a chromaticity image block alternating current coding result corresponding to each chromaticity image block; and summarizing the chroma image block alternating current coding results of each of the plurality of chroma image blocks in the second chroma sub-image to obtain a chroma alternating current coding result.
S509, obtaining a second compression result according to the direct current coding result and the alternating current coding result.
And after the direct current coding result and the alternating current coding result of the second sub-image are obtained, summarizing the direct current coding result and the alternating current coding result to obtain a second compression result.
The second sub-image comprises a second luminance sub-image and a second chrominance sub-image, the luminance direct current coding result of the second luminance sub-image and the chrominance direct current coding result of the second chrominance sub-image are determined according to the method, the luminance alternating current coding result of the second luminance sub-image and the chrominance alternating current coding result of the second chrominance sub-image are determined, and the luminance direct current coding result of the second luminance sub-image, the chrominance direct current coding result of the second chrominance sub-image, the luminance alternating current coding result of the second luminance sub-image and the chrominance alternating current coding result of the second chrominance sub-image are summarized to obtain a second compression result.
As an embodiment, S509 may include: carrying out Huffman coding on the direct current coding result to obtain a direct current Huffman coding table; carrying out Huffman coding on the alternating current coding result to obtain an alternating current Huffman coding table; and obtaining a second compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
The obtained direct current coding result comprises a brightness direct current coding result and a chrominance direct current coding result, the obtained alternating current coding result comprises a brightness alternating current coding result and a chrominance alternating current coding result, the corresponding direct current Huffman coding table comprises a brightness direct current Huffman coding table and a chrominance direct current Huffman coding table, and the corresponding alternating current Huffman coding table comprises a brightness alternating current Huffman coding table and a chrominance alternating current Huffman coding table.
And respectively carrying out Huffman coding on the luminance direct current coding result of the second luminance sub-image, the chrominance direct current coding result of the second chrominance sub-image, the luminance alternating current coding result of the second luminance sub-image and the chrominance alternating current coding result of the second chrominance sub-image to obtain a luminance direct current Huffman coding table, a chrominance alternating current Huffman coding table and a chrominance alternating current Huffman coding table, and summarizing the luminance direct current Huffman coding table, the chrominance direct current Huffman coding table, the luminance alternating current Huffman coding table and the chrominance alternating current Huffman coding table to obtain a second compression result.
S510, obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
The description of S510 refers to the description of S410 above, and will not be repeated here.
In this embodiment, the variable-length integer encoding algorithm and the run length encoding algorithm are used to encode the ac coefficient and the dc coefficient corresponding to the second sub-image, so as to reduce the data size after encoding, thereby reducing the data size of the obtained second compression result, reducing the data size of the obtained final compression result, and improving the compression effect.
For a clearer understanding of the technical solution of the present application, the image compression method of the present application is explained below in conjunction with an exemplary scenario, which is a traffic monitoring scenario.
The video camera collects video streams of the expressway, the video frames of the video streams are all video frames in RGB format, each video frame in RGB format is an image to be compressed, the video frames are shown in fig. 9, the target objects are vehicles (including cars, trucks, buses and the like), and in the video frames, the definition of the target objects and other objects except the target objects is higher (for example, the details of buildings and trees are clearer).
As shown in fig. 10, after the video camera obtains the video stream, the video camera performs target detection on the video frames in RGB format in the video stream through the target object detection model for each video frame in RGB format, so as to obtain a detection frame for framing the target object.
Meanwhile, converting a video frame in an RGB format into a format conversion image in a YUV format (namely, the target format of the embodiment), performing luminance full sampling processing on the format conversion image to obtain a luminance sampling image, performing chromaticity downsampling processing on the format conversion image to obtain a chromaticity sampling image, and then dividing the luminance sampling image and the chromaticity sampling image into a plurality of image blocks with the size of 8 x 8.
The method comprises the following steps of:
as shown in fig. 10, a luminance image block having an intersection with the detection frame is acquired and aggregated as a first luminance sub-image, and an image block having no intersection with the detection frame is acquired and aggregated as a second luminance sub-image.
For each luminance image block in the first luminance sub-image, performing DCT processing on the luminance image block: calculating the difference value between the pixel value of each pixel point in each brightness image block and a preset numerical value to be used as the intermediate value of the pixel point; performing discrete cosine transform processing on the intermediate value of each pixel point in each brightness image block to obtain a discrete result corresponding to each brightness image block; and rounding the discrete value of each pixel point in each brightness image block to obtain a rounding discrete result corresponding to each brightness image block.
After DCT processing, obtaining the rounded discrete result of each brightness image block, and then carrying out low-loss quantization processing on the rounded discrete result of each brightness image block: and compressing the rounded discrete result of each brightness image block through the first compression quantization table to obtain an intermediate result corresponding to each brightness image block.
After obtaining the intermediate result of each brightness image block, scanning and sequencing each number in each intermediate result by using a Zigzag scanning and sequencing algorithm to obtain a number sequence corresponding to each brightness image block; after obtaining the digital sequence of each luminance image block, entropy encoding is performed on the digital sequence of each luminance image block: determining a direct current coefficient (a first digit of the digital sequence) and an alternating current coefficient (second to sixty-fourth digits of the digital sequence) from the digital sequence of each luminance image block; compressing and encoding the direct current coefficients corresponding to the plurality of brightness image blocks to obtain a direct current encoding result; compression coding is carried out on the alternating current coefficient of each brightness image block, and an alternating current coding result is obtained; and respectively carrying out Huffman coding on the direct current coding result and the alternating current coding result to obtain a direct current Huffman coding table and an alternating current Huffman coding table, and obtaining a first brightness compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
For each luminance image block in the second luminance sub-image, performing DCT processing on the luminance image block: calculating the difference value between the pixel value of each pixel point in each brightness image block and a preset numerical value to be used as the intermediate value of the pixel point; performing discrete cosine transform processing on the intermediate value of each pixel point in each brightness image block to obtain a discrete result corresponding to each brightness image block; and rounding the discrete value of each pixel point in each brightness image block to obtain a rounding discrete result corresponding to each brightness image block.
After DCT processing, obtaining the rounded discrete result of each brightness image block, and then carrying out high-loss quantization processing on the rounded discrete result of each brightness image block: and compressing the rounded discrete result of each brightness image block through a second compression quantization table (the compression ratio corresponding to the first compression quantization table is smaller than the compression ratio corresponding to the second compression quantization table), so as to obtain an intermediate result corresponding to each brightness image block.
After obtaining the intermediate result of each brightness image block, scanning and sequencing each number in each intermediate result by using a Zigzag scanning and sequencing algorithm to obtain a number sequence corresponding to each brightness image block; after obtaining the digital sequence of each luminance image block, entropy encoding is performed on the digital sequence of each luminance image block: determining a direct current coefficient (a first digit of the digital sequence) and an alternating current coefficient (second to sixty-fourth digits of the digital sequence) from the digital sequence of each luminance image block; compressing and encoding the direct current coefficients corresponding to the plurality of brightness image blocks to obtain a direct current encoding result; compression coding is carried out on the alternating current coefficient of each floor image block, and an alternating current coding result is obtained; and respectively carrying out Huffman coding on the direct current coding result and the alternating current coding result to obtain a direct current Huffman coding table and an alternating current Huffman coding table, and obtaining a second brightness compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
And summarizing the first brightness compression result and the second brightness compression result corresponding to the brightness sampling image to obtain a final compression result corresponding to the brightness sampling image.
The above process is also performed on the chroma sampling image to obtain a final compression result of the corresponding chroma sampling image, where the process of the chroma sampling image is similar to that of the luma sampling image, and will not be repeated.
Traversing all video frames of the video stream to obtain a final compression result corresponding to the video stream. The final compression result corresponding to the video stream includes the final compression result corresponding to each video frame. The camera sends the final compression result of the video stream to a server (the server may refer to the distributed cloud storage system described in the above embodiment), and after receiving the final compression result corresponding to the video stream, the server decompresses the final compression result corresponding to the video stream to obtain a decompression result corresponding to the video stream, where the decompression result includes the decompression result of each video frame.
As shown in fig. 11, the decompression result corresponding to fig. 9 is a compressed image of 100KB, which occupies a significantly reduced space compared with the original video frame of 3.12MB (i.e. the compression ratio is 31.2), and the vehicle definition in the decompression result is still higher, and the definition is lower for the areas other than the unimportant vehicle (such as the detail definition of the building and the tree), so that the high compression ratio compression of the image to be compressed is realized on the premise of only reducing the definition of the area other than the target object.
Referring to fig. 12, fig. 12 shows a block diagram of an image compression apparatus according to an embodiment of the present application, an apparatus 1100 includes:
a segmentation module 1110, configured to perform segmentation processing on an image to be compressed to obtain a first sub-image including a target object and a second sub-image not including the target object;
the first compression module 1120 is configured to perform compression processing on the first sub-image through the first compression quantization table to obtain a first compression result;
the second compression module 1130 is configured to perform compression processing on the second sub-image through a second compression quantization table to obtain a second compression result, where a compression ratio corresponding to the first compression quantization table is smaller than a compression ratio corresponding to the second compression quantization table;
the result obtaining module 1140 is configured to obtain a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
Optionally, the segmentation module 1110 is further configured to perform target object detection on the image to be compressed to obtain a detection frame for selecting the target object; sampling the image to be compressed to obtain a sampled image; and determining a first sub-image and a second sub-image in the sampled image according to the detection frame.
Optionally, the segmentation module 1110 is further configured to perform segmentation processing on the sampled image to obtain a plurality of image blocks with preset sizes; acquiring and summarizing an image block with an intersection with a detection frame as a first sub-image; and acquiring and summarizing the image blocks which do not have intersection with the detection frame as a second sub-image.
Optionally, the segmentation module 1110 is further configured to perform format conversion processing on the image to be compressed to obtain a format-converted image if the image to be compressed is not the image in the target format; and sampling the format conversion image to obtain a sampling image.
Optionally, the segmentation module 1110 is further configured to perform luminance full-sampling processing on the format-converted image to obtain a luminance sample image; performing chroma downsampling processing on the format conversion image to obtain a chroma sampling image; and summarizing the brightness sampling image and the chromaticity sampling image to obtain a sampling image.
Optionally, the first sub-image includes a plurality of image blocks of a preset size; the first compression module 1120 is further configured to calculate a difference between a pixel value of each pixel point in each image block and a preset value, where the difference is used as an intermediate value of the pixel point; performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block; and compressing the discrete result of each image block through the first compression quantization table to obtain a first compression result.
Optionally, the discrete result of each image block includes a discrete value corresponding to each pixel point in the image block; the first compression module 1120 is further configured to perform rounding processing on the discrete value of each pixel point in each image block, so as to obtain a rounded discrete result corresponding to each image block; compressing the rounded discrete result of each image block through a first compression quantization table to obtain an intermediate result corresponding to each image block; scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each image block; and compressing the digital sequence of each image block to obtain a first compression result.
Optionally, the first compression module 1120 is further configured to determine a dc coefficient and an ac coefficient from the digital sequence of each image block; carrying out compression coding on the direct current coefficients corresponding to the image blocks to obtain a direct current coding result; compression coding is carried out on the alternating current coefficient of each image block, and an alternating current coding result is obtained; and obtaining a first compression result according to the direct current coding result and the alternating current coding result.
Optionally, the plurality of image blocks are arranged in a target order; the first compression module 1120 is further configured to obtain a dc coefficient of a first image block of the plurality of image blocks as a target value of the first image block; calculating the difference between the DC coefficient of each image block and the DC coefficient of the image block before the image block as the target value of the image block; and coding the target values of the image blocks by a variable length integer coding algorithm to obtain a direct current coding result.
Optionally, the first compression module 1120 is further configured to encode the ac coefficient of each image block by a run-length encoding algorithm, so as to obtain an image block ac encoding result corresponding to each image block; and summarizing the image block alternating current coding results of each of the plurality of image blocks to obtain an alternating current coding result.
Optionally, the first compression module 1120 is further configured to encode the ac coefficient of each image block by a run-length encoding algorithm, so as to obtain an intermediate encoding result corresponding to each image block; and coding the intermediate coding result of each image block through a variable length integer coding algorithm to obtain an image block alternating current coding result corresponding to each image block.
Optionally, the first compression module 1120 is further configured to perform huffman coding on the dc coding result to obtain a dc huffman coding table; carrying out Huffman coding on the alternating current coding result to obtain an alternating current Huffman coding table; and obtaining a first compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
It should be noted that, in the present application, the device embodiment and the foregoing method embodiment correspond to each other, and specific principles in the device embodiment may refer to the content in the foregoing method embodiment, which is not described herein again.
Fig. 13 shows a block diagram of an electronic device for performing an image compression method according to an embodiment of the present application. The electronic device may be the terminal 101 in fig. 1, etc., and it should be noted that the computer system 1200 of the electronic device shown in fig. 13 is only an example, and should not impose any limitation on the functions and the application scope of the embodiments of the present application.
As shown in fig. 13, the computer system 1200 includes a central processing unit (Central Processing Unit, CPU) 1201 which can perform various appropriate actions and processes, such as performing the methods in the above-described embodiments, according to a program stored in a Read-Only Memory (ROM) 1202 or a program loaded from a storage section 1208 into a random access Memory (Random Access Memory, RAM) 1203. In the RAM 1203, various programs and data required for the system operation are also stored. The CPU1201, ROM1202, and RAM 1203 are connected to each other through a bus 1204. An Input/Output (I/O) interface 1205 is also connected to bus 1204.
The following components are connected to the I/O interface 1205: an input section 1206 including a keyboard, a mouse, and the like; an output portion 1207 including a Cathode Ray Tube (CRT), a liquid crystal display (Liquid Crystal Display, LCD), and a speaker, etc.; a storage section 1208 including a hard disk or the like; and a communication section 1209 including a network interface card such as a LAN (Local Area Network ) card, a modem, or the like. The communication section 1209 performs communication processing via a network such as the internet. The drive 1210 is also connected to the I/O interface 1205 as needed. A removable medium 1211 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed on the drive 1210 as needed, so that a computer program read out therefrom is installed into the storage section 1208 as needed.
In particular, according to embodiments of the present application, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1209, and/or installed from the removable media 1211. When executed by a Central Processing Unit (CPU) 1201, performs the various functions defined in the system of the present application.
It should be noted that, the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-Only Memory (ROM), an erasable programmable read-Only Memory (Erasable Programmable Read Only Memory, EPROM), flash Memory, an optical fiber, a portable compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present application, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. Where each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present application may be implemented by software, or may be implemented by hardware, and the described units may also be provided in a processor. Wherein the names of the units do not constitute a limitation of the units themselves in some cases.
As another aspect, the present application also provides a computer-readable storage medium that may be contained in the electronic device described in the above embodiment; or may exist alone without being incorporated into the electronic device. The computer readable storage medium carries computer readable instructions which, when executed by a processor, implement the method of any of the above embodiments.
According to an aspect of embodiments of the present application, there is provided a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the electronic device to perform the method of any of the embodiments described above.
It should be noted that although in the above detailed description several modules or units of a device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functions of two or more modules or units described above may be embodied in one module or unit in accordance with embodiments of the application. Conversely, the features and functions of one module or unit described above may be further divided into a plurality of modules or units to be embodied.
From the above description of embodiments, those skilled in the art will readily appreciate that the example embodiments described herein may be implemented in software, or may be implemented in software in combination with the necessary hardware. Thus, the technical solution according to the embodiments of the present application may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a usb disk, a mobile hard disk, etc.) or on a network, and includes several instructions to cause an electronic device (may be a personal computer, a server, a touch terminal, or a network device, etc.) to perform the method according to the embodiments of the present application.
Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the application pertains. It is to be understood that the application is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the application is limited only by the appended claims.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present application, and are not limiting; although the application has been described in detail with reference to the foregoing embodiments, it will be appreciated by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not drive the essence of the corresponding technical solutions to depart from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (15)

1. An image compression method, the method comprising:
dividing an image to be compressed to obtain a first sub-image comprising a target object and a second sub-image not comprising the target object;
compressing the first sub-image through a first compression quantization table to obtain a first compression result;
compressing the second sub-image through a second compression quantization table to obtain a second compression result, wherein the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table;
and obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
2. The method according to claim 1, wherein the dividing the image to be compressed to obtain a first sub-image including the target object and a second sub-image not including the target object includes:
detecting a target object of the image to be compressed to obtain a detection frame for selecting the target object;
sampling the image to be compressed to obtain a sampled image;
and determining the first sub-image and the second sub-image in the sampling image according to the detection frame.
3. The method of claim 2, wherein the determining the first sub-image and the second sub-image in the sampled image by the detection block comprises:
dividing the sampled image to obtain a plurality of image blocks with preset sizes;
acquiring and summarizing an image block with an intersection with the detection frame as the first sub-image;
and acquiring and summarizing the image blocks which do not have intersection with the detection frame as the second sub-image.
4. The method according to claim 2, wherein the sampling the image to be compressed to obtain a sampled image comprises:
If the image to be compressed is not the image with the target format, carrying out format conversion processing on the image to be compressed to obtain a format conversion image;
and sampling the format conversion image to obtain a sampling image.
5. The method of claim 4, wherein sampling the format-converted image to obtain a sampled image comprises:
performing full sampling processing on the brightness of the format conversion image to obtain a brightness sampling image;
performing chroma downsampling processing on the format conversion image to obtain a chroma sampling image;
and summarizing the brightness sampling image and the chromaticity sampling image to obtain the sampling image.
6. The method of claim 1, wherein the first sub-image comprises a plurality of image blocks of a preset size; the compressing the first sub-image through the first compression quantization table to obtain a first compression result, including:
calculating the difference value between the pixel value of each pixel point in each image block and a preset numerical value to be used as the intermediate value of the pixel point;
performing discrete cosine transform processing on the intermediate value of each pixel point in each image block to obtain a discrete result corresponding to each image block;
And compressing the discrete result of each image block through a first compression quantization table to obtain a first compression result.
7. The method of claim 6, wherein the discrete result for each image block comprises a discrete value for each pixel in the image block; the compressing, by the first compression quantization table, the discrete result of each image block to obtain a first compressed result, including:
rounding the discrete value of each pixel point in each image block to obtain a rounded discrete result corresponding to each image block;
compressing the rounded discrete result of each image block through a first compression quantization table to obtain an intermediate result corresponding to each image block;
scanning and sorting the numbers in each intermediate result through a preset scanning and sorting algorithm to obtain a number sequence corresponding to each image block;
and compressing the digital sequence of each image block to obtain a first compression result.
8. The method of claim 7, wherein compressing the digital sequence of each image block to obtain a first compressed result comprises:
Determining a direct current coefficient and an alternating current coefficient from the digital sequence of each image block;
compressing and encoding the direct current coefficients corresponding to the image blocks to obtain a direct current encoding result;
compression coding is carried out on the alternating current coefficient of each image block, and an alternating current coding result is obtained;
and obtaining the first compression result according to the direct current coding result and the alternating current coding result.
9. The method of claim 8, wherein the plurality of tiles are arranged in a target order; the compressing and encoding the direct current coefficients corresponding to the image blocks to obtain a direct current encoding result comprises the following steps:
acquiring a direct current coefficient of a first image block in the plurality of image blocks as a target value of the first image block;
calculating the difference between the DC coefficient of each image block and the DC coefficient of the image block before the image block as the target value of the image block;
and coding the target values of the image blocks through a variable length integer coding algorithm to obtain a direct current coding result.
10. The method of claim 8, wherein said compression encoding the ac coefficients of each of said image blocks to obtain ac encoding results comprises:
Coding the alternating current coefficient of each image block through a journey coding algorithm to obtain an image block alternating current coding result corresponding to each image block;
and summarizing the image block alternating current coding results of each of the plurality of image blocks to obtain an alternating current coding result.
11. The method of claim 10, wherein the over-run coding algorithm codes the ac coefficient of each image block to obtain an image block ac coding result corresponding to each image block, and comprises:
coding the alternating current coefficient of each image block through a run coding algorithm to obtain an intermediate coding result corresponding to each image block;
and coding the intermediate coding result of each image block through a variable length integer coding algorithm to obtain an image block alternating current coding result corresponding to each image block.
12. The method of claim 8, wherein the obtaining the first compression result according to the dc encoding result and the ac encoding result comprises:
carrying out Huffman coding on the direct current coding result to obtain a direct current Huffman coding table;
Carrying out Huffman coding on the alternating current coding result to obtain an alternating current Huffman coding table;
and obtaining the first compression result according to the direct current Huffman coding table and the alternating current Huffman coding table.
13. An image compression apparatus, the apparatus comprising:
the segmentation module is used for carrying out segmentation processing on the image to be compressed to obtain a first sub-image comprising the target object and a second sub-image not comprising the target object;
the first compression module is used for compressing the first sub-image through a first compression quantization table to obtain a first compression result;
the second compression module is used for carrying out compression processing on the second sub-image through a second compression quantization table to obtain a second compression result, and the compression ratio corresponding to the first compression quantization table is smaller than that corresponding to the second compression quantization table;
and the result obtaining module is used for obtaining a final compression result corresponding to the image to be compressed according to the first compression result and the second compression result.
14. An electronic device, comprising:
one or more processors;
a memory;
one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications configured to perform the method of any of claims 1-12.
15. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a program code, which is callable by a processor for performing the method according to any one of claims 1-12.
CN202211176241.2A 2022-09-26 2022-09-26 Image compression method, device, electronic equipment and storage medium Pending CN117011396A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211176241.2A CN117011396A (en) 2022-09-26 2022-09-26 Image compression method, device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211176241.2A CN117011396A (en) 2022-09-26 2022-09-26 Image compression method, device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117011396A true CN117011396A (en) 2023-11-07

Family

ID=88562483

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211176241.2A Pending CN117011396A (en) 2022-09-26 2022-09-26 Image compression method, device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117011396A (en)

Similar Documents

Publication Publication Date Title
CN111918066B (en) Video encoding method, device, equipment and storage medium
CN109842803B (en) Method and device for image compression
CN108028941B (en) Method and apparatus for encoding and decoding digital images by superpixel
CN103886623B (en) A kind of method for compressing image, equipment and system
JP6664819B2 (en) System and method for mask-based processing of blocks of digital images
CN112565760B (en) Encoding method, apparatus and storage medium for string encoding technique
JPH11127355A (en) Image encoding apparatus, image encoding method, and recording medium recording image encoding program
US20240114185A1 (en) Video coding for machines (vcm) encoder and decoder for combined lossless and lossy encoding
CN117560511A (en) Spacer bar image compression method and system for power inspection based on graph segmentation technology
WO2022133753A1 (en) Point cloud encoding and decoding methods and systems, point cloud encoder, and point cloud decoder
CN113068034A (en) Video encoding method and device, encoder, equipment and storage medium
WO2022257528A1 (en) Point cloud attribute prediction method and apparatus, and related device
CN114501022A (en) Data processing method and device, computer equipment and storage medium
CN118890489A (en) Image processing method and system
CN113766319A (en) Image information processing method and device, and storage medium
CN117011396A (en) Image compression method, device, electronic equipment and storage medium
CN106954065A (en) A Recursive Predictive Image Compression Method Based on Gradient Oriented Histogram
CN116708800A (en) Image coding and decoding method, device and system
CN115917611B (en) Method and system for video encoding and decoding using reference region
CN116055733A (en) Video encoding method, apparatus and readable storage medium
KR20240006667A (en) Point cloud attribute information encoding method, decoding method, device and related devices
TW202147850A (en) Methods and systems for combined lossless and lossy coding
CN113365080A (en) Encoding and decoding method, device and storage medium for string coding technology
Yang et al. CC-SMC: Chain coding-based segmentation map lossless compression
US20240037799A1 (en) Point cloud coding/decoding method and apparatus, device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination