In order to compress medical pictures for long-term storage, two methods are used in this work. The first step is to use a neural network–based categorization system to simplify images using a hierarchical modeling technique. The Huffman cipher is then used to compress the reduced images. In the second method, a deep neural network is trained to make predictions. This method can potentially reduce the amount of data needed to describe a picture by using a trained neural network to make intelligent guesses about the location of individual pixels. Huffman compression is used to encrypt the remaining data. By using an improved spatial filtering method to the picture data, we can decode it and then use meta-heuristic algorithms like gray wolf optimization (GWO) and wild horse optimization (WHO) to rebuild the image. Without sacrificing data compression efficacy, this paves the way for a more practical implementation of the proposed techniques in cases when outcomes are uncertain. Images can be simplified using the suggested approaches, leading to faster decoding. Afterwards, performance metrics were taken and evaluated following predetermined daily procedures. The suggested approaches outperformed state-of-the-art deep learning-based systems in compressing medical images while maintaining an exceptionally high quality level.