Radon Transform for Java

You can read the theory of this transform at this Wikipedia link.

Description

I first heard the name of this transform while reading the article I bought from IEEE to obtain a chessboard grid for programming a function in the ChessPdfBrowser application.

IEEE Article.


This is a library with my implementation of that transform for Java.


The library code is also shared on GitHub. Link to GitHub.

Code description

Since processing is time-consuming, the library provides an executor that returns a Future, to avoid blocking the caller's execution while processing is in progress.

Parallel calculations are easily supported for using multiple threads.


The RadonTransformCalculator class calculates the transform values ​​and stores them in a two-dimensional array.


After processing, the transformation values ​​can be analyzed using the array indices to access them.

These indices can be easily translated to a (Rho, Theta) (ρ, θ) element by calling the function on the result object, which is of type RadonTransformResult.


It is also possible to obtain the N maximum values, giving the option to discard duplicates (different (ρ, θ) that are very close) through a tolerance, and a filter can also be applied at the same time on (ρ, θ) to discard beforehand those that do not meet our conditions.

For example, if you are looking for almost horizontal or vertical lines, and there is a diagonal with a very high value, then that value could be discarded.

Windows

All

Radon Transform for Java (2026)

Download

Examples

image
image

An example is included in the zip file containing the library code, which we will explain below.

This example aims to obtain the sides of the square that defines the chessboard in the target image.

The input image for the Radon transform calculation is an edge detection (Canny type) of the target image.


The transform is calculated for this Canny type image, and then the four main lines are obtained.

This is achieved by calling the function to obtain the highest values ​​of the transform, passing it four as the number of elements to search for.

Additionally, an appropriate tolerance of (ρ, θ) is also passed to discard duplicates, and a filter to discard θ values ​​that are not nearly horizontal or vertical.


In the example, these four lines that define the sides of the chessboard are successfully obtained with these tools.

With the library, the intersections of these lines can be calculated, thus obtaining the vertices.

A vertex sorter is also invoked so that when the lines are drawn sequentially, the "bowtie effect" does not occur.


This vertex ordering is done by iterating through the permutations of the vertex order until the first one that meets the suitability criterion is found.

The chosen criterion is that the vertices in that order define a convex polygon (like the square we want to detect).

To do this, it is necessary to check that the rotation of the vertices is always in the same direction (clockwise or counterclockwise).

To obtain the direction of rotation of three consecutive vertices, simply calculate the sign of the cross product of the two vectors defined by those three vertices.

Therefore, the necessary and sufficient condition for vertices in that order to define a convex polygon is that all ordered subsets of three consecutive vertices (assuming the circular list) have the same sign in the cross product calculated in that way.


After these calculations, we draw the edges that connect the vertices, and we obtain the final image.

Mission accomplished!


image
image

Downloads