Efficient Implementation of the Image Rotation Method Using Chirp Z ...

0 downloads 0 Views 914KB Size Report
that uses the chirp Z transform [7] is described; the main advantage of the algorithm is the prevention of image quality loss, with the computational complex.
SOFTWARE AND HARDWARE FOR PATTERN RECOGNITION AND IMAGE ANALYSIS

Efficient Implementation of the Image Rotation Method Using Chirp ZTransform A. V. Myagotin and E. V. Vlasov St. Petersburg State University of Civil Aviation, ul. Pilotov 38, St. Petersburg, 196210, Russia email: [email protected] Abstract—The implementation of an image rotation method based on the chirp Ztransform is presented. Low computational costs of the algorithm are achieved by performing the chirp Ztransform using convolu tion in the Fourier domain. The series of numerical experiments supports the preservation of the image qual ity, even for multiple rotations. Keywords: image rotation, chirp Ztransform, Fourier domain. DOI: 10.1134/S1054661814010131

1. INTRODUCTION Rotating a bitmap image at a certain angle is one of the basic transformations used in solving a variety of applied problems [1]. The main complexity that arises when implementing the rotation operation is the cal culation of an image in nodes of the coordinate mesh rotated with respect to an initial one. The use of the trivial algorithms generally results in the loss of low contrast details and the rise of various artifacts such as pixilation, blurring, moire, and aliasing [2]. Obviously, preservation of the quality of an initial image and low computational costs are priority requirements; various methods have been developed and tested to meet these requirements [3–5]. In [6], a novel rotation algorithm that uses the chirp Ztransform [7] is described; the main advantage of the algorithm is the prevention of imagequality loss, with the computational complex ity being O(N4) operations for an image of size N × N pixels. In this work, a modification of this method is proposed for the purpose of reducing the computa tional complexity, a quantitative estimation of the quality of a rotated image is presented, and a series of numerical experiments to compare with the classical method that uses bilinear interpolation is carried out. 2. METHOD DESCRIPTION Let f be the discrete image of size N × N pixels. The formula of the inverse discrete Fourier transform (DFT) is as follows: –1 f = F (ˆf ) xy

N/2 – 1 N/2 – 1

=

∑ ∑

2

ˆf exp ( 2πilx/N ) exp ( 2πimy/N ), lm

l = – N/2 m = – N/2

Received May 5, 2012

where ˆf = F2( f ) corresponds to the Fourier transform of the initial image. In the canonical definition of DFT, the vertical and horizontal indexation of discrete samples is assumed to be performed in the range [⎯N/2, N/2 – 1], while, in the programming lan guages and computer systems of symbol mathematics, digital images are represented by twodimensional arrays with a nonnegative indexation. Let us change ranges of sums in the following manner: N–1N–1

f xy =

∑ ∑ ˆf

l=0m=0

N exp ( 2πi ( l ⎛ l – N ⎞ ⎛ m – ⎞ ⎝ 2⎠ ⎝ 2⎠

– N/2 )x/N )

(1)

× exp ( 2πi ( m – N/2 )y/N ), in order to eliminate negative indexes ˆf and turn our attention to the periodicity property of the discrete spectrum ∀s, t ∈ Z: ˆf lm = ˆf ( l + Ns ) ( m + Nt ) , from which the following relation results: ˆf ˆ ( l – α ) ( m – β ) = f [ ( l – α )modN ] [ ( m – β )modN ] . Let us introduce the auxiliary image ˆI lm = ˆf [ ( l – N/2 )modN ] [ ( m – N/2 )modN ] for which indexes are within the range [0, N – 1] and substitute it into definition (1); then, the inverse Fourier transformation is as fol lows: N–1N–1

f xy =

∑ ∑ ˆI

lm exp ( 2πi ( l

– N/2 )x/N )

l=0m=0

(2)

× exp ( 2πi ( m – N/2 )y/N ). Note that the image ˆI is formed by the vertical and horizontal cycle shift of ˆf by N/2 samples.

ISSN 10546618, Pattern Recognition and Image Analysis, 2014, Vol. 24, No. 1, pp. 57–62. © Pleiades Publishing, Ltd., 2014.

58

MYAGOTIN, VLASOV

Let (pΔ, qΔ) be the coordinates of a point on the plane with indexes (p, q) and discretemesh step Δ = Δx = Δy; then, the affine transform that describes the rotation of the point at angle θ with respect to the cen ter (x0, y0) is as follows: x pq = x 0 + cos θ ( pΔ – x 0 ) – sin θ ( qΔ – y 0 ), y pq = y 0 + sin θ ( pΔ – x 0 ) – cos θ ( qΔ – y 0 ). Thus, the value of the pixel with indexes (p, q) in the rotated image g is calculated as follows: g pq = f ( x pq, y pq ) = exp ( – πi ( ( cos θ + sin θ ) ( pΔ – x 0 ) + ( cos θ – sin θ ) ( qΔ – y 0 ) ) ) N–1N–1

