With the rapid growth of medical image data, there is an increasing need for real-time uploading and storage of these images despite limitations in network bandwidth and storage capacity. However, existing medical image compression technologies are unable to achieve joint optimization of compression rate and image quality (referred to as "rate-distortion" optimization). The primary goal of this study is to maximize the compression of medical images while ensuring high-quality reconstruction. This study utilizes two methods for compressing medical images intended for long-term storage. In the first approach, images are simplified through a hierarchical model that classifies image elements using a neural network. These classified images are then compressed using Huffman coding. The second method employs a prediction-based approach involving deep neural network training. By utilizing a trained neural network, this approach reduces data requirements by estimating pixel positions, with the remaining data compressed using Huffman coding. To reconstruct the images, the compressed data is decoded, and an enhanced spatial filtering technique is applied, followed by reconstruction using the Wild Horse Optimization (WHO) and Gray Wolf Optimization (GWO) meta-heuristic algorithms. This method allows the proposed strategies to function effectively in non-deterministic environments without compromising compression efficiency. The proposed methods successfully simplify medical images, resulting in improved decoding speeds. We achieved a Structural Similarity Index (SSIM) of 0.9637 and a Peak Signal-to-Noise Ratio (PSNR) of 38.196, both indicating high reconstruction quality. Performance metrics were then analyzed in the context of daily practical applications. Compared to existing deep learning-based approaches, our proposed methods provide high levels of compression while preserving excellent image quality.