IMPROVED METHOD FOR ROTATING A BINARY IMAGE

Abstract: A method for rotating binary data by 90 degrees in a byte oriented data processing system, comprising the steps of: storing the data in a matrix arranged in r by c rows, where r may be equal to c, information in each row being stored in a number of bytes, each byte having b bits there being c/b bytes in each row; separating the matrix into groups of bits of rotatable size; and transposing first preselected bit positions with second preselected bit positions in each group, followed by exchanging a first one or more rows of bits in the group with a second one or more rows of bits in the group for one sense of rotation and exchanging followed by transposing for the opposite sense of rotation.

Description: The present invention relates to digital image processing methods and more particularly to improved methods for image rotation. The following are systems representative of the prior art. EP -A- 149119 teaches a method for rotating image data which recognises and takes advantage of the fact that large areas of most images are background colour such as white and that digital representations of the pels in these background areas need not be rotated since an all zeros 8 X 8 bit block of pels is the same in any 90 degree rotation of the block. The image is divided into 8 x 8 bit blocks. However, the patent does not teach nor suggest the simplified method for rotation of the bits of an n X n bit block including transposing bits within the block and flipping the rows of the block according to the present invention. US Patent 3,976,872 shows a method of rotation of an image by 90 degrees among other functions performed. However, the patent does not show a method for rotating an image by 90 degrees which includes rotation of n X n bit blocks including transposing bits within the block and flipping the block. US Patent 3,968,475 shows a digital processor for extracting data from a binary image in which the image is divided into an array of sample areas each sample area containing an array of binary data spaces. Although the patent demonstrates image rotation by any one of a number of predetermined angles, the patent does not show a method for rotating an image by 90 degrees either clockwise or counterclockwise including rotation of n X n bit blocks including transposing bits within the block and flipping the block. US Patent 4,052,699 relates to an image processing system wherein video data is stored in a matrix having n rows and n columns. The image is rotated 90 degrees in a piece-meal fashion by vertically accessing word by word video data previously stored as horizontal words. However, the method and apparatus of the patent do not include rotation of n X n bit blocks including transposing bits within the block and flipping the block. US Patent 4,168,488 shows hardware for image rotation of a word organised image buffer where the buffer is divided into a number of square sections each storing a portion of the full image. Although the patent shows apparatus for image rotation through an angle of 90 degrees, the patent does not show a method which includes rotation of n X n bit blocks including transposing bits within the block and flipping the block. US Patent 4,225,929 relates to a code converter including means for rotating an image about a centre point. The processes performed by the converter do not include rotation of n X n bit blocks including transposing bits within the block and flipping the block. US Patent 4,271,476 relates to apparatus for rotating horizontal scan format images into vertical scan format images for printing or other processing. The patented apparatus divides the image into a number of sections and then rotates each section in sequence. The processes formed by the apparatus do not include rotation of n X n bit blocks including transposing bits within the block and flipping the block. EPO published patent application number 081,096 relates to an image rotation control circuit for controlling printing of an image on a printer. The published control circuit does not store the entire display but merely a single line at a time which is converted from a horizontal line to a vertical line or vice versa for printing. The publication does not show a a method for rotating an image by 90 degrees including rotation of n X n bit blocks including transposing bits within the block and flipping the block. An article in the IBM Technical Disclosure Bulletin, Vol. 18, No. 8, January 1976, p 2640 shows a method for rotation of images using contour compressed data. However, the method does not include rotation of n X n bit blocks including transposing bits within the block and flipping the block. An article in the IBM Technical Disclosure Bulletin, Vol. 13, No. 11, April 1971, p 3267 shows a method for performing a fast transformation of axes on two dimensional binary images. The method does not include rotation of n X n bit blocks including transposing bits within the block and flipping the block. An article in the IBM Technical Disclosure Bulletin, Vol. 18, No. 8, January 1976 at page 2633 shows a shift register system for image orientation which among other functions rotates an image in 4 X 4 arrays of characters. The article mentions to achieve rotation of n X n bit blocks by transposing bits within the block and flipping the rows of the block. The article does not show transposing according to the present invention. A letter by J O Eklundh entitled "A Fast Computer Method for Matrix Transposing" in the IEEE Transactions on Computers, July 1972 at page 801, presents a method for transposing n X n data matrices which has some similarity to the method of the present invention. However, the article does not show a method for rotation of n X n bit blocks including transposing bits within the block and flipping the block. The prior art discussed above does not teach nor suggest the present invention as disclosed and claimed herein. As an attempt to obtain a significant gain in performance for a given technology, the present invention provides a method for rotating binary data by 90 degrees in a byte oriented data processing system, comprising the steps of: storing the data in a matrix arranged in r by c rows, where r may be equal to c, information in each row being stored in a number of bytes, each byte having b bits there being c/b bytes in each row; separating the matrix into square blocks of 2 P x 2 P bits, P being an integer, rotating the blocks within the matrix and rotating the bits within the blocks, characterised in that the step of rotating the bits within a block comprises transposing first the bits within the block, followed by exchanging the rows of bits in the block for one sense of rotation and first exchanging followed by transposing for the opposite sense of rotation, the step of transposing comprising P swapping steps, each swapping step i including storing selected rows of the block in two registers, offsetting the content of one of the registers by m=2 P-i bits and exchanging alternate groups of m bits stored in the first register with corresponding groups of bits stored in the second register under the control of a mask. The present invention will be described further by way of example with reference to embodiments of the invention, as illustrated in the accompanying drawing, in which: FIG. 1 is a block diagram of a system configuration capable of executing the method of the present invention; FIG. 2.1 is a diagram of a vertical stripe of n X n bit block displayed before rotation; FIG. 2.2 is a diagram of the stripe of blocks shown in FIG. 2.1 displayed after ninety degree clockwise rotation; FIG. 2.3 is a diagram of the stripe of blocks shown in FIG. 2.1 displayed after ninety degree counterclockwise rotation; FIG. 3.1 is a schematic diagram of one variation of the method of the present invention as applied to a 2 X 2 bit block of data for a ninety degree counterclockwise rotation; FIG. 3.2 is a schematic diagram of another variation of the method of the present invention as applied to a 2 X 2 bit block of data for a ninety degree clockwise rotation; FIG. 4 illustrates a method of row exchange method; FIG. 5.1 is a table showing the position of each bit n an 8 X 8 bit block of data before rotation; FIG. 5.2 is a table showing the position of each bit in an 8 X 8 bit block of data after counterclockwise rotation by ninety degrees; FIG. 5.3 is a table showing the position of each bit in an 8 X 8 bit block of data after clockwise rotation by ninety degrees; FIG. 6 is a schematic diagram of register alignment of an alternate m bit swap in accordance with an alternate embodiment of the present invention; FIG. 7 is a diagram of block bit configuration before and after a transpose; FIG. 8.1 is a schematic diagram of input register contents before a transpose; FIG. 8.2 is a schematic diagram of register contents after a NEAR TRANSPOSE; FIG. 8.3 is a schematic diagram of register contents after a FULL TRANSPOSE; and FIG. 9 is a diagram of register contents for each step of yet another version of the method. In the drawing, like elements are designated with similar reference numbers, an identical elements in different specific embodiments are designated by identical reference numbers. Image processing systems such as is shown in Fig. 1, are generally designed to perform a variety of data manipulations on image data such as rotation by 90, 180, or 270 degrees, and expansion or reduction of image size to meet the requirements of display devices or printers or resolution changes. The rotation of data in blocks of predetermined size by 90 degrees either clockwise or counter-clockwise can be performed in such a system which includes a host processor 12, an image storage 14, a display terminal 16, an image scanner 18 and a printer 20. The display terminal 16, the image scanner 18 and the printer 20 each may have different requirements for reading or presentation of a document or image. Accordingly, the host processor 12 in conjunction with image store 14 will be required to manipulate the image data to meet the presentation requirements of each of the peripheral devices 16, 18, and 20. The rotation of an image can be broken down to a rotation of square blocks around an image, (see FIG. 2.1, 2.2, 2.3) and then rotation of the blocks within themselves. As shown in FIG. 2.1, 2.2 and 2.3, one way to break down the rotation process is to convert an 8 pel wide vertical stripe to an 8 pel high horizontal band, and to repeat this operation. The vertical stripe is composed of stacked 8 X 8 pel blocks, A, B, C, D, and E, while the horizontal band consists of those same blocks side by side. For clockwise rotation the bottom block, E, in the stripe becomes the leftmost block in the band, while for counterclockwise rotation, the bottom block, E, in the stripe becomes the bottom right corner block in the band. Thus the key to generalised rotation for an average processor ie, an 8-bit byte oriented machine is being able to rotate by 8 by 8 blocks, as the rest of the process is byte oriented. Another method for completing the 90 degree rotation of a bitmap containing transposed 8 x 8 blocks is described in 'Method for Rotating a Binary Image', EP -A- 149119. Rotation can be viewed as a combination of a transposition and a mirror image flip as shown in FIG. 3.1 for counterclockwise (CCW) rotation and in FIG. 3.2 for clockwise (CW) rotation for two bit bytes. Since X flips for conventional 8 bit bytes would generally involve looking up each byte of the block in a flip table, the method of the present invention employs Y-flips, which can be accomplished by row exchanges. Figure 4 shows the necessary steps to accomplish row exchanges. As can be seen in step a of Figure 4, the exchanges are accomplished by loading two or more rows into registers and then storing each row back at a specific address, different than the one from which it came. Because the transpose manipulations to be shown proceed most efficiently when one or more 8 x 8 bit blocks have been loaded into registers for manipulation, and because this also requires that the block(s) be returned to storage once transposed, it is a simple matter to implement the row exchanges during this loading and storing by storing each row at a different address than the one it was loaded from, in a manner similar to that shown in Figure 4. The addresses are not arbitrary. Therefore, a sufficient solution to handling both directions of rotation is an efficient transposer. This also handles any requirement to transpose the image. Transposing can be useful for certain mathematical operations such as finding the determinant or inverse of a bit matrix. An original 8 X 8 bit block is shown in Table I below: The transposed block is shown in Table II as: It is well known that the transpose of a square matrix whose linear dimension is the p'th power of two can be obtained in p steps. The matrix of Table I is thought of as being subdivided into 4 square sub-matrices of equal size. The upper right and lower left sub-matrices are interchanged. For example this yields Each sub-matrix is considered as being further divided into four parts, each part being square. The upper right and lower left part are interchanged in each of the sub-matrices. For example This process of division and interchange is continued until 1 × 1 matrices are interchanged. In this embodiment, one further step yields the transposed matrix; the off diagonal elements in each of the sixteen 2 × 2 blocks are interchanged. Two embodiments of the present invention are described, one using 8 registers containing 32 bits of storage each to do 4 blocks simultaneously, the second using 2 registers containing 32 bits each to do only one block. The invention can also be implemented with a larger number of smaller registers, such as 16 bit registers or 8 bit registers. Additionally, the 4 block (preferred) embodiment permits either the loading of the blocks into the registers or the storing of the blocks after completion of the block reorganization to be done on a 32 bit basis rather than on an 8 bit basis, assuming the bit mapped storage is mapped in horizontal scan order. OPERATION Preferred Embodiment A preferred embodiment of a method of block transposition according to the present invention will be described. To transpose four 8 x 8 matrices in parallel, the matrices are arranged as follows: Where R1-R8 are general purpose 32-bit registers and bxy, x = 1-8, y = 1-8 are 8 bit bytes. The bytes b11-b81 contain the first 8 x 8 matrix to be transposed, the bytes b12-b82 the second, etc. The macro SWAP a,b,m,mask includes the following IBM System 370 instructions: The four matrices are transposed in place by the following 12 SWAP's: SWAP R1,R5,4,X'OFOFOFOF' SWAP R2,R6,4,X'OFOFOFOF' SWAP R3,R7,4,X'OFOFOFOF' SWAP R4,$8,4,X'OFOFOFOF' SWAP R1,R3,2,X'33333333' SWAP R2,R4,2,X'33333333' SWAP R5,R7,2,X'33333333' SWAP R6,R8,2,X'33333333' SWAP R1,R2,1,X'55555555' SWAP R3,R4,1,X'55555555' SWAP R5,R6,1,X'55555555' SWAP R7,R8,1,X'55555555' Note that this is three swaps per 8 x 8 bit transpose. There are certain devices which require a different bit order after transposition. For such devices, the following extension to the method of the present invention applies. After transposing four 8 x 8 blocks in parallel, the byte map is as follows: where t11-t81 are the bytes contained in the first transposed block, t12-t82 are the bytes contained in the second, etc. The required order of bytes for these devices is: This arrangement of bytes can be achieved by performing two additional sets of swap operations on the transposed blocks. SWAP R1,R3,16,X'OOOOFFFF' SWAP R2,R4,16,X'OOOOFFFF' SWAP R5,R7,16,X'OOOOFFFF' SWAP R6,R8,16,X'OOOOFFFF' giving the result and SWAP R1,R2,8,X'OOFFOOFF' SWAP R3,R4,8,X'OOFFOOFF' SWAP R5,R6,8,X'OOFFOOFF' SWAP R7,R8,8,X'OOFFOOFF' giving the result This is the desired result except that the registers are not in the proper order for a multiple register store operation. Since the embodiment described thus far would work equally well with any register assignment, the initial loading of data can be changed from sequential registers to loading of data into registers in this order: R1, R3, R5, R7, R2, R4, R6, R8. Corresponding changes must also be made in the register names of the SWAP statements. With these changes, the final ordering of registers will be sequential and a fast multiple register store operation can be used to save the result. ALTERNATE EMBODIMENT An alternate embodiment of a transposition technique in accordance with the present invention will now be described. ALTERNATE m BIT TRANSPOSE SUB-COMPONENT Referring now to FIG. 6, a second embodiment of the transpose method of the present invention will be described. Two registers are offset from each other by m bits. this may be done by a rotate right of m bits on register 2 for most microprocessors. At this point alternate groups of m bits are exchanged between the two registers, so that the first m bits of register one are intact and the last me bits of register 2 are left intact. The second group of m bits of register 1 are swapped with the first group of m bits of register 2. Then the initial shift is undone to straighten the registers. EXAMPLE An ALTSWAP macro as illustrated below may provide more efficient operation than the SWAP macro, described above with reference to the preferred embodiment of the present invention, for some microprocessors. A utility register, named RU, is used. 1. Rotate Register 2 Right m bits. 2. Load RU with reg 1. (or reg containing right part) 3. RU = RU exclusive OR'd with R2 4. RU = RU AND MASK (containing 1's in swap positions) 5. R1=R1 exclusive OR'd with RU 6. R2=R2 exclusive OR'd with RU 7. Rotate Register 2 Left m bits. Groups are now swapped. NEAR TRANSPOSE OPERATION If an 8 X 8 block of pixels as shown as ORIGINAL in FIG. 7, is to be transposed to the configuration shown as OUTPUT in FIG. 7, the ORIGINAL block is stored in a pair of Registers as shown in FIG. 8.1. The NEAR TRANSPOSE is defined as the result shown in FIG. 8.2. The FULL TRANSPOSE is defined as the result stored in the pair of registers as shown in FIG. 8.3. The NEAR TRANSPOSE result can be stored (byte by byte) with no more effort than the FULL TRANSPOSE, except the order of byte storing is slightly different. Since the vertically adjacent bytes of both input and output blocks occur in separate horizontal image scans, they are not adjacent in storage. They appear in storage separated by the width of the horizontal scans. For this reason either result is stored byte by byte and there is no particular advantage to having a full transpose vs. a near transpose. IMPLEMENTATION: 1. ALTSWAP 4 2. ALTSWAP 16 3. ALTSWAP 2 4. ALTSWAP 8 5. ALTSWAP 1 Near Transpose Complete 6. ALTSWAP 8 7. ALTSWAP 16 Full Transpose Complete Although the ALTSWAP m OPERATION was defined as beginning and ending with shift/rotate operations in the amount of m bits, it is clear that when two consecutive ALTSWAP operations occur, the ending shift of the first ALTSWAP may be combined with the beginning shift of the second ALTSWAP to produce a single shift operation. As an example, Step 3 above would end in ROTATE LEFT 2 while step 4 would begin with ROTATE RIGHT 8. These two are concatenated to produce a single ROTATE RIGHT 6 operation. The total number of operations for a NEAR TRANSPOSE is 31 using this method of concatenation. EXAMPLE CLOCKWISE ROTATION Fig. 9 shows a step by step execution of the rotation algorithm on a 8 pel by 8 pel block. The pels have been partially numbered, or rather partially assigned symbols so that their progress may be tracked. The lower left quadrant of the input block is completely numbered while the upper edge of the other three are numbered. The remaining pels are assigned symbols that identify their quadrant.

