A Study on Directionality in the Ulam Square with the Use of the Hough Transform

  • Leszek J. Chmielewski
  • Arkadiusz Orłowski
  • Maciej Janowicz
Conference paper
Part of the Advances in Intelligent Systems and Computing book series (AISC, volume 534)

Abstract

A version of the Hough transform in which the direction of the line is represented by a pair of co-prime numbers has been used to investigate the directional properties of the Ulam spiral. The method reveals the detailed information on the intensities of the lines which can be found in the square and on the numbers of primes contained in these lines. This makes it possible to make quantitative assessments related to the lines. The analysis, among others, confirms the known observation that one of the diagonal directions is more populated with lines than the other one. The results are compared to those made for a square containing randomly located points with a density close to that for the Ulam square of a corresponding size. Besides its randomness, such square also has a directional structure resulting from the square shape of the pixel lattice. This structure does not depend significantly on the size of the square. The analysis reveals that the directional structure of the Ulam square is both quantitatively and qualitatively different from that of a random square. Larger density of lines in the Ulam square along one of the diagonal directions in comparison to the other one is confirmed.

Keywords

Ulam Square Spiral Directionality Random Hough transform 

1 Introduction

Since its discovery in 1963 [1], the Ulam spiral [2] called also prime spiral [3] gains much attention as the visual way to get insight into the domain of prime numbers. It seems that the geometric structures which have an important mathematical meaning are, among others, the diagonal lines. One of the observations was that there are more primes on one diagonal than the other. It seems that there are still discoveries to be made about the Ulam spiral (cf. [4], Section Why It’s Interesting).

A proper tool for detection and analysis of line segments in an image is the Hough transform (HT) in its version for lines. The Ulam square is not a typical image in which real-world objects are represented by means of a projection onto the camera sensor, which is an approximation in itself. Rather, it is a strictly defined mathematical object. The analysis of lines treated as mathematical objects with the HT was considered by Cyganski, Noel and Orr [7, 8]. They paid attention to the problem of all the digital straight lines possible to be represented in an image, being a digitization of a mathematical straight line crossing the image. Kiryati, Lindenbaum and Bruckstein [6] compared the digital and analog Hough transforms. They discussed the relation between the digital HT according to [7] and the conventional HTs which are analog in nature.

The lines present in the Ulam square are not the approximations of any actual lines. These lines are, however, the sequences of points having strictly specified ratios of coordinate increments. Therefore, in the case of our interest, the concept of the HT described in [7] is too complex. In the present paper we shall use the version of the Hough transform according to [5] in which the ratios of coordinate increments along the object to be detected have been directly used in the process of accumulating the evidence for the existence of lines.

The HT according to [5] has already been used in [9] to find long contiguous sequences of points which form segments of straight lines. In the present paper, however, we shall investigate the directional structure of the Ulam spiral. We shall make an attempt to answer two questions. First, to what extent in some of the directions there are more linear objects in the Ulam square than in the other ones. Second, what is the difference between the directional structure of the Ulam square and the square of corresponding size with randomly displaced points. The use of the method proposed will enable us to give quantitative answers to these questions.

2 Method

Let us recall some basic ideas concerning the Hough transform version we use in this paper, according to [5]. The Ulam square [2] is the \(U\times {}U\) square, where U is and odd integer, with the coordinate system Opq, \(p,q\in {}[-(U-1)/2,(U-1)/2]\), having its origin in the middle element occupied by the number 1, as shown in Fig. 1. A line in the Ulam square is considered as a sequence of pixels, in which the increments \(\varDelta {}p,\varDelta {}q\) of the coordinates pq between the subsequent pixels fulfill the condition \(\varDelta {}p/\varDelta {}q=n_1/n_2\), where \(n_1,n_2\) are small integers. Therefore, the slope of the line can be represented by two small integer numbers which form an array \(D_{ij}\), where \(i=n_1\) and \(j=n_2\) (Fig. 2). Thus, i / j is the reduced fraction \(\varDelta {}p/\varDelta {}q\). For the sake of uniqueness it is assumed \(i\ge {}0\). The dimensions of D are restricted to \([0,N]\times [-N,N]\). From all the elements of D only those are used which correspond to reduced fractions.
Fig. 1.

Central part of the Ulam spiral for dimensions \(11\times 11\) with some of the voting pairs. Notations: (pq) – coordinates with origin in the first number of the spiral; primes: black on white, green or red background; other numbers: grey on black or blue. Selected voting pairs for direction \((\varDelta {}p,\varDelta {}q)=(2,1)\) are shown in colors. Two green pairs for primes 23, 2 and 2, 13 represent an increment \((\varDelta {}p,\varDelta {}q)=(2,1)\); two red pairs 47, 29 and 107, 37 the pair 23, 13 marked by a darker green line represent an increment (4, 2) which also resolves to (2, 1). (Color figure online)

Fig. 2.

Directions represented as a table \(D_{ij}\). The directional vector has the initial point at the empty circle (0, 0) and the terminal point in one of the black circles \((\varDelta {}p,\varDelta {}q)=(i,j)\); \(i\ne {}0\vee {}j\ne {}0\), and \(i\ge {}0\) (reproduced from [5] with permission, slightly changed).

