# Focal length correction, or: simulating a perfect flatbed scan using a camera

Is there a ready-made tool (preferrably a Photoshop filter) to correct for geometric distortion caused by finite focal length of the lens?

This is in the context of using a camera to "scan" documents, or photographing a painting or any other flat objects. It is not about barrel distortion or perspective correction (although it is related to the latter): let's assume all these corrections are already made by traditional means and we have a perfectly straight image of (say) our favourite model: a brick wall.

The problem is: that's not enough. Ideally, such an image should be made from an infinite distance by an infinitely long lens. Or, we should be "scanning" it by sliding along both axes, so that the view angle to each point was always right.

Otherwise, if we use a normal lens, and especially, of course, a wide-angle lens, the edges will be stretched compared to the centre. Even if the brick lines are perfectly straight and perpendicular. This stretch is what I want to correct, thereby simulating an infinitely long lens (but again, only in the context of flat subjects).

It is very easy to express what I need mathematically: each point of the image should be compressed with the ratio cos(a) : 1, where a is the angle of view of this point from the camera with respect to the perpendicular from the camera to the subject plane.

Before the image is cropped and otherwise corrected, this sort of correction could be almost completely automated (given the EXIF lens info). However, I haven't seen such correction in the common software. The Photoshop's Adaptive Wide Angle filter is not that. It could be somewhat emulated by warping, but that's unnecessarily complicated yet not accurate.

The correction may be said to be insignificant (<5%) for lens angles 2 * acos(0.95) ≈ 36°, which is about 65 mm focal length (35 mm eq.) (assuming perfectly central positioning of the camera). This is rather moderate, but sometimes one is physically limited to a wider lens, or needs greater accuracy... Given the simplicity of correction, I'd expect it to be common, yet apparently it isn't... Or am I missing something?

AFAIK you are overestimating the problem, at least with some lenses.

Here is a picture:

• Squared paper (5mm squares)
• Shot with Canon EF-S 35mm f/2.8 macro on APS-C camera
• Makeshift copy stand
• Using open source tools, and the lens is not in the database, so applied the correction for another 35mm lens. If you use your camera/lens manufacturer tools, you can get a better correction, and if you use open source tools you can do your own lens calibration.

• The accuracy of scanners (at least the customer kind) may be a bit overrated. The picture above is the sheet I used to check my scanner.
• Well, a lens could be made to distort (or rather correct in this case) for this effect. The correction profile you used could do it too. But in principle, this is a very 'physical' (geometric) effect: it must be present in a 'perfect' rectilinear lens, and it's not fair to correct it 'by default'. (Perhaps more reasonable for a macro lens, but not in general). For your lens, the distortion should be ~7% at the edge, but it's clearly better than that, so something must be at play. // I mention scanner only as a model. Lengthwise, it could be nearly perfect.
– Zeus
Commented Aug 22, 2022 at 0:51

The kind of lens you are describing is called a telecentric lens. Specifically an object-space telecentric lens. Such a lens has the entrance pupil at infinity and provides an orthographic projection instead of the perspective projection in an entocentric lens.

By definition, a telecentric lens must have a front element at least as large as the entirety of the subject, so the vast majority of them tend to be used only on smaller subjects. They're mostly used in manufacturing environments for etching things such as PC boards, rather than for taking artistic or even documentary photos.

Larger ones capable of photographing larger subjects are prohibitively expensive.

Another solution to get an approximate orthographic view is to use a linear motion scan camera¹ (a/k/a parallel motion scan camera) or use a more typical camera to produce a panorama where each shot is taken from a different position opposite the subject's width.

¹ Typically, the object being photographed is moved past the scanning camera at a constant speed, but the obverse can also be the case, such as with aerial or satellite camera platforms that image the surface of the earth as they pass over it.

• This is very interesting, I didn't know about such special lenses. But in their absence, aren't there filters to compensate such distortion in post (from a single, well positioned shot)?
– Zeus
Commented Aug 22, 2022 at 7:49
• Nope. What is hidden from the position of an entocentric lens can't be seen by the lens unless it is moved to a different position. Take a cube, for example. If a lens is centered over one of the six sides of the cube, none of the four sides at a 90° angle to the near side will be visible at all. There's nothing to compensate. The information needed is not contained in the image. Commented Aug 22, 2022 at 10:57
• Now imagine at the foot of a cube are some other articles against the sides of the cube. But those articles are occluded by the top of the cube which is closer to the typical entocentric lens, and thus occupies more degrees of arc than the same size base of the cube that is further away from the lens. The entocentric lens' view is limited by the angle from the lens' optical center to the top edges of the cube. Commented Aug 22, 2022 at 11:03
• Well, that's why I insisted on the flat object case. Some form of document reproduction, where a scanner would traditionally be used. When photographing a flat sheet, everything is visible, just at a different angle - and this angle simply translates to distortion (and consequently linear resolution).
– Zeus
Commented Aug 26, 2022 at 0:46