Keywords

1 Introduction

Reflection transformation is one of the most basic linear transforms [1]. There are however surprisingly few works that deal with such transforms in the digital world, although they are the key to defining n-dimensional rotations [2]. Digital rotations have many applications such as template matching [3], object tracking [4], etc.

The problem is that digital transforms on square grid are usually not bijective. The goal of this paper is to propose a digital bijective reflection on a two-dimensional image and to use this reflection to propose a digital bijective rotation algorithm that works for an arbitrary rotation center (i.e. bijective digital rigid motion). The main motivation behind this work in n-dimensional bijective digital rotation [2]. Classical methods based on shear matrices proved somewhat difficult to extend to higher dimensions so the idea was to explore digital reflections.

The theoretical discussion on the subject of digital rigid motions is presented in [5]. While the reflection transform in the digital world has not been studied much, digital rotations and more precisely bijective digital rotations has been a point of interest of the digital community for some years now [6, 7]. In [8] a discretized rotation is defined as the composition of a Euclidean rotation with rounding operations. An incremental approach to discretized rotations is presented in [9]. A link between Gaussian integers and the bijective digital rotation is proposed in [10]. In [11], bijective rigid motion in 2D Cartesian grid are discussed. Other mentionable work is the characterization of some bijective rotations in 3D space [12]. The bijective rotation has also been studied on the hexagonal grid [13, 14] and triangular grid [15].

A continuous tranform applied to a digital image is not, in general, bijective, neither injective nor surjective for that matter, even for an apparently very simple transform such as the reflection transform (see Fig. 1). Our idea is to digitize the Euclidean reflection straight line as naive digital lines (i.e. 8-connected digital lines) and to partition the two-dimensional space into naive digital lines that are perpendicular to the reflection line. A central symmetry is performed on the points of each Perpendicular Digital Straight Line (PDSL) according to the Digital Reflection Straight Line (DRSL). This is always possible because we can compute the exact pixel to pixel correspondance on each side of the DRSL for such naive digital lines. The main problem comes from the fact that the digital reflection line and a given digital perpendicular line may or may not intersect and so two different cases have to be considered.

The organization of the paper is as follows: Preliminaries in Sect. 2. Section 3 presents the mathematical foundation of bijective digital reflection. The bijective digital rotation about an arbitrary center can be determined by applying digital reflection twice (see Sect. 4). An error criteria based on the distance between the continuous and the digital rotated points are discussed in Sect. 4.2. The concluding remarks are stated in Sect. 5.

2 Preliminaries

Let \(\{\varvec{i},\varvec{j}\}\) denote the canonical basis of the 2-dimensional Euclidean vector space. Let \(\mathbb {Z}^2\) be the subset of \(\mathbb {R}^2\) that consists of all the integer points. A digital (resp. Euclidean) point is an element of \(\mathbb {Z}^2\) (resp. \(\mathbb {R}^2\)). Two integer points \(p=(p_x,p_y)\) and \(q=(q_x,q_y)\) are said to be 8-connected if \(\left| p_x-q_x\right| \leqslant 1\) and \(\left| p_y-q_y\right| \leqslant 1\).

For \(x\in \mathbb {R}\), \(\lfloor x \rfloor \) is the biggest integer smaller or equal to x and \(\lceil x \rceil \) is the smallest integer greater or equal to x.

A naive digital straight line is defined as all the integer points verifying \(-\frac{max(|a|,|b|)}{2} \leqslant ax - by < \frac{max(|a|,|b|)}{2}\), where \(\frac{a}{b}\) represents the slope of the Digital Straight Line (DSL) and \(\omega = max(|a|,|b|)\) the arithmetical thickness [16]. A naive DSL is 8-connected such that if you remove any point of the line then it is not 8-connected anymore [16]. There are no simple points.

