Pattern Recognition Letters ELSEVIER
Pattern Recognition Letters 17 (1996) 1471 - 1475
Rational bitmap scaling Eric Andres ~", Raghu Menon b, Claudio Sibata a, Raj Acharya t, a Roswell Park Cancer In.~titute. Radiation Medecine Department. Elm & Carhon Sts.. Buffalo. IVY 14263. USA b BioMedical ht aging Group. Department of ECE. 201. Bell Hall. State University o f NY at Buffak~. Buffalo. NY 14260. USA Received 16 April 1996; revised 22 October 1996
Abstract A simple mathematical approach is presented for sczding a bitmap image by a rational factor without interpolation. The transfommtion is reversible. As application of these results, we present a step-by-step scaling algorithm. Keywords: Scaling; Rational .~aling factor; Step-by-step scaling; Quasi al'finc tr:msfi)rmatitm
I. Introduction Scaling is probably one of the most used bitmap image transformations. Several techniques have been studied. Such techniques include simple pixel duplication for an integer scaling factor and interpolation methods for rational scaling factors. In this letter we shall address the scaling of a bitmap image by a rational scaling factor without interpolation (see also the works of Bracchini and Marino (1980)and ttaupt Blake (1989)). Applications can be found in scaling of black-white or low color resolution images, interactive scaling, etc. Our method is very simple and fast. We plan to use the scaling method for interactive feature scaling in CT and MR image registration. The effects on the fractal dimension of a graylevel image are also studied with applications in breast cancer tumor Iocalizations. The results presented in this letter are handled in the general affine case by Marie-Andr6e Jacob (1995). Simple mathe-
• Corrcslxmding author. E-mail:
[email protected]. edu.
matical formulations are given. We shall show that enlarging an image is reversible and we give the inverse transformation which is a Quasi Affine Transformation. Finally, we deal with the problem of increasing the size of an image by a single pixel in the x or y direction. Since many pixels remain unchanged in this case, we propose a simple algorithm that determines the modified pixels in the image.
2. Rational scaling We consider a bitmap U of K X L pixels that we want to scale to an image V of M x N pixels, where K ~ M and L ~< N. The scaling transformation is called S and its reverse R: ImageU(KxL)
s
~
Image V ( M X N ) .
(I)
R
We have by definition R * S = Id, but a point of U might have more than one image through S. S and R are therefore not commutative. In general S * R ~ ld.
0167-8655/96/SI2.00 cc) 1996 Published by Elsevier Science B.V. All rights re.~rvcd PII SO 16 7 - 8 6 5 5 ( 9 6 ) 0 0 109-2
1472
E. Andres et aL / Parrern Recognition Letters 17 (1996) 1471-1475
Our aim is to describe mathematically these two transformations. First of all, it is easy to see that R can be easily described by a Quasi Affine Transformation with the following formulae:
It is easy to see that, for a, b. c positive integers,
c >t a/b is equivalent to c t> [(a + b - l ) / b ] and that c < a/b is equivalent to c ~< [ ( a - 1)/b]. We obtain
R:[O,M-II×[O,N-I]
K
-,[o. K - l l x [o. t . - l]. (x', y ' ) ~ ( x ,
y ) = ( [ K x ' / M ] . [Ly'/N])
~
bc<.<.a
(3)
(4)
This is exactly the formula of an 8-connected discrete line in an (x', x) space as described in the work of Rt~veill~s (1991). We have an equivalent formula for y and y':
O6Ly'-Ny
Mx M ( x + I) 'K ax' < k
K
(6)
(2)
Let us apply that to our transformation T. We have [ x = Kx'/M J, so Mx ~< Kx' < M( x + 1) and finally
0 <~Kx' - Mx < M.
["x+" il
and
where [a/b] is the Integer Part Function Invariant by Translation (IPFIT) of a divided by b also called the Euclidean division (instruction floor in the C computer language, see the work of Andres and Sibata (1995) for more details). If a/b is positive, it corresponds to the classical Integer Part Function. A Quasi Affine Transformation (QAT) is an IPFIT applied to an affine transformation with rational factors. There is now a large body of theory available on these transformations and the reader might find an excellent review of them in Jacob's (1995) article. The fact that R is a QAT is important because it has been shown that affine transformations, used in numerous donmins of pattern recognition and image processing, when applied to a finite discrete domain (an image typically) are QAT. This creates a theoretical link between classical approaches, discrete lines like Brescnham lines, texture mapping, etc. Let us now try to describe S. For that. we shall use an obvious but important arithmetical property of the IPFIT. For a, b, c integers and b > 0, we have
c=[o/bl
~
(5)
L
"< "<
t,
"
(7)
We call Co(x) =
K
c , ( x) =
K
and
Note that Cl(x) = C0(x + I) - 1. We call R°(Y) =
L
and
R t ( Y ) = I N' + N - I And, of course, we also have Rt(y) = Ro(y + I) - I. Since both factors [( Mx + K - I ) / K I and [( Mx + M I ) / K J correspond each to the definition of an 8-connected discrete line, each factor can be computed incrementally. This reduces the number of computations needed. We have now the following result: -
S:[O,K-IIx[O,L-I] --* [0, M - I] × [0, N -
!],
(x, y) ~ ( X ' , y')[Co(x ), C , ( x ) ]
× [ R0(r). R,( y)].
(8)
with R(S(x, y ) ) = ( x , y). The rational scaling S replaces a pixei (x, y) by a rectangular set of pixels denoted S(x, y). There are four different types of rectangular pixels sets S(x, y) of sizes ([ M/K ]) X (LN/LI). (LM/KJ + I) X ([N/LJ), ([M/KI) X (LN/LI + I) or ([M/KJ + I) × (LN/LJ + 1). This is illustrated in Fig. I. It is easy to implement these formulae in an efficient algorithm. The computations
E. Andres ¢t al. / Pattern Recognition Letters 17 ( 19961 1471-1475
1473
F'tn,J I plxels T
u
i
•
-
.
i
c l
Ovtgm,:~[ pLx,'l'~ 2
~,
!
•
.
.
.
.
.
. .
.
.
.
-
-
-.
.
.
.
.
.
i
7 ..... % ' . % % ' . % ' A
-
"l"
i
i"
.
.
.
'.'_"
.
.
i .
.
.
.
.
.
.
.
.'
.
.
Fig. I. Pixels scaled by a factor 15/4 x 13/3.
needed to perform a scaling corresponds to the generation of two Bresenham lines.
and then !' to size ( h i + 1 ) × N ( I " ) since in general I " ~ i " . We are scaling ! to I" by modifying F.
3. Step hy step scale Let us now look at a small application of these results. In many applications, the scaling of an image is performed by dragging the image with the mouse to the desired size. Most of the time, only the outline of the image is shown while the user is dragging the ima,,e~ . It is sometimes interesting to actually see all the intermediate scales of the image. For instance, when we want to scale a given feature of the intage it is often problematic when only the outline is shown. We present here an algorithm that is very simple, fast and easy to implement. Let us suppose that we have an image / of size K x L that we already scaled to an image I' of size M x N. If we want to scale / to an image /" of size ( M + 1) × N, only a few columns change usually between I' and 1". The purpose of the following algorithm is to modify only the colunms needed in I' in order to create I". An important point to note is that scaling / to size M × N ( I ' ) and then I to size ( M + i ) × N ( I " ) is not the same as scaling I to size M X N ( / ' )
We know that by increasing the scale by ! in the x direction, the rows are not modified and only a few cohmms change. The columns change by shifting one pixel to the right. [:or all the cohmms of the original intage we are running the scaling algorithnt from right to left (decreasing x). When the scaling algorithm for size M × N gives a result other than for size ( M + 1) X N then we duplicate the cohmm. Algorithm .
colinit = M -
! ; restinit = K -
I;
• c o l f i n a l = M ; r e s t f i n a l = K - I; • for(x=Kl; x>~O; x - - ) {
- if ( c o l f i n a l > c o l i n i t ) then copy_colunm ( c o l -
init, colfinal); r e s t i n i t - = M; while ( r e s t i n i t < O) { r e s t i n i t +
- ;} = M; while ( r e s r f i n a l < O) { r e s t f i n a l + = K; colfinal- -;} } • end_ algorithm = K; colinit -
-
restfinal -
A similar algorithm for a scale increase in the y direction is easy to design. An example of this
1474
E. Andrcs et a L / Pattern R¢~wgnition Letters 17 (1996) 1471-I475
i! :
...... ,-,_:.:,.
..,,,.......,,.,
[
~
~
_
,
.o:
(a)
.~,?.:
?
....
-
, ....
~
:
~
(b)
~ ,~,~ ' !.~
..,.~.:~.~'..--..':.
(c)
(d)
Fig. 2. (a) Original image (128 X 128 bitmap). (b) Image scaled to size 270 x 150. (¢) Image scaled to size 140 X 256. (d) Image scaled ItS, size 256 X 266.
scaling algorithm applied to a 128 × 128 bitmap image is shown in Fig. 2.
4. Conclusion In this letter we propose a simple and clear mathcmatical formulation for tile rational scaling of bitmap ima,,es This leads to a simple and efficient aLoorithm, in Section 2 we present an algorithm that
serves as basis for the interactive fast scaling of a bitmap image. This can be useful for feature matching in CT and MR registration" "" for example. The complexity of this scaling method is that of generating two Bresenham lines. This method is well suited for the scaling of Black-and-White and low-resolution inmges contrary to classical methods like linear interpolation scaling.,;. The fact that the scaling transformation and its inverse are well defined allows easy point designation and in general scaled image manipulations.
E. Andres et al. / Pattern Recognition Letters 17 (1996) 1471-1475
Acknowledgments T h e authors w o u l d like to thank Ian W e b b for his help.
References Andres. E. and C. Sibata (1995). Choice of integer part function for computer graphics. IEEE Trans. Visualization and Computer Graphics. Submitted.
1475
Braccini, C. and G. Marino (1980). Fast geometrical manipulations of digital images. Computer Graphics and Image Processing 13. 127-141. Jacob, M.-A. (1995). Transformation of digital images by discrete aff'mc applications. Computer & Graphics 19 (3), 373-389. Haupt Blake. E. (1989). Complexity in natural scenes: a viewercentered metric for computing adaptative detail, Ph.D. Thesis. Dept. of Computer Science. Queen Mary College, London. UK. Rtveill~s, J-P. (1991). Gt~omt~trie Disc~te. calculs en hombres entiers et algorithmique (in French). State Thesis, Universit6 Louis Pasteur, Strasbourg. France.