Statistical mechanics of image restoration