Jigsaw restoration algorithm