Keywords

AMS classification. 68R15.

1 Introduction

1.1 Drawing Lines

A screen can be schematized as a grid of small unit square pixels \({\mathfrak P}\), naturally white but which can be colored in various ways. The most natural way to represent a segment is to blacken the squares encountered by this segment. It is not the one that is chosen in practice, probably for aesthetic reasons. The method adopted dates back to the 1960s and was proposed by Bresenham: a pixel \({\mathfrak P}\) is blacked when the line (with a slope lower than 1) encounters the small horizontal segment joining the midpoints of the horizontal sides of the square (See Fig. 1 ex. 2), and similarly with the small vertical segment for slopes greater than 1.

In practice, it will also be considered that the pixel can be grayed with various levels of gray in finite number.

In the following, we will consider dynamically the segments, starting at the origin (0, 0) and ending in some integer point (qp), or half-lines originating from (0, 0) and of any slope, whether rational or not. This slope will always be positive, the other cases will naturally deduce from it. We use lines for these two cases.

The unit pixels composing the screen grid are considered to be centered at the integer points. The hypothesis of putting the integer points at the vertices of the squares can also be made, and the results adapted.

1.2 Our Concept: The Active Multi-pixel

Definition 1

An active multi-pixel is an increasing sequence of closed sets:

$$\begin{aligned} \begin{array}{l} (0,0) \in {\mathfrak A}_n \subset \ldots \subset {\mathfrak A} _2 \subset {\mathfrak A}_1. \end{array} \end{aligned}$$

In practice, n corresponds to the maximum level, that is, black.

When \(n=1\), which corresponds to a single level of gray that will be black, we will call it an active pixel.

When \(n=1\) and \({\mathfrak A} \subset {\mathfrak P}\), we will call it a strict active pixel.

1.3 Representation of a Segment Using an Active Multi-pixel

The line is drawn by blackening the starting pixel at the origin and then with the gray level i the center pixel (nm) as soon as the segment passes through the translated set \({\mathfrak A }_i + \overrightarrow{(n,m)}\), the i being the maximum index with this property.

In the case of an active pixel, all the pixels corresponding to the translates of the active pixels crossed by the segment are blackened.

1.4 Coding the Lines

The line can then be described by the finite or infinite sequence of the symbols corresponding to the translations going from one colored pixel to the next one, adding if necessary the gray level when \(n \ge 2\). Thus the alphabet used is therefore a subset of \({\mathfrak T} \times \{ 1,2, \ldots , n \}\) where \({\mathfrak T}\) is the set of translations of positive integer vectors. We obtain what is conventionally called the Freeman Code, [9], denoted here by FC, each letter in this finite or infinite sequence coding the translations, and possibly being indexed by the level of gray.

Subsequently, movements - which are translations of an integer vector - can be viewed in geographical terms from the four elementary movements: N for to the North, i.e., upwards, S, E, W which combine. These codes are known in two very classical cases, linked to the question of the possible neighbors of a pixel:

  • the case with four neighbors, where the possible movements are N, S, E, W. This corresponds to the simplest case and appears at first, [9]. In the case which is ours (positive slope and movement to the right and upwards), only N and E are used;

  • the case with eight neighbors, where we also allow the diagonal movements NE, NW, SW and SE, as found in [16]. Here too we need only N, E and NE.

In the following we will encounter more complex cases:

  • the case with sixteen neighbors, where we add to the previous ones the eight possible movements of the rider in the chess game, NNE, NNO, etc. As before we need only movements N, E, NE, ENE, NNE. In practice, we will symbolize these five movements by the letters abcde respectively.

Similar approaches are found in many authors, for example in [8] or [17], as well as higher dimensional analogues, [5]. In all cases we describe the line using a word that codes it, and we get discrete lines in the sense of Réveilles [15].

2 Some Examples

2.1 General Examples

We give some examples of drawing for the segment joining the integer points (0, 0) and (5, 2), the chosen active multi-pixel is given on the right.

Fig. 1.
figure 1

Strict active pixels

The corresponding FC are respectively abaaaba, and acaca in the last two cases.

Fig. 2.
figure 2

Active pixels

The FC is dad in the first case, and we need more letters for the others. We denote by fg the translations SSE and SE respectively. Then bbfbbfbbgbbfbbgbbfbbfbb is a possible code in the second case (others are possible). The third one needs a new letter for the translation SSSE. The second and third active pixels can be used for drawing bold lines (Fig. 2).