A reflection transformation \(\mathcal {R}_{\theta ,(x_o,y_o)}:\mathbb {R}^2 \mapsto \mathbb {R}^2\) reflects (or flips) a continuous point, like in a mirror, on a continuous straight line called the reflection line. The reflection line is defined as the line with the vector director \(v=(\sin \theta ,\cos \theta )\) passing through a point of coordinates \((x_o,y_o)\in \mathbb {R}^2\). The corresponding digital reflection is denoted \(\textit{R}_{\theta ,(x_o,y_o)}:\mathbb {Z}^2 \mapsto \mathbb {Z}^2\). A continuous rotation \(\mathcal {R}ot_{\theta ,(x_o,y_o)}\) of center \((x_o,y_o)\) and angle \(\theta \) can be defined as the composition of two continuous reflections \(\mathcal {R}_{\alpha ,(x_o,y_o)}\) and \(\mathcal {R}_{\alpha +\frac{\theta }{2},(x_o,y_o)}\). The angle \(\alpha \) is arbitrary.

3 Digital Reflection

3.1 Principle

Let us consider the continuous reflection transform, \(\mathcal {R}_{\theta ,(x_o,y_o)}\). It is not difficult to note that if we simply compose the continuous reflection with a digitization transform (such as for instance \(\mathcal {D}: (x,y) \mapsto \left( \left\lfloor x+1/2\right\rfloor , \left\lfloor y+1/2\right\rfloor \right) \)) then we have a transform that is, in general, neither injective nor surjective (see the middle image in Fig. 1).

Fig. 1.
figure 1

Reflection transform applied to an image. On the left, the original image. In the center, the continuous reflection transform composed with a rounding function. On the right, our proposed bijective digital reflection

To avoid this problem and create a digital bijective reflection transform, a completely digital framework is proposed here based on the following digital primitives:

  • A naive DSL called digital reflection straight line (DRSL);

  • and a partition of the digital space with naive DSLs that are perpendicular to the digital reflection straight line. These digital lines are called Perpendicular Digital Straight Lines (PDSL).

The idea of the reflection method is the following. Let us consider a point p that belongs to a given digital perpendicular straight line \(\textit{P}_k\) (k is a parameter identifying the PDSL in the partition). The point p may belong to the digital reflection line (in case there is an intersection) or lie on either side of that line. Let the digital reflection of p be determined in the following way (see Fig. 2):

  • let us first suppose that p lies in the intersection between the PDSL \(\textit{P}_k\) and the DRSL. Such an intersection does not always exist between the two digital lines but when it does (in this case point p) then the image of p by the digital reflection is p;

  • Let us now suppose that p does not belong to the intersection between the PDSL and the DRSL (whether such an intersection exists or not). The point p is then located on one side of the DRSL: the digital space is split by the DRSL into three regions, the DRSL and two regions on each side of it. All the integer points of \(\textit{P}_k\) on each side of the DRSL can formally be ordered according to the distance to the DRSL with as first point the closest one to the DRSL. As we will see, there actually is no real ordering needed. Let us suppose that p is the \(n^{th}\) point of the ordered list on its side and an integer point q is the \(n^{th}\) point of the list on the other side of the DRSL. The digital reflection of p will then be the point q and vice-versa.

Figure 2 shows the two possible cases: on the left, the perpendicular digital line has an intersection point (the point marked as point 0) with the digital reflection line, while on the right there is no intersection point. The points marked by the number i (from 1 to 5) are images of each other. The image of the point marked 0 is itself. The idea is to create a digital transformation that is bijective and easily reversible. Let us now, in the next section, present the various definitions and mathematical details to make this work out.

Fig. 2.
figure 2

The image of each point is the mirror image in the perpendicular line according to the digital reflection straight line. The image of a point numbered i is the opposite point numbered i. The point numbered 0 is its own image.

3.2 Mathematical Details

