Image processing algorithm