The document explores a technique for enhancing JPEG image compression through an optimized run length coding method that utilizes sparse matrices to minimize redundancy while maintaining image quality. The proposed method focuses on improving the entropy coding step of JPEG compression and has been tested on various images, showing efficiency in reducing image size without loss of quality. Results indicate that this approach yields better or comparable compression ratios to existing methods, with significant memory savings.