A Fast Algorithm to Compress Gray Level Images