## 3 Proposed Method
### Packaging Technique for Image Segments (Data Structure)  
Although the image segments vary in size and shape, they are effectively divided based on similar color and texture characteristics. To enable lossless storage of these segments before compression, a generic data structure was developed. This data structure is not limited to compression tasks but can also be applied to any scenario involving the storage of segmented images, offering a versatile solution to the literature.  
At this stage, the most crucial consideration is minimizing the data size of the package. Without this, the benefits of compression could be offset by the size of the data package itself. To address this issue, the process was designed to function in a modular way by generating two distinct files, each optimized to occupy the smallest possible data size. For this purpose, two data structures, named \"header\" and \"data\", were created for each image. The specifics of the first structure, referred to as \"header\", are illustrated in Figure 5.  
Figure 4: Segmentation process results. (**a**) Input image, (**b**–**k**) image segments.  
The details of the data stored in the \"header\" data structure are comprehensively explained. The first 1-byte field of this data structure stores the information regarding the number of segments (n) into which the image has been segmented.  
The next 12-byte data fields store the following information for each segment: y, number of lines, 1. Huffman header size and 2. Huffman header size, and finally compressed data size. For instance, as shown in Figure 5, the image is divided into three segments. The number of these fields is increased in direct proportion to the total number of segments in the image. Specifically, for each segment:  
* y: the segment's starting position on the y-axis of the image (2 bytes),
* number of lines: the number of rows occupied by the segment along the y-axis (2 bytes),
* 1. Huffman header size: the length of the Huffman header for the segment (2 bytes--explained later),
* 2. Huffman header size: the length of the Huffman header for the segment (2 bytes--explained later),
* Compressed data size: the compressed data size of the segment (4 bytes).  
The next 2-byte field stores the size of each segment along the x-axis for the corresponding y value. The x values and length values stored in this field allow the data for each row of the image to be recorded. As the y value progresses incrementally until the end of the image, its starting value is stored in the previous field to avoid redundancy. The developed data structure ensures that an image can be segmented into parts and accurately reconstructed from the segmented data without any loss. Furthermore, the header data structure remains uncompressed and serves as a reference guide for each compressed image.  
The size of the header data structure was calculated for various images and different numbers of image segments. For instance, a 512 \(\times\) 512 image with 10 segments occupies approximately 10 KB, while a 1024 \(\times\) 1024 image with 10 segments occupies around 20 KB. With increasing pixel count and image dimensions, the header's relative size becomes negligible after compression.  
The details of the data structure named \"Data\" are presented in Figure 6. This structure contains two Huffman headers and the compressed data for each segment. The size of the field content in the data structure is entirely dynamic, as the size of the compressed data for each segment is not predetermined. Consequently, the \"Header\" data structure stores the Huffman header data size and compressed data size for each segment.  
The developed data structure was specifically designed for the storage of image segments and their data. These data structures can also find applications in a wide range of fields that rely on image segmentation.  
Figure 5: Header data structure.