Fig. 3.
figure 3

Strict active multi-pixels with two levels of gray

Here letters must be indexed by the level of gray FC (\(1=\) gray et \(2=\) black), and we get the FC \(a_2b_1a_2a_2a_1b_2a_2\) et \(a_1b_1a_2a_2a_1b_1a_2\) (Fig. 3).

Fig. 4.
figure 4

Active multi-pixels with three levels of gray

2.2 Cutting Sequence

It is a matter of considering the active square pixel \({\mathfrak A}={\mathfrak P}\), as given in the first example of Fig. 1. In practice, therefore, the pixels encountered by the line are blackened. The associated FC has been widely studied in a slightly different context, it is called classically Cutting Sequence, denoted here by CS, even if this term is normally used for the case where the origin is put on a vertex of the unit square. The reader will find in [1] or [2] broad presentations of this concept.

It is easy to build the CS, using the two following results.

Proposition 1

Let u be the CS of the segment ending at the integer point (qp). Then the CS of the segment ending at (nqnp) is equal to \(u^n\).

Proposition 2

The CS of the segment ending at (qp) is the word of length \(|u|=p+q\) which can be obtained starting from the word \(a^qb^p\) and iterating the following process:

  • take the word \(a^qb^p\);

  • replace it by the new word obtained by the 3-2-decimation of its third power;

  • stop when the new word is the same as the former one;

  • if this last word is not a palindrome, then compare it with its reverse or mirror word (i.e., the word obtained by writing the letters in the reverse order) and replace any block ab corresponding to a block ba in the reverse word by c.

The 3-2-decimation of the word u consists in keeping only the letters a whose rank between the a’s of the word (u) is equal to 2 modulo 3, and making the same for the letters b.

This method is similar to those given in [10] or [3].

2.3 Bresenham Method

It consists in using as an active pixel the diamond, which connects the middles of the four edges of the unit square, as in Example 2 of Fig. 1. Indeed, crossing the vertical segment or crossing the diamond are equivalent properties for a straight line with a slope lower than 1, and we have the corresponding result when the slope is higher.

The computation of the FC can be done from the previous case, but with a small modification: in fact, it is the image by a simple transducer of \(u^2\), see [4], where u is the classical CS, i.e., putting the origin on a vertex. This classic CS is obtained as before, but by taking 2-2 or 3-3-decimation.

2.4 A Particular Case: The Strict Active Pixel

It is clear that when the active pixel \(\mathfrak A\) is contained in the unit square \(\mathfrak P\), then the blackened or grayed pixels are among the blackened pixels of the CS. Thus we can only indicate for each of these pixels whether it is blackened or not (\(n=1\)) or what is its level of gray, which amounts to coding this level on the alphabet \(\{0,1,\ldots ,n \}\). For the segment that links (0, 0) to (qp) it is therefore of length \(p+q\).

3 Properties of Active Pixels

For simplicity, active pixels with no intermediate gray levels will only be considered in this section.

3.1 Equivalent Pixels

Definition 1

The positive convex hull of an active pixel \(\mathfrak A\) is the intersection of the closed half-planes containing \(\mathfrak A\), whose boundary line has a positive or zero slope.

Two active pixels with the same positive convex hull are said to be equivalent.

It means that we add to the classical convex hull the SW et NE corners, as it can be seen on Fig. 5 below.

Fig. 5.
figure 5

An example

A line or a segment of positive slope passes through an active pixel if and only if it passes through its positive convex hull. The FC of a segment or of an half-lines depends therefore only on the positive convex hull \(\widetilde{\mathfrak A}\) of \(\mathfrak A\). The two will then be confused in the following.

Fig. 6.
figure 6

Four equivalent active pixels

The second pixel in Fig. 6 corresponds to the classic case of the diamond (see for example [12]) and the fourth is its positive convex hull. It corresponds to the classical case of the four neighbors [16], as well as to the Bresenham method, as seen on the first form, [7].

3.2 Diameters

Definition 2

The diameter seen from the angle \(\theta \) of an active pixel is the length of its orthogonal projection on the line of polar angle \(\theta + \frac{\pi }{2}\). It is denoted by \(\delta _{\theta } \).

