Method for compressing Tiled Image image file
By only storing the same image block once in the TIFF format image file and merging the black image blocks, combined with pre-storage judgment and compression technology, the problem of redundant storage space in the TIFF format is solved, achieving efficient image file compression and reducing storage space and improved compression efficiency.
Patent Information
- Application Number
- CN202310338488.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-01
AI Technical Summary
There is a problem of redundant storage space when storing TIFF format image files, especially in the fields of geographic information systems, aerial photography, and photogrammetry. The outer boundaries of polygonal strips are filled with black, resulting in an increase in redundant space.
By only storing the same image block once, and judging whether the information has been stored before storage, if it is, it will not be stored, if not, it will be stored, to avoid redundant storage; at the same time, black image blocks will be merged to reduce redundant storage , and compress the image blocks before storage.
It effectively reduces the storage space of TIFF image files, avoids redundant storage, improves compression efficiency, reduces storage space without changing data distortion, and improves storage space utilization.
Smart Images

Figure CN118733544A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image processing, and in particular relates to a Tiled Image image file compression method. Background Art
[0002] Tiled Image file is a file that stores image data in TIFF (Tag Image File Format) format into tiles, and each tile has a specific Tile number. In Tiled Image data processing, first read the image width ImageWidth and image length ImageLength parameters, and divide the image into several tiles according to the tile width TileWidth and tile length TileLength, with a total of TilesPerImage tiles. When dividing into several tiles, if there is a part that needs to be divided that is less than a tile with a tile width of TileWidth and a tile length of TileLength, fill the image with black (the RGB value of black is R=0, G=0, B=0) to expand the image boundary until it can be completely divided by tiles with a tile width of TileWidth and a tile length of TileLength. The final total number of tiles TilesPerImage=TilesAcross*TilesDown.
[0003] like Figure 1 The image is divided into 100 tiles. Each tile in the image corresponds to a tile number, and the numbers of the 100 tiles are different. Specifically, the tiles and their corresponding numbers are as follows: Figure 1 As shown, each tile has a unique number. The corresponding tile offset, tile byte count, and tile data are arranged in this way, and the tiles are Figure 2 The shown files are stored in TIFF format.
[0004] TIFF (Tag Image File Format) image file is one of the commonly used formats in graphic image processing. Its image format is complex. Because it is independent of the operating system, the storage form of image information is flexible, it can support many color systems, and it has the advantages of containing coordinate system, scale, longitude and latitude, length and angle unit geocoding information. It has been widely used in geographic information systems, aerial photography, photogrammetry and remote sensing.
[0005] The TIFF image file format is a three-level structure system with a .tif extension, including a file header information area, an identification information area, and an image data area ( Figure 2 The format is as follows:
[0006] The first structure is the file header information area, its English name is Image File Header (abbreviated as IFH). IFH consists of 16 bytes. It is at the top level of the TIFF image file structure system, located at the beginning of the file. It is unique and has a fixed position in the TIFF file. It is mainly used to describe the necessary information required by the TIFF file, such as Figure 2 The 8th to 15th fields of the file header information are used to record the offset of the location of the file directory.
[0007] The second structure is the identification information area, which consists of image file directories and tags. The English name of the image file directory is Image File Directory (abbreviated as IFD), which is a table used to distinguish one or more variable-length data blocks called tags (the English name of tags is tags). IFD stores a series of pointers (pointers are also called indexes), which are used to mark the starting position of tag-related data in the TIFF file and give the data type and length of each field. Its format is very flexible. Figure 2 The tag information is recorded in the identification information area starting from the 9th grid. The file directory occupies (20n+16) characters, of which a single tag data description information occupies 20 grids. The 12th to 19th bytes of tag1 are used to describe the pointer to the storage space, pointing to the storage location of tag1 in the image data area.
[0008] The third structure is image data, which stores relevant image information according to the address pointed to by IFD. Figure 2 Each tag in the image data shown has a 20-byte description file, and the image data is arranged in ascending order.
[0009] In the practical application of TIFF format image files in the fields of geographic information systems, aerial photography, photogrammetry and remote sensing, a target polygon strip is first delineated according to user requirements, and then a regular rectangular image with an area larger than the target polygon strip is output, and the outer boundary of the target polygon strip is filled with black. This filling leads to a lot of redundant space in the image file, such as Figure 1 The black block numbered 01 in the upper left corner has the same information as the black block numbered 10 in the upper right corner, so there is a defect of redundant storage space when the prior art TIFF format is used for storage. Summary of the invention
[0010] The object of the present invention is to provide a Tiled Image file compression method to solve the problem of large storage space due to redundant storage space when storing images based on the existing TIFF format.
[0011] In order to solve the above technical problems, the present invention provides a Tiled Image file compression method, comprising the following steps:
[0012] 1) Divide the original Tiled Image into multiple image blocks according to the set division rules;
[0013] 2) Among the image blocks with the same image data information, only the image data of one of the image blocks is selected and stored in the image data area of the TIFF image file, and the storage address of the image data is obtained as the storage address corresponding to the image block with the same image data information; the image data of the image block with unique image data information is also stored in the image data area of the TIFF image file, and the corresponding storage address is obtained as the storage address corresponding to the image block;
[0014] 3) Constructing the file header information and identification information area of the TIFF image file, wherein the data description information of each divided image block is established in the identification information area according to a set order; the address in the data description information is the storage address corresponding to the image block.
[0015] The beneficial effects are as follows: the method of the present invention stores the same image block only once, so that there is no storage space redundancy in the image data area of the TIFF image file, thereby reducing the storage space of the TIFF image file and realizing the compression of the Tiled Image file. Moreover, the method of the present invention reduces the storage space by storing the same image block only once without changing the data distortion of the original image, that is, the compression method of the present invention reduces the storage space of the TIFF image file without changing the data distortion.
[0016] Furthermore, in step 2), the image data information of the image blocks is stored in sequence in the image data area of the TIFF image file, and before storing, it is determined whether the image data information already stored includes the image data information of the image block to be stored. If so, the image data of only one of the image blocks is selected and stored in the image data area of the TIFF image file without storing the information.
[0017] The method of the present invention can accurately determine whether the information to be stored has been stored by judging it with the information already stored before storage. If it has been stored, it does not need to be stored again. If there is no information identical to the information to be stored in the information already stored, the information will be stored, avoiding the redundancy of stored information and reducing the storage space.
[0018] Furthermore, the image blocks with the same image data information and the same image are black image blocks.
[0019] Since no information is stored in the black image blocks, the present invention avoids the situation where repeated storage of black image blocks causes redundant storage space by merging only the black image blocks, and ensures the normal storage of other image blocks of the original image, thereby ensuring that the data information of other image blocks is not lost.
[0020] Furthermore, in step 2), the image data information of a black image block is first stored in the image data area of the TIFF image file, and then the image data information of other image blocks are sequentially stored in the image data area of the TIFF image file.
[0021] Since the method of the present invention only merges black image blocks, after the black image blocks are stored first, other image blocks can be compared with the black image blocks when they are subsequently stored, thereby simplifying the comparison process and improving compression efficiency.
[0022] Furthermore, when storing image data of an image block having unique image data information, the unique image block is compressed according to a set compression rule and then stored.
[0023] By compressing the image blocks before storing the data information, the storage space can be further reduced, further reducing the storage space of the TIFF image file.
[0024] Furthermore, in step 1), the setting division rule is to divide the image into regular rectangular image blocks of a set size.
[0025] Since the original Tiled Image is a regular rectangle, the original Tiled Image is divided by using regular rectangular image blocks of a set size, thereby ensuring that the original Tiled Image matches the segmented image blocks in shape. In addition, based on the method of the present invention, the original Tiled Image can be completely divided by using regular rectangular image blocks of a set size.
[0026] Furthermore, in step 1), the image blocks are numbered after being divided according to the set division rule, and the image blocks correspond to the numbers of the image blocks one by one, and the set order in step 3) is in the order of numbers from small to large.
[0027] By first numbering the divided image blocks, and one number corresponds to only one image block, the image blocks can be processed in sequence based on the numbering rule in subsequent steps, thus avoiding the problem of missing the image blocks to be processed.
[0028] Furthermore, in step 1), if the length of the original Tiled Image cannot be divided by the length of the regular rectangular image block of the set size, or the width of the original Tiled Image cannot be divided by the width of the regular rectangular image block of the set size, the length of the original Tiled Image is first supplemented to be divisible by the length of the regular rectangular image block of the set size, and the width is supplemented to be divisible by the width of the regular rectangular image block of the set size, and then divided into multiple image blocks according to the set division rule, and the supplemented part is filled with black.
[0029] Furthermore, in step 1), the number of image blocks divided according to the set division rule is TilesPerImage:
[0030] TilesPerImage = TilesAcross × TilesDown, where TilesAcross is the number of tiles in the width direction, LengthTiles is the number of tiles in the length direction, and TilesAcross = (ImageWidth + TileWidth - 1) / TileWidth, TilesDown = (ImageLength + TileLength - 1) / TileLength, ImageWidth is the width of the original Tiled Image, ImageLength is the length of the original Tiled Image, TileWidth is the width of a regular rectangular image block of a set size, and TileLength is the length of a regular rectangular image block of a set size.
[0031] When calculating the number of tiles in the width direction, the method of the present invention first increases the read image width by the value of (tile width - 1), so as to accurately calculate the number of image blocks in the width direction by rounding the result calculated by the definition formula of the number of tiles in the width direction (that is, if the actual calculation result is not an integer, the actual calculation result is rounded down to obtain the final calculation result, for example, if the actual calculation result is 5.6, the final calculation result is 5). Similarly, the above formula of the present invention can accurately and simply calculate the number of image blocks in the length direction, and then determine the total number of divided image blocks.
[0032] Furthermore, in step 2), before storing the image data of the image block in the TIFF image file, the image block is compressed and then stored. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 It is a schematic diagram of dividing the original data image into tiles;
[0034] Figure 2 This is a schematic diagram of the existing TIFF format;
[0035] Figure 3 It is a flow chart of the Tiled Image image file compression method of the present invention. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is further described in detail below with reference to the accompanying drawings and embodiments.
[0037] Tiled Image image file compression method embodiment:
[0038] The method of this embodiment first reads the image length and width parameters, divides the image into several tiles and uniformly numbers them, establishes blank image data sample blocks, compares the difference between tiles and sample blocks, and then uses the Tiled Images image format to merge blank image data blocks, uses only one storage space for the same redundant space, and all redundant storage offsets point to one position, and finally creates file header information and identification information. The purpose of compressing the file is achieved through the above operations. The method of this embodiment screens the image blocks into which the original image is divided, so that only one image block with the same image data information is retained in the image data of the TIFF image file, and other image blocks that do not have the same situation are also retained in the image data of the TIFF image file. Then, after the method of the present invention, there is no redundancy in the image data in the TIFF image file, which avoids the problem of redundant storage space caused by storing the image data information of the redundant image blocks in multiple storage locations of the image data of the TIFF image file. Then, compared with the existing TIFF format storage method, the method of the present invention reduces the storage space of the TIFF image file.
[0039] In this embodiment, the original image is finally converted into Figure 2 The TIFF image file is stored in the form of a TIFF image file as shown, wherein the specific structure of the file header information area is shown in Table 1, the format of the image file directory IFD in the identification information area is shown in Table 2, the format of the tag in the image file is shown in Table 3, and the description of the important tag ID number in the Tiled Image image file is shown in Table 4:
[0040] Table 1 Format of file header information area IFH
[0041]
[0042] Table 2 Format of image file directory IFD
[0043]
[0044] Table 3 Tag format in image file
[0045]
[0046] Table 4 Description of important TagID numbers in Tiled Image files
[0047]
[0048]
[0049] Based on the above specific TIFF image file format, this embodiment adopts the following Figure 3 The method shown here realizes Tiled Image file compression:
[0050] 1) Read the original image parameters, divide the original image into tiles, and number the divided tiles;
[0051] First, read the image width ImageWidth and image length ImageLength parameters from the image raw data file, and then divide the raw data into tiles from top to bottom and from left to right according to the tile parameters TileWidth*TileLength equal to 256*256 pixels. The right and bottom borders that are less than 256 pixels are filled with black (r=0, g=0, b=0) to expand the border. The number of tiles in the width direction TilesAcross and the number of tiles in the length direction LengthTiles are defined as follows:
[0052] TilesAcross=(ImageWidth+255) / 256;
[0053] TilesDown=(ImageLength+255) / 256;
[0054] The total number of tiles TilesPerImage = TilesAcross*TilesDown;
[0055] In this embodiment, when calculating the number of tiles in the width direction, the read image width is first increased by the value of the tile width - 1 (i.e., 256-1=255), so as to round the result calculated by the definition formula of the number of tiles in the width direction mentioned above (i.e., if the actual calculation result is not an integer, the actual calculation result is rounded down to obtain the final calculation result, for example, if the actual calculation result is 5.6, the final calculation result is 5).
[0056] The split tile data blocks are uniformly numbered in two dimensions, with the numbers arranged from 0 to (TilesAcross-1) from left to right in the width direction and from 0 to (TilesDown-1) from top to bottom in the length direction. For example, the tile numbered (Across, Down) corresponds to the Across+1th tile in the width direction and the Down+1th tile in the length direction of the image.
[0057] In this embodiment, a piece of uncompressed TIFF image data of a mountain is taken as an example, and the image width ImageWidth=209626 and the image length ImageLength=176458 are read from the original data file of the image; the tiles are divided according to the method of tile division of the original image in this embodiment, and the number of tiles in the width direction TilesAcross, the number of tiles in the length direction LengthTiles and the total number of tiles TilesPerImage after the division are:
[0058] TilesAcross=(209626+255) / 256=819;
[0059] TilesDown=(176458+255) / 256=690;
[0060] TilesPerImage=819*690=565110;
[0061] Based on the method in this embodiment, the segmented tile data are numbered in the same two-dimensional manner, that is, the numbers are arranged from 0 to 818 from left to right in the width direction, and the numbers are arranged from 0 to 689 from top to bottom in the length direction. For example, the tile numbered (0, 0) corresponds to the first tile in the width direction and the first tile in the length direction of the image, and the tile numbered (818, 689) corresponds to the 819th tile in the width direction and the 690th tile in the length direction of the image.
[0062] 2) defining a blank image data sample block, and comparing the tiles divided in step 1) with the blank image data sample block; merging tiles with the same image data information as the blank image data sample into the blank image data block, and increasing the storage space of the tile image data information for tiles with different image data information from the blank image data sample;
[0063] The method for defining a blank image data sample block in this embodiment includes the following steps:
[0064] 2.1) Declare a one-dimensional array pTileDataSize for storing tiles, of type 64-bit unsigned long integer, of size TilesPerImage; declare a tile data offset array pOffset, of type 64-bit unsigned long integer, of size TilesPerImage;
[0065] 2.2) Generate a 256*256 pixel blank image data block to store the blank image (r=0, g=0, b=0), the data is recorded as pSpaceSourceData, and generate the corresponding compressed data block pSpaceData according to the specified compression format, and its data size is TileSpaceDataSize;
[0066] 2.3) Create TIFF file header information. First, assume that the offset of the first IFD of the file is 0, and generate a Tiff format file header according to the Tiff format requirements. Record the current file position offset iSpaceOffset. Store the data block pSpaceData, size TileSpaceDataSize, and record the current file pointer position iOffset.
[0067] This embodiment takes into account that black filling will be used for the original image when the original image is divided into blocks, so there will be black tiles with the same image data information after the division. Therefore, in this embodiment, the blank image data sample block is stored in the blank image (r=0, g=0, b=0) to filter out the black block tiles based on the blank image data sample.
[0068] In this embodiment, the divided tile data block is compared with the blank image data sample block by traversing the entire divided tile data block from left to right in the width direction and from top to bottom in the length direction. The specific process is as follows:
[0069] a) Initialize the split tile data block (Across, Down), setting Down=0, Across=0.
[0070] b) Scan and split the original data block (Across, Down), and record the data as pSourceData. Compare the image data in the current original data block (Across, Down) with the data in the blank image data block. If they are all the same, assign values to the following array:
[0071] pTileDataSize[Down*TilesAcross+Across]=TileSpaceDataSize;
[0072] pOffset[Down*TilesAcross+Across]=iSpaceOffset, does not store any data, that is, the original data block of the current block in the image data area of the TIFF file shares the storage space of the blank image data block to reduce redundant space.
[0073] If they are different, increase the image information space, generate the corresponding compressed data block pData according to the specified compression format, record the data block size as TileDataSize and assign it:
[0074] pTileDataSize[Down*TilesAcross+Across]=TileDataSize;
[0075] pOffset[Down*TilesAcross+Across]=iOffset;
[0076] iOffset=iOffset+TileDataSize.
[0077] The storage data block pData has a size of TileDataSize, and the current file pointer position (or offset) is the new iOffset.
[0078] c) Fix the Down value in the original data block (Across, Down) of the current block, increase Across by 1 each time, and repeat step b) until Across = (TilesAcross - 1), completing the storage of the original data block in the Across direction.
[0079] d) Each time Down is increased by 1, and steps b) and c) are repeated until Down is equal to (TilesDown-1), thereby completing the storage of the original data block in the Down direction.
[0080] Also taking a piece of uncompressed TIFF image data of a mountain in step 1) as an example, step 2) of this embodiment is performed, wherein a one-dimensional array pTileDataSize for storing tiles is declared, the type is a 64-bit unsigned long integer, and the size is 565110; a tile data offset array pOffset is declared, the type is a 64-bit unsigned long integer, and the size is 565110. Since the uncompressed format is used this time, the compressed data blocks pSpaceData and pSpaceSourceData are the same. Since each blank image data block consists of three RBG elements, its data size is 256*256*3=196608; based on the above process of creating TIFF file header information in this embodiment, the current file position offset iSpaceOffset (at this time, iSpaceOffset is 20, which is the offset of the first tag corresponding to the image file directory IFD in Table 2). Store the data block pSpaceData, size TileSpaceDataSize=196608, and record the current file pointer position iOffset (iOffset is 20+196608 at this time), and then process the divided tiles and the blank image data sample block according to steps a) to d) of this embodiment, wherein, when the image data in the current block original data block (Across, Down) is compared with the data of the created blank image data block, the result is that they are all the same:
[0081] pTileDataSize[Down*TilesAcross+Across]=pTileDataSize[0]=196608;
[0082] pOffset[Down*TilesAcross+Across]=pOffset[0]=iSpaceOffset=20;
[0083] When the comparison result is different, increase the image information space, generate the corresponding compressed data block pData according to the specified compression format, and record the data block size as TileDataSize. Because it is not compressed this time, it can be copied directly. The size is 196608, and the assignment is as follows:
[0084] pTileDataSize[Down*TilesAcross+Across]=TileDataSize=196608;
[0085] pOffset[Down*TilesAcross+Across]=iOffset;
[0086] iOffset+=196608.
[0087] The data block pData is stored with a size of TileDataSize = 196608. The current file pointer position (offset) is the new iOffset.
[0088] 3) Create the file header information and identification information of the TIFF image file.
[0089] In this embodiment, the current file position IFD_OFFSET is recorded, the file directory IFD is generated according to the TIFF format requirements, IFD_OFFSET is stored in a 64-bit unsigned long integer format, and the file is stored at the current position; the file pointer is moved to position 8 in Table 1, and IFD_OFFSET is stored in a 64-bit unsigned long integer format.
[0090] The method based on this embodiment reduces redundant space. Since the method of this embodiment is only a process of releasing redundant space, the data distortion of the original image is not changed. Therefore, the method of this embodiment can compress data without changing the data distortion. Taking a piece of TIFF image data in an uncompressed format of a mountain as an example, the method of this embodiment is used for compression, so that the original data size of the TIFF image data is 103GB, and the data size is 44GB after compression using the method of this embodiment, and the compression ratio = 103 / 44 = 2.34, that is, the method of this embodiment improves the compression ratio and reduces the storage space for storing image files without changing the compression method.
[0091] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. The patent protection scope of the present invention shall be based on the claims. All equivalent structural changes made using the contents of the description and drawings of the present invention should also be included in the protection scope of the present invention.
Claims
1. A Tiled Image file compression method, characterized in that: The steps include: 1) Divide the original Tiled Image into multiple image blocks according to the set division rules; 2) Among the image blocks with the same image data information, only the image data of one of the image blocks is selected and stored in the image data area of the TIFF image file, and the storage address of the image data is obtained as the storage address corresponding to the image block with the same image data information; the image data of the image block with unique image data information is also stored in the image data area of the TIFF image file, and the corresponding storage address is obtained as the storage address corresponding to the image block; 3) Constructing the file header information and identification information area of the TIFF image file, wherein the data description information of each divided image block is established in the identification information area according to a set order; the address in the data description information is the storage address corresponding to the image block.
2. The Tiled Image file compression method according to claim 1, characterized in that: In step 2), the image data information of the image blocks is stored in the image data area of the TIFF image file in sequence, and before storing, it is determined whether the image data information already stored includes the image data information of the image block to be stored. If so, the image data of only one of the image blocks is selected and stored in the image data area of the TIFF image file without storing the information.
3. The Tiled Image file compression method according to claim 2, characterized in that: The image blocks with the same image data information and the same image are black image blocks.
4. The Tiled Image file compression method according to claim 3, characterized in that: In step 2), the image data information of a black image block is first stored in the image data area of the TIFF image file, and then the image data information of other image blocks are sequentially stored in the image data area of the TIFF image file.
5. The Tiled Image file compression method according to claim 4, characterized in that: When storing image data of an image block with unique image data information, the unique image block is compressed according to a set compression rule and then stored.
6. The Tiled Image file compression method according to claim 1, characterized in that: In step 1), the setting division rule is to divide the image into regular rectangular image blocks of a set size.
7. The Tiled Image file compression method according to claim 6, characterized in that: In step 1), the image blocks are numbered after being divided according to the set division rule, and the image blocks correspond to the numbers of the image blocks one by one. In step 3), the set order is in the order from small to large numbers.
8. The Tiled Image file compression method according to claim 6, characterized in that: In step 1), if the length of the original Tiled Image cannot be divided by the length of the regular rectangular image block of the set size, or the width of the original Tiled Image cannot be divided by the width of the regular rectangular image block of the set size, the length of the original Tiled Image is first supplemented to be divisible by the length of the regular rectangular image block of the set size, and the width is supplemented to be divisible by the width of the regular rectangular image block of the set size, and then divided into multiple image blocks according to the set division rule, and the supplemented part is filled with black.
9. The Tiled Image file compression method according to claim 8, characterized in that: In step 1), the number of image blocks divided according to the set division rule is TilesPerImage: TilesPerImage = TilesAcross × TilesDown, where TilesAcross is the number of tiles in the width direction, LengthTiles is the number of tiles in the length direction, and TilesAcross = (ImageWidth + TileWidth - 1) / TileWidth, TilesDown = (ImageLength + TileLength - 1) / TileLength, ImageWidth is the width of the original Tiled Image, ImageLength is the length of the original Tiled Image, TileWidth is the width of a regular rectangular image block of a set size, and TileLength is the length of a regular rectangular image block of a set size.
10. The Tiled Image file compression method according to claim 1, characterized in that: In step 2), before storing the image data of the image block in the TIFF image file, the image block is compressed and then stored.
Citation Information
Patent Citations
Medical image file compression processing method for reducing file storage
CN115376659A
Method of generating image file
US20090185761A1
Cited By
In-situ streaming replacement compression and recovery method and device in GeoTIFF image block fixing slot, and storage medium
CN122156332A