Let us consider the continuous reflection \(\mathcal {L}\) line defined by the point \((x_o,y_o) \in \mathbb {R}^2\) and the direction vector \(v=(a,b)=\left( \sin \theta , \cos \theta \right) \). The analytical equation of the reflection line is given by: \(\mathcal {L} = \left\{ (x,y) \in \mathbb {R}^2: a(x-x_o) - b(y-y_o) = 0\right\} \).

The digital reflection straight line (DRSL) the digitization (as naive DSL) of \(\mathcal {L}\) defined as integer points verifying:

$$\begin{aligned} DRSL : -\frac{max(|a|,|b|)}{2} \leqslant a(x-x_o) - b(y-y_o) < \frac{max(|a|,|b|)}{2} \end{aligned}$$

The perpendicular digital straight lines (PDSL) \(\textit{P}_k\) are naive DSLs defined as all the integer points (xy) verifying:

$$\begin{aligned} \textit{P}_k: \frac{(2k-1)\max \left( |a|,|b|\right) }{2} \leqslant b(x-x_o) + a(y-y_o) < \frac{(2k+1)\max \left( |a|,|b|\right) }{2} \end{aligned}$$

It is easy to see that all the PDSLs are perpendicular to the DRSL and that the set of PDSLs, as a set of naive digital lines, partitions the two dimensional digital space.

Let us now suppose for what follows, w.l.o.g, that \(-\pi /4 \leqslant \theta \leqslant \pi /4\), then \(0 \leqslant |a| \leqslant b\) and thus \(\max \left( |a|,|b|\right) =b\). The DRSL is then defined by \(-b/2 \leqslant a(x-x_o) - b(y-y_o) < b/2\) and the PDSLs are then defined by \(\textit{P}_k: (2k-1)b/2 \leqslant b(x-x_o) + a(y-y_o) < (2k+1)b/2\).

The method supposes that we are able to formally order the points of a given perpendicular line that are located on either side of the reflection line. This is always possible because the PDSLs are naive lines and for an angle verifying \(-\pi /4 \leqslant \theta \leqslant \pi /4\), there is one and only one point per integer ordinate y (For angles \(\pi /4 \leqslant \theta \leqslant 3\pi /4\), we will have, symmetrically, one and only one point per integer abscissa x in a given PDSL).

More precisely, \((2k-1)b/2 \leqslant b(x-x_o) + a(y-y_o) < (2k+1)b/2\) means that \((2k-1)/2 +x_o-\frac{a}{b}(y-y_o) \leqslant x <(2k+1)/2 + x_{o}-\frac{a}{b}(y-y_o) \). Since \(\frac{2k+1}{2}-\frac{2k-1}{2} = 1\), there is one and only one value x. For a given ordinate y, the abscissa x in the PDSL \(\textit{P}_k\) is given by the following function:

$$\begin{aligned} \mathcal {X}(y)=\left\lceil \frac{(2k-1)}{2} +x_o-(a/b)(y-y_o) \right\rceil \end{aligned}$$

Let us note that for a given integer point p(xy), it is easy to determine the PDSL \(\textit{P}_k\) it belongs to: \((2k-1)b/2 \leqslant b(x-x_o) + a(y-y_o) < (2k+1)b/2\) leads to \(2k \leqslant 2\frac{b(x-x_o)+a(y-y_o)}{b}+1 < 2k+2\) and thus:

$$\begin{aligned} k=\left\lfloor (x-x_o)+\frac{a}{b}(y-y_o)+\frac{1}{2} \right\rfloor \end{aligned}$$
Fig. 3.
figure 3

The green point represents the intersection point between the continuous reflection line and the continuous perpendicular line. The orange disks mark the two candidate points for the digital intersection. On the left \((x_1,y_1)\) is the digital intersection point between the DRSL and the PDSL. On the right there is no digital intersection point. (Color figure online)