We give three examples.

  • When \(\mathfrak A\) is a disk its diameters \(\delta _{\theta }\) does not depend on \(\theta \).

  • When \(\mathfrak A=\mathfrak P\) is the unit square \(\delta _{\theta }=\sin \theta + \cos \theta \), so when \(0\le \theta \le \frac{\pi }{2}\) the diameters vary between 1 and \(\sqrt{2}\), see Fig. 7.

  • When we take the diamond, \(\delta _{\theta }=\max (\sin \theta ,\cos \theta )\) and the diameters vary between \(1/\sqrt{2}\) and 1, see also Fig. 7.

Diameters \(\delta _{\theta }\) of equivalent active pixels are obviously the same for \(0\le \theta \le \frac{\pi }{2}\).

4 The Size of the Languages

Here, too, will be only considered to simplify strict active pixels. The results may be generalized, the constraint then holds on the exterior part \(\mathfrak A_1\), and must be written in a slightly different way.

4.1 FC of a Line

Proposition 3

The FC of any segment linking two integer points or any half-line starting from an integer point is written on a finite alphabet, unless it is empty.

A segment meets the two active pixels associated with its extremities, so its FC is non-empty and of course finite. The same is true for an half-line with rational slope. Finally, for an half-line with an irrational slope, two cases may occur essentially:

  • \(\mathfrak A\) is the point (0, 0), and the FC is empty or does not exist;

  • \(\mathfrak A\) contains a small open disk around the origin, and the line encounters an infinite number of translated active pixels, with a bounded return time. It implies that the FC uses a finite number of letters.

4.2 FC in the Neighborhood of a Line

Proposition 4

For any positive number \(\rho \), there exists some neighborhood \(\rho \,\pm \, \varepsilon \) and some finite alphabet \(\mathcal A\) such that all the FC of any segment or half-line whose slope belongs to this interval can be written using \(\mathcal A\).

4.3 The Set of All the FC

Proposition 5

The set of all FC of segments and half-lines can be written on a unique finite alphabet \(\mathcal A\) if and only if the diameters \(\delta _{\theta }\) of the active pixel \(\mathfrak A\) satisfy:

  • \(\delta _{-\frac{\pi }{4}}=\sqrt{2}\);

  • \(\delta _{\frac{\pi }{4}} \ge \frac{\sqrt{2}}{2}\).

Then we can choose \(\mathcal{A} =\{ a,b,c,d,e\}\), corresponding to the five elementary moves E, N, NE, ENE, NNE.

The first condition means exactly that the two points \((-1/2,-1/2)\) and \((1{\slash }2,1{\slash }2)\) belongs to the convex hull of the active strict pixel, that is to say that \(\mathfrak A\) reaches the four edges of the unit square \(\mathfrak P\).

The proof of this Proposition uses the notion of visible active pixel: a translated active pixel \({\mathfrak A} +\overrightarrow{(q,p)}\) is visible from \(\mathfrak A\) when there exists some segment linking these two active pixels and not crossing any other translated active pixel.

We easily get that the FC only uses the alphabet of visible active pixels, and a density argument shows that all its letters must be used for some segments or half-lines. Then some elementary geometrical considerations gives Proposition 5.

The active strict pixel \(\mathfrak A\) given in Fig. 5 is an example of a five letters alphabet. In this case each occurence of the letter d or e correspond to some discontinuity in the drawing.

4.4 Some Examples

  • For any CS we need letters a and b except for horizontal or vertical segments or half-lines. Letter c only appears when the line passes though a semi-integrer point, i.e., a point on the grid. It corresponds to a segment or half-line with an odd rational slope, i.e., with odd numerator and denominator.

  • For Bresenham Method, the letters a and c both appears for a slope between 0 and 1, and the letter b appears only for rational slope with an odd numerator and an even denominator. If we choose to remove the point \((1{\slash }2,1)\) from the diamond, letter b no longer appears.

    For a slope greater to 1 we get the same result permuting letters a and b.

  • If we consider the disk of diameter 1 as the strict active pixel, the three letters abc are needed for all FC, except for rational slope with sufficiently small numerator and denominator in irreducible form.

5 How to Compute the Freeman Code

5.1 Automatic Computation of the FC

We have seen before in Proposition 2 that the CS can be easily computed, so we are interested in the possibility to use this CS to compute the FC associated with arbitrary active multi-pixel. However, it is not possible except in some special cases.

Theorem 1

