Monday, February 5, 2018

Perspective Transform




Among the various geometric transformations, the Perspective transform is very useful. By default, this transform is not available in Image > Transform. However, it is very easy to implement such a tool...


UPDATE: Perspective Transform was rewritten using the latest version of JavaScript (ECMAScript 2015+).

1. Input image


Fig.1: Distorted image

2. How to unwarp the image

  1. Download the script es6_perspective_transform.js at the end of this post and open it in ImageJ with File > Open...
  2. Then, select four points with the Multi-Points Tool in a zig-zag order as shown in Fig.2.
  3. Fig.2: Selection of four points with the Multi-Points Tool
  4. Finally, run the script, set the size of the output squared image and  the interpolation mode (Fig. 3).
  5. Fig.3: Dialog


  6. Et voilĂ ! Depending of the interpolation mode (None or Bilinear), the rendering may be different.
Fig. 4: Unwarped images with interpolation modes: None (left) and Bilinear (Right). The image calculated with a bilinear mode appears smoother than those with no interpolation.

3. The script

With this new version, the script is split in two parts:
  • (i) The core functions implementing the perspective transform  and located in the file es6_perspective_transform.js.
  • (ii) A main script — warping_main.js — adding a dialog box and calling the core functions.

+++ Javascript:es6_perspective_transform.js +++
+++ End of Script: es6_perspective_transform.js +++

To use the core functions, we assume that you created a directory 0Homemade/ in the ImageJ/plugins folder.

... And, here is an example of use...

+++ Javascript:warping_main.js +++
+++ End of Script: warping_main.js +++

The old implementation for archive...
+++ Javascript:perspective_transform.js +++
+++ End of Script: perspective_transform.js +++

No comments:

Post a Comment