The next question that arises is the determination and the localization of the potential intersection point between the digital reflection line and a given digital perpendicular line. As already mentioned, there may be 0 or 1 digital intersection points between the DRSL and a given PDSL since both are naive digital lines. We propose here a simple criterion to determine the existence of such an intersection point and its localization, if it exists. If the point does not exist, it will yield the closest point of the PDSL to the DRSL on either side of the digital reflection line.

Firstly, let us note that the DRSL is the digitization of the continuous reflection line of equation: \(a(x-x_o) - b(y-y_o)=0\) which lies in the middle of the strip defining the DRSL. In the same way, the continuous straight line of equation \(b(x-x_o)+a(y-y_o)=kb\) lies in the middle of the strip defining the perpendicular digital straight line \(\textit{P}_k\). The intersection point of those two continuous lines is given by \(\left( k b^2+x_o, a b k+y_o\right) \) (since \(a^2+b^2=1\)). It is easy to understand that the only digital intersection point, if it exists, has an ordinate value given by either \(\left\lceil a b k+y_o \right\rceil \) or \(\left\lfloor a b k+y_o \right\rfloor \). This is a direct consequence of the fact that the DRSL is a naive digital line of slope between \(-1\) and 1 and thus with only one integer point per integer ordinate value. We have therefore a very simple test to determine the existence and coordinates of the intersection point (see Fig. 3):

  • let us define \((x_1,y_1)=\left( \mathcal {X}\left( \left\lceil a b k+y_o \right\rceil \right) ,\left\lceil a b k+y_o \right\rceil \right) \) and \((x_2,y_2)=\left( \mathcal {X}\left( \left\lfloor a b k+y_o \right\rfloor \right) ,\left\lfloor a b k+y_o \right\rfloor \right) \)

  • If \((x_1,y_1)\) belongs to the DRSL then there is an intersection point, \((x_1,y_1)\) in this case. A central symmetry of the PDSL points can be performed around the ordinate value \(y_1\). The digital reflection of a point \(p\left( x_p,y_p\right) \in \textit{P}_k\) is given by \(\left( \mathcal {X}(2y_1-y_p),2y_1-y_p\right) \). Let us note here that the central symmetry around the ordinate \(y_1\) does not mean here that there is a central symmetry around the point \((x_1,y_1)\) because space partition would not be guaranteed and thus bijectivity would be lost. The abcissa \(\mathcal {X}(2y_1-y_p)\) is computed so that the reflected point still belongs to \(\textit{P}_k\).

  • Else, if \((x_2,y_2)\) belongs to the the DRSL then there is an intersection point \((x_2,y_2)\). A central symmetry of the PDSL points can be performed around the ordinate value \(y_2\). The digital reflection of a point \(p\left( x_p,y_p\right) \in \textit{P}_k\) is given by \(\left( \mathcal {X}(2y_2-y_p),2y_2-y_p\right) \).

  • Otherwise there is no intersection point and \((x_1,y_1)\) and \((x_2,y_2)\) are the first points of the PDSL on each side of the Reflection line. The central symmetry can be performed around the ordinate value \(\frac{y_1+y_2}{2}\). The digital reflection of a point \(p\left( x_p,y_p\right) \in \textit{P}_k\) is given by \(\left( \mathcal {X}(y_1+y_2-y_p),y_1+y_2-y_p\right) \).

The important point here is that, since there is only one point per ordinate y, a central symmetry on the ordinate leads directly to the reflection point. Algorithm 1 presents the digital reflection transform method.

figure a

3.3 Bijectivity of the Digital Reflection Transform