To accumulate the evidence of the existence of lines in the square, pairs of prime numbers are considered. Each pair is a voting set and it votes for a line having the slope determined by \(\varDelta {}p/\varDelta {}q\). If the slope corresponds to an element of D, the pair is stored in \(D_{ij}\), where i / j is the reduced fraction \(\varDelta {}p/\varDelta {}q\); otherwise it is neglected. The votes are stored along the third dimension k of the accumulator, not shown in Fig. 2. For each such vote, the line offset is also stored, defined as the intercept with the axis Op for horizontal lines and with Oq for the remaining ones.
Fig. 3.

Relation of the indexes in the direction table shown in Fig. 2 and the angle \(\alpha \).

The relation of the coordinates in the direction table and the angle \(\alpha \) can be seen in Fig. 3. Only some specific angles can be represented. This is in conformity with our interest in sequences of points for which the increments of coordinates are expressed by small integers.

After the accumulation process, in each element of the accumulator, which corresponds to a specific line characterized with the slope and the offset, as previously defined, the following data are stored: the number of voting pairs and the number of primes in this line, and the list of primes which lie on this line. For each prime in this list the following data are stored: its value, its index in the spiral, and its coordinates pq. Each list can be easily sorted according to the chosen item in these data.

The accumulator can be analyzed with respect to such aspects like, for example, the directional structure of the Ulam spiral, the existence of lines with large numbers of primes, the contiguous strings of points representing primes in the square, etc.

3 Directionality – Selected Results

Before we go on to the results, one more issue needs consideration. In any of our experiments we consider an Ulam square having a specific size, limited by the memory of the computer used and the available time for calculations. Both these requirements do not seem to be crucial, due to that on the one hand very large memories are available now and on the other hand we have to make the calculations only once. However, at this stage we have tried to see if there is a variability in the results with the growing size of the square, or if the results have a tendency to stabilize above some size. As it will be seen further, for some of the characteristics of the directionality, the second case holds. Therefore, we have come to a conclusion that, for the problem of our interest, we can preform the calculations for the square of quite a moderate size of \(1001\times 1001\) points. It contains \(78\,650\) primes, where the largest one is \(1\,001\,989\).

3.1 Ulam Square

Let us consider several ways in which the directionality can be presented. In general, it is related to the intensity of lines having a specified direction. However, let us start from looking at the number of lines having a specific direction, shown in Fig. 4. The number of lines have been normalized with the maximum number for the given square size, which appeared at a different angle for each square size. No tendency of stabilization of the numbers with the growing size of the square can be seen. This characteristic can not be considered suitable for the analysis.
Fig. 4.

Normalized numbers of lines in the given direction, for the squares of sizes \(101\times 101\), \(201\times 201\), \(1001\times 1001\) and \(2001\times 2001\). No tendency of stabilization of the numbers with the growing size of the square can be seen.

Fig. 5.

Normalized numbers of primes on all the lines in the given direction, for the squares of selected sizes from \(101\times 101\) to \(2001\times 2001\). The numbers stabilize at a nearly uniform value.

Let us check if the number of primes on lines in each direction reveals some information on the directionality. This is shown in Fig. 5. It can be seen that the directional structure of the square is not revealed in this plot.

The basic parameter of line intensity in the Hough transform is the number of votes given to the specific line in the accumulation process, that is, the number of pairs of primes in a line. Let us then look at the number of voting pairs in the lines having a specific direction, shown in Fig. 6.
Fig. 6.

Normalized numbers of votes (pairs of primes) on all the lines in the given direction, for the squares of various sizes. A tendency of stabilization of the points in the graphs with the growing size of the square can be seen.

Let us also check if the number of voting pairs of primes per line, in the given direction, is useful for investigating the directionality of the Ulam spiral. This is shown in Fig. 7. This measure also has the tendency to stabilize as the size of the square grows, and exhibits the ability to reveal its directional structure.
Fig. 7.

Normalized numbers of pairs of primes per line in the given direction, for the squares of various sizes. Tendency of stabilization of the points in the graphs with the growing number of primes can be seen.

In the plots of Figs. 6 and 7 is is clearly see that the horizontal, vertical and diagonal lines are the most populated in the Ulam square. It can also be seen that one of the diagonals has more representation that the other in both graphs. This is in conformity with the observations found in literature [1]. These two plots will be used in the further analysis.

3.2 Random Square

The question of directionality of the Ulam spiral can be well assessed in relation to that of a square with random dots of similar density. The tendency of the human visual system of seing regularities where they do not exist is known (cf. the famous dispute on the canalli on Mars, see e.g. [10]). The other side of the problem is that the image of our interest is formed by square pixels, which can be of importance as far as the directions are concerned, due to that vertical, horizontal and diagonal lines are the most naturally represented in the square grid. Therefore, in the two random dot images of Fig. 8 the human eye tends to see some regularities, but they are different in each one.
Fig. 8.

Two random dot images of \(101\times 101\) pixels with the density of points close to that of the Ulam spiral.

Fig. 9.

