Image compression algorithm