Algorithm 1 provides a digital reflection method for an integer point. It is not very difficult to see that this defines a bijective digital reflection transform. Let us briefly summarizes the arguments for this:

  • The computation of the value k in line 1 of Algorithm 1 yields the same value for any point of a given PDSL (and only for those).

  • Line 6, 8 and 9 ensure that the image of an integer point of a given PDSL \(\textit{P}_k\) is an integer point belonging to \(\textit{P}_k\). Indeed the ordinate values \(2y_1-y, 2y_2-y\) and \(y_1+y_2-y\) are integers if \(y_1,y_2\) and y are integers and \(\left( \mathcal {X}(y),y\right) \) is, by construction, a point of \(\textit{P}_k\) if y is an integer.

  • The reflection of the reflection of an integer point \((x,y) \in \textit{P}_k\) is the integer point (xy). Let us consider \((x,y) \mapsto \left( \mathcal {X}(y'),y'\right) \mapsto \left( \mathcal {X}(y''),y''\right) \) where \(y'=2y_1-y\), \(y'=2y_2-y\) or \(y'=y_1+y_2-y\). Let us note first that \((x,y)=\left( \mathcal {X}(y),y\right) \). For all three cases, we have respectively \(y''=2y_1-y'=2y-1-(2y_1-y)=y\), \(y''=2y_2-y'=2y_2-(2y_2-y)=y\) and \(y''=y_1+y_2-y'=y_1+y_2-(y_1+y_2-y)=y\) which proves the point.

4 Reflection Based Rotation

As mentioned in the preliminaries, a continuous rotation transform \(\mathcal {R}ot_{\theta ,(x_o,y_o)}\) of center \((x_o,y_o)\) and angle \(\theta \) can be defined as the composition of two reflections based on two reflection lines passing through \((x_o,y_o)\) with an angle \(\theta /2\) between the two lines. In the same way, we define the digital rotation by:

$$\begin{aligned} \textit{R}ot_{\theta ,(x_o,y_o)}(x,y) = \left( \textit{R}_{\alpha +\frac{\theta }{2},(x_o,y_o)} \circ \textit{R}_{\alpha , (x_o,y_o)}\right) (x,y) \end{aligned}$$

Compared to previous digital rotations methods [6, 9, 13, 17], there is an extra parameter that comes into play: the angle \(\alpha \). Each value of \(\alpha \) defines the exact same continuous rotation although not the same digital rotation. Let us note as well that, since the digital reflection transform is bijective, the digital rotation based on the reflection transforms will be bijective as well. Furthermore, the inverse transform is easily defined. This last point may seem obvious but it is not because a digital transform is bijective that the inverse transform is easily computed.

4.1 Rotation Evaluation Criteria

In order to evaluate the “quality” of such a digital rotation, let us present some simple error measures [6]. Each grid point has one and only one image through a bijective digital rotation but that does not mean that the digital rotation is a good approximation of the continuous one. To measure how “wrong” we are by choosing the digital rotation over the continuous one, we are considering two distance criteria that were proposed in [6]. The considered distance is the Euclidean distance. Let us denote \(\mathcal {R}ot_{\theta (x_o,y_o)}(p)\) the continuous rotation of center \((x_o,y_o)\) and angle \(\theta \) of a grid point \(p \in \mathbb {Z}^2\) and \(\textit{R}ot_{\theta ,(x_o,y_o)}(p)\) the digital rotation of center \((x_o,y_o)\) of a grid point p. The Maximum Distance quality criteria (MD) consists in computing \(\max _{p\in \mathbb {Z}^2} \left( d(\mathcal {R}ot_{\theta ,(x_o,y_o)}(p), \textit{R}ot_{\theta ,(x_o,y_o)}(p))\right) \). The average distance quality criteria (AD) consists in computing \(avg_{p\in \mathbb {Z}^2} \left( d(\mathcal {R}ot_{\theta (x_o,y_o)}(p), \textit{R}ot_{\theta (x_o,y_o)}(p))\right) \), where \(avg_{p\in \mathbb {Z}^2}\) is the average distance over the grid.

The idea is to measure what error is made by using the digital rotation instead of the continuous one in terms of (Euclidean) distance to the optimal position (to the continuously rotated point). Let us finish by noting that for the best known digital bijective rotations [10, 11, 17] and for the angles where the digitized rotations are bijective (except for the trivial \(k\pi /2\) angles), the maximum MD values are \(\frac{\sqrt{2}}{2} \approx 0.7\) and the AD values are \(\approx 0.3\). Note also that this method is not bijective for all angles. Other notable methods, that work for all angles, based on shear matrices [6, 7], have MD values of \(\approx 1.1\) and AD values of \(\approx 0.6\).

4.2 Evaluation Analysis

It is difficult to give a completely detailed rotation evaluation here due to lack of space as there are four different parameters that can influence the outcome of the evaluation criteria: the center coordinates \((x_o,y_o)\) and the angles \(\theta \) and \(\alpha \).

Fig. 4.
figure 4

Rotations of center (xy), angle \(\pi /8\) and \(\alpha =0\)

Fig. 5.
figure 5

For each rotation angle \(0\leqslant \theta \leqslant \pi /4\), the average error measures of 500 rotations with random center and respectively \(\alpha =0\) and random \(\alpha \) (with \(0 \leqslant \alpha \leqslant \pi /4\))

Fig. 6.
figure 6

Rotation of the Lena image by various angles and randomly chosen center.

At first, we wanted to have an idea on the effect of the rotation center on the rotation error measure with the angle \(\alpha =0\) and \(\theta =\pi /8\). This means that the first reflection corresponds to a reflection with the continuous reflection line \(y=y_o\), for \(-1/2 \leqslant y_o < 1/2\) and the digital reflection \(y=0\). In Fig. 4 we represented the influence of moving the center on the interval \([0,1/2]^2\). As can be seen, the error measures are almost not affected by the shift on the ordinate but greatly by a shift on the abscissa of the rotation center. This can be explained by the fact that the shift on the perpendicular lines has a direct influence on the lateral error that adds up to the global error. Let us note that the surfaces are similar looking for other couple of angles \((\alpha ,\theta )\) even though the amplitude of the error measure may be different.

Next, we wanted to have an idea on the effect of the angle \(\alpha \) on the rotation error measures. Although the angle \(\alpha \) always defines the same continuous rotation, it changes the digital rotation. So, for each rotation angle \(0\leqslant \theta \leqslant \pi /4\), the average error measures for 500 rotations with randomly chosen center and respectively angle \(\alpha =0\) and a randomly chosen angle \(0\leqslant \alpha \leqslant \pi /4\). The result can be seen in Fig. 5. It can be seen that the angle \(\alpha \) has only a minor influence on the average error but the maximal error is typically significantly increased for an angle \(\alpha >0\). It is interesting to note that this is not always so clear: the digital rotation of angle \(\pi /6\) and center (0, 0) has an average / maximum error of (0.6367, 1.3972) for \(\alpha =0\) and (0.5726, 1.4186) for \(\alpha =\pi /6\). What can be noticed as well is that the error ratio between \(\alpha =0\) and random chosen \(\alpha \) is relatively stable over all the rotation angles. The error measures in general are significantly higher than those obtained for the shear based method [6] that is also defined for all angles and centers. The reflection based rotation is however easier to implement for arbitrary centers: see [6].

5 Conclusion

A novel bijective digital reflection transform in two dimensions has been proposed. The reflection line is defined by an arbitrary Euclidean point and a straight line passing through this point. A rotation can be defined by the composition of two reflections, and so an associated new bijective digital rotation transform has been proposed. This new bijective digital rotation is defined for all angles and for all rotation centers, defining a rigid motion transform (see Fig. 6 that illustrates the rotation of an image at various angles and centers). In average the distance between a continuously and a digitally rotated point is about 0.8 (for a pixel of side 1) which is more than for other known methods. However, this method is much simpler to implement for arbitrary centers and this reflection based rotation seems better suited for extensions to higher dimensions which is not easily done with previous methods. This is the main perspective for the future: exploring digital reflection based bijective rotations in three and higher dimensions.