There exist a given transducer \(\mathcal T\), depending only on the active multi-pixel, such that the FC of any line is the image by \(\mathcal T\) of its CS u (half-line) or some power \(u^n\) (segment) if and only if the following properties are true:

  • the global part \(\mathfrak A_1\) of the active multi-pixel satisfies the properties of Proposition 5;

  • for all \(1\le i\le n\) the sets \(\mathfrak A_i\) are polygons whose vertices have rational coordinates with odd denominators.

This result is proven in [4], in a sligthly different context and for a strict active pixel only. The general proof is similar.

5.2 The General Case: The Matrix of Factors

We consider only strict active pixels for simplicity reasons. The dynamical system corresponding to any line is an intervalle exchange transformation, the number of intervals involved being the number of different letters. These transformations have been introduced by Keane and Rauzy in the 70’s, see [11] or [14], and intensively studied. Using this general principle, we can get the FC corresponding to any strict active pixel.

The process is shown in the case corresponding to the segment joining (7, 3), and when the active pixel is the disk of diameter 1, generalization is easy.

Step 1: build a square matrix of letters, putting seven times letter a then three times letter b vertically in the first column, and shifting upward the b’s in the successive columns:

$$\begin{aligned} \begin{array}{llllllllll} a&{}a&{}a&{}b&{}a&{}a&{}b&{}a&{}a&{}b\\ a&{}a&{}b&{}a&{}a&{}a&{}b&{}a&{}a&{}b\\ a&{}a&{}b&{}a&{}a&{}b&{}a&{}a&{}a&{}b\\ a&{}a&{}b&{}a&{}a&{}b&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}a&{}b&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}b&{}a&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}b&{}a&{}a&{}b&{}a&{}a\\ b&{}a&{}a&{}a&{}b&{}a&{}a&{}b&{}a&{}a\\ b&{}a&{}a&{}b&{}a&{}a&{}a&{}b&{}a&{}a\\ b&{}a&{}a&{}b&{}a&{}a&{}b&{}a&{}a&{}a \end{array} \end{aligned}$$

The coefficients \(c_{i,j}\) of this matrix are equal to b when \( i+3j\equiv 1,2,3(\mathrm {mod}~{10})\) and a elsewhere. Rows are exactly the factors of length 10 of the parallel half-lines, written in lexicographic order. Such a matrix is connected with the Burrows-Wheeler transformation, and has been studied by many authors, see [6, 13] for example. We get easily the following properties.

Proposition 6

  • Two consecutive rows differ exactly on a block ab (in the upper row) which gives a block ba (in the lower row). Then the corresponding intermediate row is given by replacing this block by a single letter c.

  • The classical CS corresponds to the common part of the consecutive rows ending by different letters. In our case, it corresponds to the third and the forth rows, which gives aabaabaa for the classical CS.

  • The CS corresponds to the row in the middle when \(p+q\) is odd, or the intermediate row between the two middle rows when \(p+q\) is even.

Step 2: As said in Proposition 6 we get the CS by taking the two middle rows (\(p+q=10\) is even), so here we take the fifth and the sixth rows:

$$\begin{aligned} \begin{array}{llllllllll} a&{}b&{}a&{}a&{}a&{}b&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}b&{}a&{}a&{}a&{}b&{}a\\ \end{array} \end{aligned}$$

and we replace the block by c, so the CS is:

$$\begin{aligned} \begin{array}{lllllllll} a&b&a&a&c&a&a&b&a \end{array} \end{aligned}$$

Step 3: For a given strict active pixel, look at its diameter \(\delta _{\arctan \frac{3}{7}}\), in our example 1 as we have chosen the unit disk. The key point of this method is to show that we have to cancel (in our case) exactly one letter on each side, so we underline the two extremal letters a and b in the first column, then the corresponding ones in the others columns:

$$\begin{aligned} \begin{array}{llllllllll} \underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a&{}b&{}a&{}a&{}b\\ a&{}a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a&{}b\\ a&{}a&{}b&{}a&{}a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}\\ a&{}a&{}\underline{b}&{}a&{}a&{}b&{}a&{}a&{}b&{}\underline{a}\\ a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a\\ a&{}\underline{b}&{}a&{}a&{}b&{}a&{}a&{}b&{}\underline{a}&{}a\\ b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a&{}b&{}a&{}a\\ b&{}a&{}a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a\\ \underline{b}&{}a&{}a&{}b&{}a&{}a&{}b&{}\underline{a}&{}a&{}a \end{array} \end{aligned}$$

Then look at the two middle rows, as \(p+q=10\) is even:

