Compressing medical images with minimal information loss