Numbers of pairs of primes on all the lines in the given direction for 10 realizations of the random square compared to those for the Ulam square. Marks corresponding to the realizations are nearly in the same locations, with no significant dependence on the square size.

Fig. 10.

Numbers of pairs of primes per line in the given direction for random squares compared to those in the Ulam square.

In Figs. 9 and 10 the results for ten different realizations of the random square are compared to those of the Ulam square. Most of these realizations were taken for \(1001\times 1001\) pixels, as this size was considered reasonable for the case of the primes square. However, to see whether the properties depend on the size of the random square, two realizations were taken for size \(501\times 501\) and two for size \(2001\times 2001\) pixels. For each of the ten realizations, the results are very similar. This means that the directional structure of the random square is stable, besides that any particular realization differs in its details and that the size of the image changes.

In the plots of Figs. 9 and 10 it can be seen that the random squares exhibit the directional structure in which the horizontal, vertical and both diagonal lines are dominating above the lines in other directions and that the directions are represented by different numbers of voting pairs. This phenomenon does not significantly depend on the realization of the random process which gave rise to a particular image. As it could be expected, the horizontal direction is not favored versus the vertical one; similarly, one diagonal direction is not favored versus the other one.

On the contrary, in the Ulam square one diagonal direction is dominating over the other one. This is the most conspicuous difference. The pattern of other points for subsequent directions is also different from that for the random square.

4 Summary and Prospect

A version of the Hough transform proposed previously has been used to investigate the directional properties of the Ulam spiral. The method makes it possible to assess the difference in the intensities of lines related to subsequent directions in the quantitative way, due to that the data on the points related to the angles are available.

The measures of line intensities used here allowed us to show that one of the diagonal directions is more populated with lines than the other one. Such a phenomenon is absent in the random square, although in that square also some directionality is observed.

The proposed method gives the possibility to study other quantitative characteristics of the Ulam square [11].

References

  1. 1.
    Wikipedia: Ulam spiral — Wikipedia, The Free Encyclopedia (2016). https://en.wikipedia.org/w/index.php?title=Ulam_spiral&oldid=726734495. Accessed 20 June 2016
  2. 2.
    Stein, M., Ulam, S., Wells, M.: A visual display of some properties of the distribution of primes. Am. Math. Mon. 71(5), 516–520 (1964). doi:10.2307/2312588 MathSciNetCrossRefMATHGoogle Scholar
  3. 3.
    Weisstein, E.W.: Prime spiral. From MathWorld–A Wolfram Web Resource (2016). http://mathworld.wolfram.com/PrimeSpiral.html. Accessed 20 June 2016
  4. 4.
    Authors of the Prime Spiral chapter: Prime spiral (Ulam spiral). The Math Images Project (2016). http://mathforum.org/mathimages/index.php/Prime_spiral_(Ulam_spiral). Accessed 20 June 2016
  5. 5.
    Chmielewski, L.J., Orłowski, A.: Hough transform for lines with slope defined by a pair of co-primes. Mach. Graph. Vis. 22(1/4), 17–25 (2013)Google Scholar
  6. 6.
    Kiryati, N., Lindenbaum, M., Bruckstein, A.: Digital or analog Hough transform? Pattern Recogn. Lett. 12(5), 291–297 (1991). doi:10.1016/0167-8655(91)90412-F CrossRefGoogle Scholar
  7. 7.
    Cyganski, D., Noel, W.F., Orr, J.A.: Analytic Hough transform. In: Proceedings of SPIE. Sensing and Reconstruction of Three-Dimensional Objects and Scenes, vol. 1260, pp. 148–159 (1990). doi:10.1117/12.20013
  8. 8.
    Liu, Y., Cyganski, D., Vaz, R.F.: Efficient implementation of the analytic Hough transform for exact linear feature extraction. In: Proceedings of SPIE. Intelligent Robots and Computer Vision X: Algorithms and Techniques, vol. 1607, pp. 298–309 (1992). doi:10.1117/12.57109
  9. 9.
    Chmielewski, L.J., Orłowski, A.: Finding line segments in the Ulam square with the Hough transform. In: Chmielewski, L.J., Datta, A., Kozera, R., Wojciechowski, K. (eds.) ICCVG 2016. LNCS, vol. 9972, pp. 617–626. Springer, Heidelberg (2016). doi:10.1007/978-3-319-46418-3_55
  10. 10.
    Evans, J.E., Maunder, E.W.: Experiments as to the actuality of the “canals” observed on Mars. Mon. Not. R. Astron. Soc. 63, 488–499 (1903). doi:10.1093/mnras/63.8.488 CrossRefGoogle Scholar
  11. 11.
    Chmielewski, L.J., Orwski, A.: Prime numbers in the Ulam dsquare (2016). www.lchmiel.pl/primes. Accessed 01 Aug 2016

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  • Leszek J. Chmielewski
    • 1
  • Arkadiusz Orłowski
    • 1
  • Maciej Janowicz
    • 1
  1. 1.Faculty of Applied Informatics and Mathematics (WZIM)Warsaw University of Life Sciences (SGGW)WarsawPoland

Personalised recommendations