Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to reproduce the image of a painting printed in a heavy book. This circumstance makes impossible to use a flat bed scanner for the job. So I am using a handheld one.

After several tries I have obtained quite decent images, but not one of them is perfectly rectangular as the original is. Because of the irregularities in my driving of the scanner, the sides of the image are not ortogonal and are also slightly ondulated. It is not much but, when one fits it in a true rectangle, there remain small white kind of wedges around the sides.

I can conceive of a couple of methods for solving the problem in some way:

  • keep the (bigger) enclosing rectangle size, fill the blanks with surrounding material via some kind of cloning tool and finally reduce the size to the original one;

  • select one corner, rotate the image around it in the required measure, make a smaller rectangular selection, crop what does not fit in it and expand the rest to the required final size.

But both of them would give as a result a copy slightly (in this case) unfaithful to the original, something that I do not want: I want to get the full image of the original painting. On the other hand such an adulterated outcome does not seem to be unavoidable, as all the right pixels are there, only a little displaced. Can some clear and expert mind suggest to me some general approach that could be followed to rectify in due form these deviations? I am using Gimp for it but, as this same question shows, not very proficiently.

share|improve this question

You could try the "perspective" tool. I must admit I have never used GIMP, but this seems to be the same tool as I would use in Photoshop.

share|improve this answer

The proper term for what you are wanting to do is called deskewing. Deskewing fixes the perspective issues you are having by using a handheld scanner. It also typically involves resizing the image back to its original print size as well. This is common in architectual and aerospace fields when converting paper/mylar prints into digital versions. Tools like Gimp and Photoshop can do this, but require a delicate touch to avoid artifacts on the produced image.

The tool we use is called VPStudio, and it made for the purpose of manipulating blueprints.

It's probably overkill for this situation though(and extremely expensive!) You'd probably be better off with some Gimp or PS plugins. One i found, aptly titled Deskew is for gimp. I haven't given it a try but it may be what you're looking for.

share|improve this answer

Have a look at Gimp's cage transform tool, it has been introduced in version 2.8. An accurate mesh of many polygons might help you with roundish distortions near the center of the book.

share|improve this answer

It has taken me some time to get the materials suggested by you all, assimilate them and try some of them. I thank you very much for your help. I think that I have learnt quite a few things in the process, so that I will try to sythetize them here just in case they could be of some help to someone else in the future. I regret that they have to be rather verbose to pretend any utility at all.

The nature of the problem

The first thing that I see more clearly now is the nature and the causes of my original problem.

The handheld scanner has two sources of image distortion that the flatbed one does not:

1) irregularities in the velocity of its forward displacement (which will influence the number of resulting scan lines and its contents) and

2) lateral deviations from the initial direction of the scan (which will deform the image's perimeter).

The first one will be seldom detectable to the unaided eye if present only in small amounts, unless the subject matter provides strong helping clues (like some kind of grid or reference lines). The perception of the second will be on the contrary usually unavoidable, given the mathematical exactness that should have the contour of the resulting image (rectangle or square) and the extreme sensitiviness of human vision to squareness.


Fortunately neither of these devices can have problems related to perspective, as none of them generates its image by conical or pyramidal projection through pointlike apertures (stenope, pinhole, lens system). Its optical mechanism provides ideally a contact copy (in old photographic terms) of the original. The surfaces of the object and image planes are parallel and therefore cannot produce perspective distortions (which are consequent to distances and angles intervening between them). What is more, each pixel of the sensor has its own exclusive aperture for itself so that posible perspective problems would be limited to its minuscule individual area. The perspectival aspects of paintings and photographs extend on the contrary to the whole surface of the image.

Therefore the tools provided by image manipulation programs for handling perspective issues (in its proper sense) are not pertinent to this case. As well the Tools / Transform tools / Perspective tool as the very well conceived and exemplarly documented Ez perspective filter of Gimp ( deal with the image as a whole, as they should do, whereas what the problem under consideration usually requieres is the manipulation of just some part of it.


Although I am not sure of the proper technical meaning of this term, as I have seen it used loosely in different contexts, I conclude that the more common one would refer to the angle that the whole image or some subset of it (for instance a text column) makes in some direction with the system of coordinates currently operative as reference. Of course the present problem implies skews in this sense also, but the important ones are determined by its relation to the straight parts of the same image and much less to the axes of the coordinate system.

Therefore the deskewing algorithms that I have been able to examine are also unsuitable for the task, as they deal with the whole image and take care only of its rotation as such. In the case of Gimp's obscure, difficult to get and undocumented deskew plugin all it seems to be able to do is to perform automatically small rotations of the whole image around its geometrical center (

The appropriate tools

So is there no way out of the difficulty? No, I think that there are enough. As the problem under consideration is one of partial image distortion, its solution must necessarily come from the application of a neutralizing complementary distortion at the right places and in the right measure.

Gimp has several complements that can be used for this: Filters / Map / Displace, Filters / Map / Warp, Filters / Generic / Convolution matrix or Filters / Distort / Curve bend. But all of them are quite subtle to understand (especially because Gimp's pedagogical materials keep being much poorer than the program after so many years) and difficult to apply, although for different individual reasons. They can do the job but they require a lot of effort and patience in their application. Its use should better be compared to the old procedure of retouching negatives or paper positives manually than to the effortless automatic performance which we have come to expect nowadays of magical computer algorithms.

But one can learn a lot by studying and applying them. Just reflecting about how one should structure an eventual Gimp script or complement that helped to perform programmatically this operation would be a nice and instructive exercise.

Concluding (practical) remarks

  • the graphical reproductions obtained with handheld scanners will almost always be affected by distortion of several kinds in variable amounts. Such distortion is aleatory and nonlinear and therefore very difficult to remove by procedural rules (algorithms) of an elementary nature. Through the retouching process one can only aspire to replace one kind of distortion with another less objectionable.

  • if it is unavoidable to use such devices for demanding work, one has to ponder the relative convenience of these two ways of behaving: either to make as many trials as necessary until obtaining one result that is passable (or can be made so with elementary manipulations only) or to devote a lot of time and skill to rectify the bigger distortions of a faulty one with the generic deformation tools available in contemporary image manipulation programs. Or both.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.