$$\begin{aligned} \begin{array}{llllllllll} a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a&{}a&{}b&{}a\\ a&{}b&{}a&{}a&{}b&{}\underline{a}&{}a&{}a&{}\underline{b}&{}a \end{array} \end{aligned}$$

and replace all the two letters-blocks whose second letter is underlined in any of these two lines by the letter c. Then we get the FC:

$$\begin{aligned} \begin{array}{lllllll} a&c&a&c&a&c&a \end{array} \end{aligned}$$

6 The Role of Diameters

6.1 The Average Visual Thickness

If we consider a continuous black line (segment) of length \(\ell \) and width \(\delta \), then its black surface is equal to the product \(\ell \times \delta \). The surface of a discrete line - union of black pixels - is equal to the number N of black pixels, each unit pixel being of surface 1. If we consider that the visual effect of a gray pixel at level i is the ratio \(i{\slash }n\), we get the global visual effect, or visual surface, of the line:

$$\frac{1}{n}\sum _{i = 1}^n{N_i} $$

where \(N_i\) is the number of gray pixels at the level i.

It is natural to say that the length of the discrete line is the distance between the centers of the two pixels blackened at the extremes. Choose the following definition, by analogy to the continuous case:

Definition 3

Using the previous notations, the mean visual thickness of a discrete line is the ratio between its visual area and its length:

$$\frac{1}{n\ell }\sum _{i=1}^n{N_i}.$$

Then we get:

Proposition 7

The average visual thickness of a discrete line of polar angle \(\theta \) and obtained using an active multi-pixel \({\mathfrak A}_i\) is:

$$\sum _ {i = 1}^N {\delta _{\theta , i}} + O(\frac{1}{\ell '})$$

where \(\ell '\) is the length of the associated irreducible segment.

Roughly speaking we have to count the integer points inside a rectangle, which can be made by looking at the orthogonal projection of these points on the direction of polar angle \(\theta +\frac{\pi }{2}\). These projections are regularly spaced by \(\frac{1}{\ell }\).

6.2 Size of the Diameters

More generally, if we look only at strict active pixels satisfying to Proposition 5:

  • when the three letters alphabet \(\{ a,b,c \}\) can be used, the diameters \(\delta _{\theta }\) take any value in the domain whose limits are the curves \(f_1(\theta )=\sin \theta +\cos \theta \) and \(f_2(\theta )=\max ( \sin \theta ;\cos \theta )\): the number of blackened pixels is clearly between \(p+q\) et \(\max \{ p;q \}\);

  • when we use the five letters alphabet, the upper limit is the same, i.e., \(f_1\), and the lower limit is \(f_3(\theta )=\max (|\cos \theta - \sin \theta |;\frac{1}{2}(\cos \theta +\sin \theta ))\), corresponding to the diamond whose diagonals have lengths \(\sqrt{2}\) and \(\frac{\sqrt{2}}{2}\).

These three curves can be seen on Fig. 7.

6.3 Irregularity of the Thickness

We expect that the thickness of the representation of a line should not depend on its inclination. If we limit ourselves to the case of a strict active pixel, this means that its diameter must not depend on the polar angle \(\theta \). This is clear for the disk of diameter 1. On the other hand, it is then not possible to build the FC from the CS by a simple process, as we have seen in Theorem 1.

In both classical cases CS or FC corresponding to Bresenham Method, the ratio between the maximal and the minimal values of the diameters is equal to \(\sqrt{2}\).

Fig. 7.
figure 7

Octogonal strict active pixel and variations of the diameters (bold curve)

It is therefore interesting to find a strict active pixel for which the variation of \(\delta _{\theta } \) is small, and whose calculation of the FC from the CS is easy, using Theorem 1. It is therefore a polygon with few sides and fairly regular to be round enough. A compromise is to take the octagon build on the one third middle segment of each of the four edges of \(\mathfrak P\). In that case we have (bold curve in Fig. 7):

$$\delta _{\theta }= \frac{1}{3}(\sin \theta +\cos \theta )+ \frac{2}{3}\max (\sin \theta ;\cos \theta ).$$

The ratio between the maximal and the minimal value of the diameters is equal \(\frac{\sqrt{5}}{2}\), which corresponds to a global variation of 11,8%, which can be compared to 41,2% in the two classical cases CS and Bresenham Method. Remark that for any octagon we get at least 8,2%. Moreover, we can build the FC from the CS using a transducer with 11 states, following the method given in [4].