×

∑ ∑ ˆI

l=0m=0

lm exp

⎛ 2πi  ( ( l – N/2 )x 0 + ( l – N/2 )y 0 )⎞ ⎝ N ⎠

2πi × exp ⎛ –  ( x 0 sin θ + y 0 cos θ )m⎞ ⎝ N ⎠ Δ cos θ × exp ⎛ 2πi  ( lp + mq )⎞ ⎝ ⎠ N Δ sin θ exp ⎛ 2πi  ( mp – lq )⎞ . ⎝ ⎠ N Let us turn to the definition of the twodimensional chirp Ztransform [7]: N–1N–1

∑ ∑h

lm

(3)

l=0m=0

× exp ( – 2πiα ( lp + mq ) ) exp ( – 2πiβ ( mp – lq ) ), according to which the calculation of the value in the rotated image can be represented in the following form: g pq = exp ( – πi ( ( cos θ + sin θ ) ( pΔ – x 0 ) (4) – Δ cos θ – Δ sin θ + ( cos θ – sin θ ) ( qΔ – y 0 ) ) )Z pq ⎛ h, , ⎞ . ⎝ N N ⎠ In formula (4), the auxiliary image h is used, and its values are given as follows: 2πi h lm = ˆI lm exp ⎛  [ ( l – N/2 )x 0 + ( m – N/2 )y 0 ⎝ N (5) ⎞  – ( x 0 cos θ – y 0 sin θ )l – ( x 0 sin θ + y 0 cos θ )m ] . ⎠ Let us substitute powers of exponents in expres sion (3) ( lp + mq ) = – ( q – l ) ( p – m ) + lm + pq 2

2

2

2

2

2

2 ( mp – lq ) = ( q – l ) – ( p – m ) + ( m – l ) + ( p – q ) and introduce the following designations: 2

2

C pq = exp ( – 2πiαpq – πiβ ( p – q ) ),

2

2

(7)

2

B lm = exp ( 2πiαlm + πiβ ( m – l ) ),

(8)

then, the resulting formula of the chirp Ztransform N–1N–1

Z pq = C pq

∑ ∑A

lm B ( q – l ) ( p – m ) ,

(9)

l=0m=0

is reduced to the convolution of two discrete images A and B, for which efficient calculation can be per formed in the frequency domain as is shown in the fol lowing section. 3. PROGRAM IMPLEMENTATION The algorithm for rotating the discrete image f around the point with coordinates (x0, y0) at angle θ is represented by a rotate (f, x0, y0, θ) procedure involv ing three logical blocks: preparation of the image (strings 1–5), implementation of the chirp Ztrans form (string 6), and multiplication of the result by the exponent (strings 7–9). procedure rotate(f, x0, y0, θ) 1: ˆf forwardFFT(f)

× exp ⎛ – 2πi  ( x cos θ – y 0 sin θ )l⎞ ⎝ N 0 ⎠

Z pq ( h, α, β ) =

2

A lm = h lm exp ( – 2πiαlm – πiβ ( m – l ) ),

(6)

2: ˆI cyclic shift of ˆf by N/2 samples 0 to N – 1 do 3: for l 4: for m 0 to N – 1 do 5: compute hlm with (5) chirpZ(h, Δcosθ/N, Δsinθ/N) 6: Z 0 to N – 1 do 7: for p 8: for q 0 to N – 1 do 9: compute gpq with (4) 10: return g The chirpZ(h, α, β) procedure implements the chirp Ztransform according to formula (9), with con volution (strings 5–10) being performed in the fre quency domain to reduce computational costs [8]. procedure chirpZ(h, α, β) 0 to N – 1 do 1: for l 2: for m 0 to N – 1 do 3: compute Alm with (7) 4: compute Blm with (8) ˆ 5: A forwardFFT(A) 6: 7: 8: 9:

ˆ B forwardFFT(B) for l 0 to N – 1 do for m 0 to N – 1 do ˆ ˆ ˆ D A ⋅B lm

lm

lm

