The present invention relates to a compression method. More particularly, given a digital image, the invention is concerned with a fast and efficient method whose purpose is to compress and store multiple Boolean masks that indicate which pixels of the image belong to different objects.
While annotating images and videos, one often needs to draw multiple Boolean masks over the image to indicate which pixels of the image belong to different objects.
While editing video annotation, multiple such masks may be loaded into client memory for different video frames, while only a fraction of these masks is used at a time.
It follows from the above that there is a need for a fast and efficient method for compressing currently unused masks in memory, and also for transferring these masks between client and server.
Using lossless data compression methods (deflate) such as Lempel-Ziv or Huffman coding is not an option, because there is no native deflate API (Application Programming Interface) in web browsers, and JS (JavaScript)-based implementations are too slow for many applications.
Moreover, the use of PNG (Portable Network Graphics) images is prohibitive because conversion from multiple PNG image BLOBs (Binary Large OBjects) to arrays of bits and back using native APIs is too complicated.
The invention is based on a novel compression/decompression method that is specially designed for compressing Boolean bit-masks in web applications.
The method is especially well-suited for simple-shaped masks (e.g. containing a single concave shape) under 1200×1200 pixels, and provides a balanced tradeoff between compression level and CPU demand.
The invention relates to a method for performing compression and decompression of bitmasks comprising the steps of:
According to one embodiment of the invention, a run lengths above 66810 items is encoded as several runs with 0-length runs of alternate value in between.
In another embodiment of the invention, the compression/decompression algorithm is applied in a web application. In a further embodiment of the invention, the compression/decompression algorithm is applied to digital images or videos.
In some embodiments, when packing the bitmask as detailed in (II) above, the mask is scanned in column-major order. In other embodiments of step (II) above, the run length values are then encoded as bytes using variable length encoding.
In some embodiments of step (IV) above in which the first scanned bit of the bitmask is True, the first scanned bit of the bitmask is the upper-left bit. In other embodiments of step (IV) above, if the first scanned bit of the bitmask is False, then the first run of True values is stored as having 0 instances.
The invention also encompasses apparatus for carrying out the method of the invention, comprising a CPU and memory means associated with said CPU, where said memory means dynamically store information provided by the CPU about run lengths, and where the CPU dynamically retrieves said information from said memory means whenever required.
According to an embodiment of the invention, the CPU is adapted to perform the following steps:
In the drawings:
A bitmask is represented as a 2D (two-dimensional) matrix where each cell contains a single Boolean value (bit) indicating whether a specific pixel is included in the mask or not.
The mask is packed as an array of numbers, each number representing the length of a continuous run of False or True values, as shown in
Only run lengths, as shown in
Run length values are then encoded as bytes using variable length encoding (1-3 bytes per value), as shown in
Run lengths above 66810 items will not be represented directly, but will be encoded as several runs with 0-length runs of alternate value in between, as shown in
Decompression is done by performing in reverse order the actions described for the compression stage.
The code included in the illustrative embodiment that implements the operations discussed in the detailed description of the invention for both of the compression process and of the decompression process, is shown in the following, it being understood that the illustrative example shows a simplified process, provided for the purpose of illustration only, and is not meant to limit the invention in any way.
All the above description and examples have been provided for the purpose of illustration and are not intended to limit the invention in any way. As will be apparent to the skilled person, the invention can be performed with many variations and with a variety of objects to be compressed and decompressed, all as defined in the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
281257 | Mar 2021 | IL | national |
Filing Document | Filing Date | Country | Kind |
---|---|---|---|
PCT/IL2022/050221 | 2/28/2022 | WO |