Claims: A method for rotating binary data by 90 degrees in a byte oriented data processing system (12, 14), comprising the steps of: storing the data in a matrix arranged in r by c rows, where r may be equal to c, information in each row being stored in a number of bytes, each byte having b bits there being c/b bytes in each row; separating the matrix into square blocks of 2 P x 2 P bits, P being an integer, rotating the blocks within the matrix and rotating the bits within the blocks, characterised in that the step of rotating the bits within a block comprises transposing first the bits within the block, followed by exchanging the rows of bits in the block for one sense of rotation and first exchanging followed by transposing for the opposite sense of rotation, the step of transposing comprising P swapping steps, each swapping step i including storing selected rows of the block in two registers, offsetting the content of one of the registers by m=2 P-i bits and exchanging alternate groups of m bits stored in the first register with corresponding groups of bits stored in the second register under the control of a mask. A method as claimed in claim 1, in which a plurality of groups of bits of rotatable size are transposed simultaneously in a parallel operation storing the plurality of groups in a plurality of multi-bit registers in a predetermined order; and simultaneously exchanging preselected bits between a selected pair of registers under the control of a predetermined mask. A method as claimed in claim 1 further including: storing selected bits of one of the groups of bits of rotatable size in a pair of registers; offsetting a second of the registers from a first of the registers by a predetermined number of bits; exchanging alternate groups of bits equal in number to the number of bits of the offset between the two registers; and repeating the above steps for further selected bits of said group of bits until all selected bits are exchanged; and shifting a second of the registers in a direction opposite to the offset to achieve the desired order of transposed bits.

Inventors: GOERTZEL, GERALD, PRUETT, DAVID RAYMOND, THOMPSON, GERHARD ROBERT
Applicants: INTERNATIONAL BUSINESS MACHINES CORPORATION
Application year: 1986
Main classification: G06F15
IPC codes: G06T3