ˆ) 10: D inverseFFT( D 0 to N – 1 do 11: for p 12: for q 0 to N – 1 do 13: compute Cpq with (6) Zpq Cpq ⋅ Dpq 14: 15: return Z

PATTERN RECOGNITION AND IMAGE ANALYSIS

Vol. 24

No. 1

2014

EFFICIENT IMPLEMENTATION OF THE IMAGE ROTATION METHOD (a)

(b)

59

(c)

Fig. 1. Test images: (a) Lena, (b) Shepp–Logan phantom, and (c) radiographic image of the foam.

(a)

(b)

Fig. 2. Results of the 32fold rotation of the image: (a) method based on bilinear interpolation and (b) method based on the chirp Ztransform.

The convolution of images A and B in the Fourier domain provides reduction of the computational com plexity of the chirp Ztransform and, thus, the rota tion algorithm from O(N4) to O(N2logN) operations. The presented algorithms are implemented using C++ language, the FFTW v.3.3 fast Fourier transform library [9], the highlevel optimization of the code and compiler flags GCC v.4.4 [10]. The test results for var ious input parameters support the high performance of the resulting program, with more than 70% of time being taken by library functions to perform the Fourier transform and only 20–30% of the time being required to perform the other operations. Further reduction in time costs of the rotation algorithm can be achieved by using vector and parallel computing. PATTERN RECOGNITION AND IMAGE ANALYSIS

4. NUMERICAL EXPERIMENTS The quality estimation of the rotated image obtained by the proposed method is carried out in comparison with the classical algorithm based on bilinear interpolation. The testing involves tree input images (see Fig. 1): (a) the Lena standard test image; (b) the idealized model of a human head, i.e., the so called Shepp–Logan phantom that is used in tomo graphic studies [11]; and (c) the radiographic image of water foam, which provides visual estimation of the method in preventing the loss of small details when rotating the image. Figure 2 shows examples of the 32fold full rotation of the Lena test image using both methods with the step θ = 11.25°. The resulting image (see Fig. 2a), which is rotated using bilinear interpolation, involves Vol. 24

No. 1

2014

60

MYAGOTIN, VLASOV σL

EL 0.05 0.04

ChirpZ

Bilinear

0.03 0.02 0.01 0

5

8

11

14 17

t

20

23 26 29 32

0.12 0.10 0.08 0.06 0.04 0.02 0

Bilinear

ChirpZ

5

8

11

14 17

t

20

23 26 29 32

Fig. 3. Brightness variation depending on the number of rotations t.

σL 0.05

E∇L 0.200

ChirpZ

0.04

Bilinear

ChirpZ

0.150

Bilinear

0.03 0.100

0.02

0.005 0 5

0.01 8

11

14 17 20 23 26 29 t

32

0

5

8

11

14 17

20

t

23 26 29

32

Fig. 4. Variation of the blurring degree depending on the number of rotations t.

considerable blurring of contrast boundaries, while, in the case of multiple rotation using the proposed method, all the scene elements are preserved (see Fig. 2b) and the difference between the initial image and the resulting image is insignificant. For a quantitative estimation of the difference in the quality of the initial image and the rotated image, it is proposed to use the brightness variation measure that is determined as follows: EL =



Δ I ( x, y )/N U ,

x, y ∈ U

and its meansquare deviation σL =



2

( E L – Δ I ( x, y ) ) /N U ,

x, y ∈ U

where ΔI(x, y) = f ( x, y ) – g ( x, y ) is the modulus of the difference in the brightness of the initial image f and the rotated image g at the point (x, y); U is the set of points that belong to the circle in the center of the image with the radius N/2; and NU is the number of points in the region U. Let us similarly introduce mea

sures that estimate the blurring degree of the rotated image: E ∇L =



Δ ∇I ( x, y )/N U ,

x, y ∈ U

σ ∇L =



2

( E ∇L – Δ ∇I ( x, y ) ) /N U ,

x, y ∈ U

where Δ ∇I (x, y) = ∇f ( x, y ) – ∇g ( x, y ) is the modu lus of the difference vector of the brightness gradients at the point (x, y). For the Lena test image, the depen dencies of the proposed measures on the number of rotations are shown in Figs. 4 and 5. Numerical exper iments clearly demonstrate that rotation based on the chirp Ztransform, in contrast to bilinear interpola tion, preserves image quality even for multiply rota tions. Similar dependencies take place for the other test images. Note that the nodes of the discrete mesh in the rotated image do not coincide with the initial bitmap, resulting in wavelike artifacts at the objects’ bound aries, i.e., the socalled Gibbs phenomenon (see Fig. 5) [12]. A popular method to deal with the latter is the σapproximation, which is close to the filtration of

PATTERN RECOGNITION AND IMAGE ANALYSIS

Vol. 24

No. 1

2014

EFFICIENT IMPLEMENTATION OF THE IMAGE ROTATION METHOD

61

(b) (a) 1.0 0.5

A

B

0

10

20 (c)

1.0 0.5 0

10

20

Fig. 5. Example of the Gibbs phenomenon: (a) image with wavelike artifacts, (b) values along the AB segment, and (c) value pro file along the AB segment upon applying the σapproximation.

low frequencies and consists of multiplying samples of the image spectrum ˆf lm by the Lanczos σfactors [13] σ lm = sinc ( l/N )sinc ( m/N ). This technique has low computational costs and allows parasitic highfrequency harmonics to be effi ciently suppressed (see Fig. 5c). At the same time, the tests support that, with multiple use of the technique (for example, after each rotation), the image quality rapidly degrades and becomes comparable with the result of bilinear interpolation. 5. CONCLUSIONS An implementation of the bitmapimage rotation algorithm that is based on the chirp Ztransform and has the computational complexity of O(N2logN) oper ations is presented. Quantitative measures for estimat ing the rotatedimage quality such as the average brightness variation and the degree of blurring are pro posed. A series of numerical experiments supports the fact that, for multiple rotation using the proposed method, the image remains unchanged, in contrast to the use of the widespread bilinear interpolation method. The Gibbs phenomenon that arises when working with images in the frequency domain is pro posed to be eliminated using σapproximation. The advantage of the proposed rotation algorithm is its applicability in calculating the rotation for a three dimensional case. When assigning the three values (θ, γ, and φ) that determine the angles of rotation around a corresponding axis, it is sufficient to successively apply the proposed algorithm to each layer of a 3D image (in a corresponding direction). In this case, the total com putational costs are O(N3 logN) operations. The main direction of further investigations is the use of the parallel and distributed computing to increase the performance of the proposed algorithm. PATTERN RECOGNITION AND IMAGE ANALYSIS

REFERENCES 1. R. C. Gonzalez and R. E. Woods, Digital Image Pro cessing (Prentice Hall, 2002). 2. P. Thévenaz, T. Blu, and M. Unser, “Image interpola tion and rotation,” in Handbook of Medical Imaging, Ed. by N. Bankman (Acad. Press, 2000). 3. K. G. Larkin, M. A. Oldfield, and H. Klemm, “Fast Fourier method for the accurate rotation of sampled images,” Opt. Commun. 139, 99–106 (1997). 4. E. Andres, “The quasishear rotation,” Discrete Geom. Comput. Imag. 1176, 307–314 (1996). 5. A. W. Paeth, Graphics Gems (Acad. Press Pro., San Diego, CA, 1990). 6. R. Tong and R. W. Cox, “Rotation of NMR images using the 2D Chirpz Transform,” Magn. Resonance Med. 41, 253–256 (1999). 7. L. R. Rabiner, R. W. Schafer, and C. M. Rader, “The chirp ztransform algorithm and its application,” Bell Syst. Tech. J. 48, 1249–1292 (1969). 8. H. J. Nussbaumer, Fast Fourier Transforms and Convo lution Algorithms (Springer, New York, 1982). 9. Fastest Fourier Transform in the West. http://fftw.org/ 10. The GNU Compiler Collection. http://gcc.gnu.org/ 11. A. C. Kak and M. Slaney, Principles of Computer Tomog raphy Imaging (IEEE Press, 1999). 12. V. N. Tsibanov and A. S. Krylov, “The way to use regu larizing method of quasisolutions for suppressing Gibbs effect in images,” Estesstv. Tekhn. Nauki, No. 1, 306–312 (2008). 13. R. W. Hamming, ““Lanczos Factors” and “The Factors in the General Case”,” in Numerical Methods for Scien tists and Engineers, 2nd ed. (Dover, New York, 1986), pp. 534–536.

Translated by Yu. Kornienko Vol. 24

No. 1

2014

62

MYAGOTIN, VLASOV Anton Vladimirovich Myagotin. Born in 1979. Graduated from the Khabarovsk State Technical Univer sity in 2001. Received candidate’s degree in 2010. Dean at the Faculty of Special Training Programs of the St. Petersburg State University of Civil Aviation. Scientific interests: image processing, parallel computing. Author of more than 30 papers.

Evgenii Vital’evich Vlasov. Born in 1990. Graduated from the Institute of Economics and Transport System Management of the St. Petersburg State University of Civil Aviation in 2012. Postgraduated student of the Department of Flight Operations and Aviation Personnel Training. Scien tific interests: computer graphic, image processing, flight simulators. Author of 5 papers.

PATTERN RECOGNITION AND IMAGE ANALYSIS

Vol. 24

No. 1

2014

Suggest Documents