# Image Storage in DNA by an Extensible Quaternary Codec System
## 2 Materials and Research Methods  
### Encoding  
The encoding framework of the ETQ is illustrated in Figure 2. It is well known that compressing image data is necessary for storage; however, compression can result in a significant loss of image quality when errors occur. To mitigate this, conventional methods typically add up to 30% error redundancy [1; 20], which significantly increases the cost of DNA storage. To reduce redundancy and save costs, we divide the image into RGB color channels, encode and store them separately, and use a 3 nt block to represent the RGB color information of each image. The probability of simultaneous errors occurring in multiple channels for the same pixel is extremely low, and decoding errors can be detected using majority rule color correction [12]. Thus, this design treats storing different color channels as a proxy for redundant encoding. By dividing the image into three sub-images corresponding to RGB channels, redundancy is reduced.  
The subsequent step employs a Hilbert space-filling curve, which transforms the 2D pixel matrix into a 1D pixel vector while preserving the local similarity and smoothness of the 2D image. This results in linear strings with minimal differences between adjacent entries [21], making it suitable for images of various scales.  
Taking the R channel as an example (the same process applies to the other two channels), the encoding begins by using the Hilbert space-filling curve to convert the 2D image data into a 1D sequence. This approach is suitable for images of various scales. Next, a quaternary Huffman tree is constructed to encode the data (as shown in Figure 3).  
1. Probability Calculation: The probability of the occurrence of each pixel value in the image is calculated and used as the weight of the leaf nodes of the Huffman tree. The nodes are sorted in ascending order of their weights (from bottom to top).
2. Tree Construction: The four nodes with the smallest weights are sequentially encoded as A/T/C/G. The weights of these four nodes are summed, and the result is used as the weight of a new node to construct the next level of the Huffman tree. This process is repeated until all nodes are encoded. The resulting sequence is denoted as seq_init.
3. Metadata Generation: The initial encoded sequence is analyzed to generate an information table and a tree table, which are stored in the computer to enhance decoding accuracy.  
Biochemical Constraints: Due to limitations in DNA synthesis and sequencing technologies [22; 23; 24], biochemical constraints must be applied to the initial sequence. The ETQ system adopts a two-step extended mapping strategy:  
* CG Content Control: A 5-to-6 mapping is used, grouping every five bases and mapping them to six bases with a GC ratio close to 50%.
* Homopolymer Length Control: Sliding windows are applied to replace homopolymers of \"CCCC\", \"GGGG\", \"TTTT\", and \"AAAA\" with \"ATGCC\", \"ATGCG\", \"ATGCT\", and \"ATGCA\", respectively, ensuring a controlled homopolymer length.  
The final encoded sequence is thus obtained. However, a DNA storage system requires the synthesis of specific DNA sequences, followed by the preservation, amplification, and sequencing of DNA molecules. These processes may introduce random and systematic errors, posing challenges to the reliability of the DNA data. To address these issues, appropriate error correction schemes are required to add error correction sequences to the encoded DNA fragments. At present, almost all error correction methods rely on redundancy--both physical and logical--to ensure the accuracy of information recovery [11; 14; 25].  
Figure 3: The illustration of quaternary Huffman encoding for image data storage, focusing on the conversion of pixel values into nucleotide sequences.  
Figure 2: The process of encoding an image into DNA via the ETQ codec.