Method and apparatus for image rotation

Abstract: When an image is to be rotated, the image is divided into blocks each having a predetermined size, and rotation of the image is realized by rotation of the respective blocks and rotation in units of blocks over the entire image. In this case, lines included in each block are moved to a predetermined region so that the lines are continuous in the order of lines. In the region in which the lines are moved as described above, predetermined digit positions in the respective lines appear at intervals of pixels for one line irrespective of the digit positions. After the respective digits are set to have a predetermined positional relationship between lines, since a logic operation is simultaneously performed for a plurality of lines, a plurality of pixels can be simultaneously moved to have a positional relationship after rotation. Also, a plurality of sets of pixels having the positional relationship after rotation can be similarly, simultaneously moved.

Description: The present invention relates to an image processing method and apparatus for drawing a bitmap image obtained by rotating an image in an arbitrary area of input bitmap data. A bitmap rotation method for drawing bit map images obtained by rotating an image in an arbitrary area of input bitmap data through 90° x n (n = 1, 2, 3) includes the following methods. In the following description, the rotation angle represents that in the counterclockwise direction, and the leftmost pixel corresponds to bit 7 unless otherwise specified. Fig. 5 summarizes principal part of conventional 90° rotation processing of an image. The rotation processing is performed in units of 8-byte blocks each consisting of 1 byte x 8 lines (8 x8 pixels). Referring to Fig. 5, p_from and p_to are respectively the output and input pointers of a block to be processed, and a suffix [n] indicates an address advanced by n bytes. For example, p_from[2] indicates an address advanced by 2 bytes from p_from[0]. row_from and row_to are the numbers of bytes per line of images before and after rotation, and work is a work variable for the rotation processing. A symbol "=" represents substitution from the right-hand side to the left-hand side, and a symbol ":=" represents substitution of the OR of the right- and left-hand sides into the left-hand side. On the other hand, a symbol "+=" represents addition of the right-hand side to the left-hand side. In step S51, initialization is performed, i.e., variables such as a pointer p_from indicating a block to be rotated, a pointer p_to indicating a rotated block, and the like are initialized. Steps S52-1 to S52-8 correspond to the main rotation processing. In order to generate data of one rotated block (8 bytes), 8-byte data of an original block is transferred to a variable work in units of pixels per operation to generate rotated data in the variable work, and the rotated data is written in a buffer indicated by the pointer p_to. In steps S52-1 to S52-8, the respective columns of a non-processed block (8 rows x 8 columns) are moved to the respective rows of a processed block. In step S52-1, pixels in the rightmost column of the non-processed block are moved to the uppermost row of the processed block. Note that words "right, left, up, and down" indicate the corresponding positions when an 8 (pixels) x 8 (pixels) block is visually considered. In this case, the pixels are moved as follows. That is, a pixel in the leftmost column of an i-th row of a non-processed block is moved to an i-th column of the uppermost row of a processed block. This movement is repeated in turn for i = 1 to 8. Similarly, in step S52-2, the second column from the right side of the non-processed block is moved to the second row of the processed block. In this manner, the pixels are sequentially moved up to the eighth column to rotate one block through 90°. Upon completion of step S52, the flow returns to step S51 to process the next block. Figs. 6A and 6B show conventional 180° rotation processing. Fig. 6A shows a case wherein a 256-byte look-up table (LUT) is used, and Fig. 6B shows a case wherein movement in units of pixels is repeated as in the conventional 90° rotation processing. In the example using the LUT, a non-processed block is converted using an LUT "table" in units of rows, i.e., bytes to obtain a converted block. The LUT "table" has a value obtained by reversing the order of a binary value i as the contents of an i-th byte from the beginning. For example, the (0x05)-th byte of the LUT "table" has a value 0xA0 obtained by reversing its order as a binary value. For this reason, in step S602, a value obtained by rotating a byte indicated by a pointer p_from through 180° is assigned to a processed block indicated by a pointer p_to. Every time one row is processed, the pointer p_from is advanced by one row and the pointer p_to is returned by one row. When this processing is performed for eight rows, rotation of one block is completed. In Fig. 6B, in step S612, one row (one byte) of a non-processed block is reversed, i.e., rotated through 180°. This processing is performed in turn from upper rows of the non-rotated block, and the rotated rows are assigned in turn from the lower rows of a rotated block, thereby obtaining a block rotated through 180°. In this connection, the 90° rotation processing may use an LUT. However, in the conventional method, since processing is performed in units of bits, the processing speed is low. In addition, in order to perform processing in units of bits, data must be accessed for each processing unit including a target bit, e.g., in units of bytes. For this reason, the processing time is further prolonged since 8-byte data must be accessed each time rotated one-byte data is generated. Such long processing time becomes conspicuous in a system having no data cache. Although a 16-bit processor can perform a 16-bit arithmetic operation and a 32-bit processor can perform a 32-bit arithmetic operation, a portion actually used in the arithmetic operation is only an 8-bit (1-byte) portion, resulting in wasteful processing. When the LUT is used, since the number of data accesses increases, a data cache is preferably arranged to attain high-speed processing. In order to attain higher-speed processing using the LUT, assume that the table size is increased, e.g., is changed to convert a block in units of 2 bytes so as to decrease the number of accesses. In this case, the table size in units of bytes is 1 x 2 8 bytes, while the table size in units of 2 bytes is 2 x 2 16 bytes, i.e., becomes 512 times that in units of bytes. However, as compared to this increase in table size, the number of accesses to the LUT can only be halved, resulting in very poor efficiency. On the contrary, in a system having a data cache, the cache hit rate may lower, and the system speed may decrease. As an equipment to which image rotation is applied, a digital copying machine is known. In a digital copying machine, an original image or the like is optically read, and an image is formed on a recording sheet after digital processing. In such an apparatus, document sheets including a plurality of pages are read in turn, and images can be formed on recording sheets. The direction of a copied document image has a one-to-one correspondence with that of an original document image provided to the apparatus. In an electronic filing apparatus as well, a read image is displayed on a display in correspondence with the read direction. Therefore, when a document image is input, a copied document image cannot have a normal direction unless a document image is input in a normal direction. For example, when one of a plurality of document pages is set upside down, only a document image corresponding to the page is copied upside down. When a copying operation is executed in this state, the user must confirm the page after he or she inputs documents, and must adjust the document directions by picking up the page set in the wrong direction. In the electronic filing apparatus, a document page read in a wrong direction must be set again on a reader in a normal direction and subjected to read processing again, or an input document image must be rotated by user's designation. As described above, in the conventional digital copying machine or electronic filing apparatus, when an original image is input in a wrong direction, the user is required to perform some correction operations, resulting in a heavy load on the user. It is a concern of the present invention to provide an image processing method and apparatus which can reduce the number of times of arithmetic operations by performing pixel re-arrangement for rotation stepwise in the order from smaller portions to larger portions. IBM Technical Disclosure Bulletin, vol. 30, No. 12, May 1988, pages 26 to 28 discloses a technique for rotating 8x8 dot image. By this technique, the dot image is divided into four equal parts and the four parts are moved counterclockwise. This processing is repeated recursively until each of the four parts consist of a dot. In accordance with a first aspect of the present invention there is provided an image processing apparatus as set out in claim 1. In accordance with a second aspect of the present invention there is provided an image processing method as set out in claim 9. Embodiments of the present invention will now be described with reference to the accompanying drawings in which: Fig. 1 is a flow chart showing the 90° rotation processing sequence according to the first embodiment of the present invention; Figs. 2A and 2B are views for explaining data packing according to the first embodiment; Fig. 3 is a view for explaining the 90° rotation processing sequence according to the first embodiment; Figs. 4A to 4C are views showing the order of block processing according to the first embodiment; Fig. 5 is a flow chart showing the sequence of the conventional 90° rotation processing of a block; Figs. 6A and 6B are flow charts showing the sequences of the conventional 180° rotation processing of a block; Fig. 7 is a flow chart showing the sequence of the 180° rotation processing of a block according to the second embodiment of the present invention; Fig. 8 is a view for explaining the 180° rotation processing of the second embodiment; Fig. 9 is a flow chart showing the sequence of the 270° rotation processing according to the fourth embodiment of the present invention; Fig. 10 is a flow chart showing the processing sequence executed when the processing of the first embodiment is executed by a 64-bit processor; Fig. 11 is a flow chart showing the sequence of the 90° rotation processing of a block in which one pixel is expressed by 2 bits, according to the fifth embodiment of the present invention; Fig. 12 is a flow chart showing the processing sequence executed when a plurality of lines are simultaneously processed according to the sixth embodiment of the present invention; Fig. 13 is a flow chart showing the processing sequence executed when a plurality of blocks are simultaneously processed according to the seventh embodiment of the present invention; Fig. 14 is a block diagram showing the system that performs the image processing of the respective embodiments; Fig. 15 is a flow chart showing the 90° rotation processing sequence according to the first embodiment of the present invention; Fig. 16 is a flow chart showing the 90° rotation processing sequence according to the first embodiment of the present invention; Fig. 17 is a flow chart showing the 180° rotation processing sequence according to the second embodiment of the present invention; Fig. 18 is a flow chart showing the 180° rotation processing sequence according to the second embodiment of the present invention; Fig. 19 is a view showing the state wherein a block in which one pixel is expressed by 2 bits is rotated through 90° according to the fifth embodiment of the present invention; Fig. 20 is a view showing another state wherein a block in which one pixel is expressed by 2 bits is rotated through 90° according to the fifth embodiment of the present invention; Fig. 21 is a view showing the state of blocks when a plurality of blocks are simultaneously processed according to the seventh embodiment of the present invention; Fig. 22 is a block diagram showing the arrangement of an electronic filing apparatus according to an embodiment of the present invention; Fig. 23 is a flow chart showing the operation sequence of the electronic filing apparatus according to the embodiment shown in Fig. 22; Fig. 24 is a flow chart showing the sequence of the character cut-out processing (step S3) in the embodiment shown in Fig. 22; Fig. 25 is a flow chart showing the sequence of the four-direction recognition processing in the embodiment shown in Fig. 22; Fig. 26 is a view for explaining the scanning directions for feature amount extraction in the embodiment shown in Fig. 22; Fig. 27 is a flow chart showing the calculation sequence of an average similarity in a given scanning direction in the embodiment shown in Fig. 22; Fig. 28 is a view showing the character cut-out state from a character region; Figs. 29A to 29C are views for explaining an example of combined 1-byte size cut-out regions; Fig. 30 is a flow chart for explaining another method of acquiring feature amounts corresponding to a rotated image; Fig. 31 is a view showing blocks divided in correspondence with cut-out regions and direction components used for acquiring feature amounts by the other method; Fig. 32 is a view showing the storage state of data upon acquisition of feature amounts by the other method; Fig. 33 is a flow chart showing the direction determination sequence in the embodiment shown in Fig. 22; Fig. 34 is a view showing an example of a character string whose rotation is not easily identified; Fig. 35 is a view showing an example of the directions of characters described in a document; and Fig. 36 is a flow chart showing the sequence for rotating an image by rotating blocks constituting an image and re-arranging the blocks. [First Embodiment] Fig. 14 is a block diagram showing the system for realizing rotation processing of an image as an embodiment of the present invention. Referring to Fig. 14, a CPU 1 controls the entire system by executing programs stored in a ROM 2 or a RAM 3, thereby performing image rotation processing and the like. The ROM 2 stores control programs (including programs associated with the flow charts to be described later) of the CPU 1, and data. The RAM 3 stores work data of the CPU 1 and images before and after rotation. The programs may be stored in the RAM 3. A scanner 4 is used for inputting an image. A display 5 displays an image. A storage device 6 comprises a magnetic disk device or the like, and stores images, programs, and other data. The storage device 6 may comprise a removable device. A printer 7 prints out an image and the like. An input/output interface (I/F) 8 is connected to an external device to input/output data. Of these blocks, the following blocks are used for performing image rotation. <Printer> Data described in a page description language and input from, e.g., the input/output interface 8 is stored in the RAM 3. The CPU 1 draws the data on the RAM 3 while interpreting it, and sends the drawn bitmap data to the printer 7 to print the data on a paper sheet. In the printer 7, bitmap data is rotated, bitmap font data is rotated, or image rotation processing is performed when an A3-size printer outputs an A4-size image. <Filing Device> In Fig. 14, the storage device 6 corresponds to a fling device. In the case of an intelligent filing device which stores an original image read by the scanner 4 and performs character-recognition of the read image, the original image read in a wrong direction must be rotated. <CPU> The CPU 1 stores an image read from the scanner 4 or the storage device 6 in the RAM 4, rotates the stored image, and displays the rotated image on the display 5. As described above, the image rotation processing is performed as needed. The rotation processing is realized by the following sequence. <Sequence of Rotation Processing> Fig. 1 is a flow chart that best illustrates the image rotation processing according to an embodiment of the present invention. The processing in this embodiment is performed in units of blocks each consisting of 1 byte x 8 lines (8 x 8 pixels). Variables p_from and p_to are input and output pointers of a block to be processed. Variables row_from and row_to indicate the numbers of bytes per line of images before and after rotation. For example, assuming that the pointer p_from indicates the uppermost row (a row of interest) of a given block, the address of the next row is represented by the sum of the address of the row of interest and the size row_from for one line of an image. Variables work, tmp1, and tmp2 are work variables for the rotation processing. Note that uint32 is the data type indicating a 4-byte length integer, and is assumed to be defined beforehand. On the other hand, a symbol "&" represents an AND operation, and "|" represents an OR operation. Referring to Fig. 1, step S11 corresponds to an initialization step. In this step, the variables such as read and write pointers of a block to be processed are initialized. More specifically, the address of a non-rotated block is stored in the variable p_from, and the address of a rotated block is stored in the variable p_to. Step S12 corresponds to packing processing for reading out all the data of the block to be processed and simultaneously storing the readout data in a variable larger than a 1-byte length. As shown in Fig. 2A, byte data of the respective lines in a block of 1 byte x 8 lines are divided into those of upper four lines and those of lower four lines, and these data are sequentially stored in the variables tmp1 and tmp2. Note that a symbol "m<<n" represents a shift of m to the left by n bits, and a symbol "m>>n" represents a shift of m to the right by n bits. Step S13 corresponds to processing for sequentially generating and writing rotated data on the basis of the contents of the variables tmp1 and tmp2. Note that a symbol "*p_to" represents a region indicated by the pointer p_to. Fig. 3 shows a summary of "bitcombine(shiftpat1,shiftpat2)" macro processing of step S13. In Fig. 3, the parameter shiftpat1 = 4, and the parameter shiftpat2 = 0. By the processing in step S12, the variables tmp1 and tmp2 respectively store pixel data of 1 byte x 8 lines (seventh to 0-th lines) which are packed in units of 4 bytes. In step S13, 1-byte data obtained by arranging and rotating pixel data of the LSBs (least significant bits) of byte data of the seventh to 0-th lines is read out. In a 90° rotated state, the data form one row while the LSBs of the respective lines are arranged in sequence. Note that values matching the line numbers are written in the LSBs of the respective bytes for the sake of easy understanding. The LSB of an i-th byte will be referred to as "LSBi" hereinafter. In addition, a mark "X" represents that the value does not care. Operation 1 is a logic operation for reading out pixel data of LSB7 to LSB0 from the variables tmp1 and tmp2 shown in state 1, and storing the readout data in a variable work. In this operation, the contents of tmp1 are shifted to the left by 4 bits, and the shifted value and hexadecimal mask data mask2=0x10101010 are ANDed. With this operation, the value stored in the variable tmp1 is shifted to the left by 4 bits, and bits other than LSB7, LSB6, LSB5, and LSB4 of original 4-byte data become 0. Also, the contents of the variable tmp2 and hexadecimal mask data mask1=0x01010101 are ANDed. As a result, all the bits other than the LSBs of the respective bytes in the contents of tmp2 become 0. In this manner, the value shown in state 2 is obtained in the variable work by ORing the shifted and masked contents of tmp1 and the masked contents of tmp2. In operation 1, the positional relationships between LSB7 and LSB3, between LSB6 and LSB2, between LSB5 and LSB1, and between LSB4 and LSB0 are set to be equal to those after rotation. In operation 2, the value of the variable work shown in state 2 and a value obtained by shifting the value in state 2 to the right by 7 bits are ORed. As a result, the contents of the variable work are re-arranged, as shown in state 3, and the positional relationships between LSB7 and LSB6, LSB3 and LSB2, LSB5 and LSB4, and LSB1 and LSB0 are set to be equal to those after rotation. Finally, in operation 3, the value of the variable work shown in state 3, and a value obtained by shifting the value in state 3 to the right by 14 bits are ORed. As a result, the contents of the variable work are re-arranged, as shown in state 4, and pixel data for the first row after bit rotation are obtained in 8 bits from the LSB of the variable work. With the above operations "bitcombine", the rightmost column of a non-rotated block can be moved to the uppermost row of a rotated block. In order to perform the above-mentioned operations for one block, pixels extracted in the above description are moved pixel by pixel from the LSB to upper digit positions, and the same operations are repeated. In order to move pixels, the shift amounts "shiftpat1" and "shiftpat2" for the variables tmp1 and tmp2 are decreased to perform a shift operation, so that the digit positions to be processed correspond to bits 0 to 7 in state 2. Lower 1 byte of state 4 obtained in this manner corresponds to a 90°-rotated row. Figs. 15 and 16 are flow charts showing in more detail the flow chart in Fig. 1. The CPU 1 can realize the image 90° rotation processing by executing the programs corresponding to the sequences shown in the flow charts in Figs. 15 and 16. Referring to Fig. 15, step S151 corresponds to steps S11 and S12, and executes processing shown in Fig. 2A. Steps S152 to S155 correspond to step S13. In the description of step S13, the logic operation is performed for the respective columns. However, in Fig. 15, since the column number is generally represented by n, loop processing is added. Fig. 16 is a flow chart for explaining in detail step S153, and describing the processing of the macro bitcombine() in Fig. 1, i.e., the sequence described above with reference to Fig. 3, in conformity with Fig. 3. In Fig. 16, the contents of the packed 32-bit variable tmp1 are shifted to the left by (4-n) bits to set all bits to be 0 except for 4-th, 12-th, 20-th, and 28-th bits. Note that n indicates the column (digit) to be rotated. When (4-n) is negative, the shift direction is reversed. In step S162, the contents of tmp2 are shifted to the right by n bits to set all bits to be 0 except for 0-th, 8-th, 16-th, and 24-th bits. In step S163, the results obtained in steps S161 and S162 are ORed. The above-mentioned operation corresponds to operation 1 in Fig. 3. Steps S164 to S166 are as described above as operations 2 and 3. In this manner, since the respective lines of a block are not processed in units of lines but are converted into continuous data and are then subjected to logic operations, a plurality of pixels can be parallelly processed in a single operation in place of one pixel per operation, resulting in high-speed processing. More specifically, since 4-byte data are respectively packed and stored in the variables tmp1 and tmp2, even when required pixels are masked and read out from data of 1 byte x 8 lines, a plurality of pixels (four pixels in this embodiment) can be read out by a single logic operation (AND operation). Since the data are packed in the variables tmp1 and tmp2 in correspondence with the arrangement of bits after rotation, stepwise pixel replacement like in operations 2 and 3 can be realized. The variables tmp1 and tmp2 can be re-used not only in the case of bit 0 like in Fig. 3 but also when rotated data at the respective digits are to be read out. For this reason, if these values are saved, rotated data of the remaining 7 bytes (lines) can be generated without accessing image data. Even when the above-mentioned processing is executed in a system having no data cache, if tmp1 and tmp2 are assigned to register variables, they are stored in registers of the CPU 1, and rotated data can be generated without requiring any memory access, resulting in very high-speed processing. Since a plurality of image data are packed, the number of variables can be reduced, and the variables can be easily assigned to register variables. Even when the variables cannot be assigned to register variables, the number of times of data accesses can be reduced to 1/4 (since an access in units of 4 bytes replaces an access in units of bytes, the number of times of accesses can be reduced from eight to two). When the number of times of required operations is calculated in detail, in order to rotate one block of 1 byte x 8 lines, one read access for each byte data is required for packing, eight or nine arithmetic operations are required for generating rotated 1-byte data from packed data, and one write access is required for each rotated byte data. In this connection, in the example shown in Fig. 3, operation 1 requires four arithmetic operations, and each of operations 2 and 3 requires two arithmetic operations. More specifically, the number of times of accesses to image data can be minimized, and rotation processing is realized by only a little over one arithmetic operation per pixel. In Fig. 1, upon completion of step S13, the flow returns to step S11 to process the next block. In this case, the next block may be a right or left block or an upper or lower block adjacent to the previous block which has already been processed. A case will be examined below wherein 25 blocks, i.e., blocks a to y each consisting of 1 byte x 8 lines are processed in the order from 1 to 25, as shown in Figs. 4A and 4B. When a data cache is used, even when one byte is to be read out, if a processor has a 32-bit data bus, four bytes on the 32-bit data bus including the byte data of interest are stored in the cache memory. For this reason, when one byte in, e.g., block m is read, data of blocks ℓ and n are also stored in the cache memory. Since the data cache effect for block a appears upon processing of block b, when blocks are processed in the order of blocks a, f, k, p, u, b,..., as shown in Fig. 4A, the contents of the data cache are updated upon processing of middle blocks f, k, p, and u, and the probability of miss hit becomes high upon processing of block b. For this reason, the data cache hit rate becomes higher if the processing is done in the order shown in Fig. 4B. That is, even a small-capacity data cache can be effectively used. Therefore, as shown in Fig. 4C, when a block has a line arrangement indicated by an upper left block 41, after a hatched block is processed, a block on either one of the right and left sides (directions of circular marks) of the hatched process is preferably processed. Blocks are processed in the order in which the addresses of pixels that form an original image to be subjected to rotation processing continue. Fig. 1 shows the case wherein all data in one block consisting of 1 byte x 8 lines are complete. However, when data are incomplete like in a block at the end of an image, the following processing can be performed. When data in eight lines are incomplete, data short portions in the variables tmp1 and tmp2 are processed as blank portions in step S12 in Fig. 1 (or step S151 in Fig. 15). When eight pixels in one byte are short, i.e., when one column is short, control can be made so that one corresponding to the short portion of eight macros bitcombine() in step S13 is not executed. This control corresponds to a case wherein processing is not executed for omitted n in step S153. [Variation of The Embodiment] The macro bitcombine() in the above embodiment, i.e., the processing sequence shown in Fig. 16 may be modified as follows to obtain the same result. In step S161, after the 32-bit variable tmp1 is shifted, bits other than the 4-th, 12-th, 20-th, and 28-th bits are set to be 0. In this modification, these bits are set to be 1 in place of 0. Similarly, in step S162, bits other than the 0-th, 8-th, 16-th, and 24-th bits are set to be 0. Similarly, in this modification, these bits are set to be 1. Furthermore, in step S163, an OR is calculated. However, in this modification, an AND is calculated. As a result of this operation, blank digits in state 2 in Fig. 3 are filled with 1 in place of 0. The subsequent steps are the same as those in Fig. 16. This operation is described as follows in the same manner as bitcombine() in the upper portion of Fig. 1. mask1=0xfefefefe; mask2=0xefefefef; #define bitcombine(patl,pat2)¥ work=((pat1)|mask2)&((pat2)|mask1); ¥ work&=work>>14; ¥ work&=work>>7; Note that a symbol "&=" represents substitution of an AND of the right- and left-hand sides in the left-hand side. In this example, when the number of lines of one block is smaller than 8, pixels in a short portion become 1. In image data, since a black pixel can assume either 0 or 1, when a blank portion is set in white or black, this example and the example of Fig. 1 can be selectively used. As described above, each block is rotated through 90°. In order to rotate the entire image, 90'-rotated blocks must be re-arranged, or blocks must be re-arranged and then rotated through 90°. The re-arrangement of the blocks is also required in 270° rotation and 180° rotation. Of course, different rotation angles require different re-arrangement methods of blocks. Fig. 36 is a flow chart showing the rotation processing of an image including re-arrangement of blocks. Step S3601 corresponds to rotation processing of pixels in each block, and includes the processing shown in Figs. 1, 7, 9, 10, 11, 12, 13, 15, 16, 17, and 18. Even when steps S3601 and S3603 are replaced with each other, the same result can be obtained. When an image is rotated, the image is divided into blocks, and the respective blocks are rotated. The blocks in the image are re-arranged in the same manner as in re-arrangement of pixels in each block upon rotation of the block, thereby rotating the image. [180° Rotation] Fig. 7 is a flow chart showing the sequence for performing 180° rotation processing of an image by the image processing apparatus according to the present invention. Variables p_from and p_to are input and output pointers of a block to be processed. Variables row_from and row_to indicate the numbers of bytes in the horizontal direction before and after rotation, and a variable work is a work variable for the rotation processing. A variable rem1 stores a value for end processing, i.e., a shift amount when the end of an image does not match a 1-byte boundary. A variable rem2 stores a fixed value (32 - rem1). Step S71 corresponds to an initialization step, and initializes variables such as read and write pointers of a block to be processed. In this case, processing is performed in units of 4 bytes x 1 line. Step S72 corresponds to packing processing for reading out all data of a block to be processed, and storing the readout data in a region larger than a 1-byte length. The packed data are stored in the variable work. When the value of the variable rem1 is not 0, processing "work=(work>>rem1) |((uint32)p_from[0]<<rem2);" in step S72 is executed to adjust the end. This formula means that a value obtained by shifting the contents of the variable work to the right by the number of digits rem1 and a value obtained by converting a value indicated by the pointer p_from[0] into a 32-bit value and shifting the converted value to the left by the number of digits rem2 are ORed. Although similar processing is required in the conventional processing, its description is omitted for the sake of simplicity. Note that the right shift arithmetic operation to be executed here is a logic shift arithmetic operation for filling 0 in blank digits obtained after the shift operation. Step S73 corresponds to processing for sequentially generating rotated data based on the variable and writing the rotated data. Upon completion of step S73, the flow returns to step S71 to process the next block. Fig. 8 is a view for explaining a macro "bitcombine2()" in step S73 in Fig. 7. For the sake of simplicity, bit rotation of 1-byte data will be exemplified below. Bit data 7 to 0 are aligned in the variable work, as shown in state 1. By operation 1, pixel data 7 and 6, 5 and 4, 3 and 2, and 1 and 0 in the variable work are replaced with each other, and the variable work is set in state 2. By operation 2, the contents of the variable work are re-arranged, i.e., pixel data 6-7 and 4-5, and 2-3 and 0-1 are replaced with each other in units of 2 bits. As a result, the variable work is set in state 3. Finally, by operation 3, the contents of the variable work are re-arranged, i.e., pixel data 4-7 and 0-3 are replaced with each other in units of 4 bits. As a result, the variable work is set in state 4, and the rotation processing is completed. More specifically, since stepwise pixel replacement is performed at a plurality of positions in a single operation, high-speed processing is assured. Note that the same result is obtained independently of the order of operations 1 to 3. The variable work to be rotated is a 4-byte variable, and the upper- or lower-half 4 bytes of each block are packed in the variable work in step S72. Thus, in the processing in step S73, the operations shown in Fig. 8 are simultaneously performed for 4 bytes in the variable work. When this processing time is calculated in detail, each of operations 1 to 3 requires five arithmetic operations, i.e., a total of 15 arithmetic operations are required. Since the conventional method shown in Fig. 6B requires 21 arithmetic operations, only this fact assures higher-speed processing. Furthermore, in this embodiment, since the variable work stores 4 bytes and these bytes can be simultaneously subjected to processing, still higher-speed processing can be realized. In addition, since this algorithm does not make any extra data accesses unlike in an LUT, a decrease in speed is small even when this algorithm is executed by a system having no data cache. As can be seen from Fig. 8, in the 180° rotation processing, pixels can be replaced stepwise from small portions even when a plurality of byte data are not packed. For this reason, the packing processing is not always required. Fig. 7 shows a case wherein data in one block consisting of 4 bytes x 1 line are complete. When data are incomplete like a block at the end of an image, the following processing can be performed. When data in 4 bytes are incomplete, the processing in step S72 is performed while portions corresponding to omitted bits in the variable work are filled with blank bits. In step S73, the same applies to the macro "bitcombine2()", and the control may be made to write only effective portions of data. Fig. 17 is a flow chart for explaining in more detail the processing shown in Fig. 7. Fig. 18 is a flow chart for explaining the macro bitcombine in Fig. 7. The CPU 1 can realize 180° rotation of an image by executing the programs corresponding to the sequences of the flow charts shown in Figs. 17 and 18. Referring to Fig. 17, the upper-half 4 bytes of an 8 x 8 block to be rotated are packed in the variable work (S171). If the block to be processed is an incomplete block, incomplete portions are filled with blank bits (S173). Then, the upper and lower digits of an n-th line in the block are reversed (S175). This processing is shown in Fig. 18, i.e., corresponds to the processing itself shown in Fig. 8. The processing in step S175 is performed for four lines packed in the variable work. Upon completion of the upper four lines, the same processing is repeated for the lower four lines from step S171 (S179), thus completing 180° rotation of one block. Referring to Fig. 18, adjacent odd and even digits of the packed four bytes are replaced with each other in step S181 (operation 1), and adjacent odd and even pairs of replaced bits are replaced with each other in step S182 (operation 2). In step S183, adjacent odd and even sets of four bits including the pairs of bits replaced in step S182 are replaced with each other (operation 3). In this manner, replacement of the upper and lower digits of the packed four bytes is completed. When the n-th line in this non-rotated block is stored as a (7-n)-th line in a rotated block, rotation of the first line is completed. As described above, the 180° rotation processing of an image can be performed at high speed. [90° Rotation When Bit 0 is on Left] The first embodiment has exemplified the 90' rotation when bit 7 corresponds to a left pixel. This embodiment exemplifies a case wherein bit 0 corresponds to a left pixel. Fig. 9 shows the sequence in this case. The operation is substantially the same as the processing in the first embodiment. However, in the processing in step S92, the packing method of data is reversed, as shown in Fig. 2B, and the order of lines converted from columns to rows by the macro "bitcombine()" in step S13 in Fig. 1 is reversed. More specifically, in the processing shown in Fig. 1, since the LSB corresponds to the rightmost digit, the rotation is performed so that the LSBs are aligned in the first line. However, in Fig. 9, since the leftmost digit corresponds to the LSB, a line is formed by reading out pixel data in the leftmost digits in an order opposite to Fig. 3, and this line is determined to be the first line. In this manner, even when bit 0 is at the left end, the 90° rotation processing can be similarly performed. [270° Rotation] When an image is rotated through 270°, the same sequence as in Fig. 9 is executed when bit 7 corresponds to a left pixel, and the same sequence as in Fig. 1 is executed when bit 0 corresponds to a left pixel. Only a difference from the 90' rotation is the order of blocks to be processed in initialization of pointers in step S11 or S91. As can be seen from the above description, in the processing operations shown in Figs. 1 and 9, the rotation directions are opposite to each other in consideration of only the arrangement order of bits. That is, in Figs. 1 and 9, both the variables p_from and p_to are set to indicate the first line of a block in the initialization step. However, in the case of 270° rotation, one of the variables p_from and p_to is set to indicate the last line. The pointer set to indicate the last line is incremented toward the first line of the block. [90° Rotation Accelerated by 64-bit Arithmetic Operation] The first embodiment uses 32-bit arithmetic operations. Fig. 10 shows an example when a processor that can perform 64-bit arithmetic operations is used. Note that uint64 is an 8-byte length integer and is assumed to be defined beforehand. This processing is essentially the same as that described above with reference to Fig. 3 or Figs. 15 and 16. However, since 64 bits can be parallelly processed, tmp1 and tmp2 shown in Fig. 3 can be set in a single variable work. More specifically, in state 1 in Fig. 3, the upper and lower 4 bytes of a block are divisionally packed in two 4-byte variables. Alternatively, in step S102 in Fig. 10, 8 bytes for one block are packed in a single variable. That is, since tmp1 and tmp2 correspond to the continuous variable work in Fig. 10, a value obtained by shifting the contents of the variable work to the right by 32 digits (4 bytes) corresponds to the variable tmp1. Therefore, operation 1 in Fig. 3 corresponds to an operation for shifting the upper 32 bits of the variable work by 4 digits and ORing the shifted value and the lower 32 bits (including processing for masking digits not to be processed). As described above, in the first embodiment, the number of arithmetic operations in the micro "bitcombine3()" is 8 or 9. However, in Fig. 10 of this embodiment, since the processing of operation 1 in Fig. 3 can be attained by only the shift operation and ORing, the number of arithmetic operations can be further reduced to 7 or 8. As described above, the conventional algorithm has no room for a higher processing speed even when the processor evolves, since it performs processing in units of 8 bits irrespective of the number of digits to be parallelly processed of the processor. However, according to the present invention, higher-speed processing can be realized in correspondence with evolution of the processor. In this embodiment, the variables tmp1, tmp2, mask1, and mask2 required in the first embodiment can be reduced to two variables, i.e., tmp and mask. A portion "work | =work>>28;work | =14;work | =work>>7;" of the macro "bitcombine3()" in Fig. 10 yields the same processing result as in Fig. 1 although its order is opposite to that in Fig. 1. More specifically, the processing in "work | =work>>28;work | =14;work | =work>>7;" correspond to operations 1 to 3 for shifting and superposing digits described above with reference to Fig. 3, but the same result is obtained even when these operations are executed in a reverse order. [Second, Embodiment] [Multi-value Image Rotation] Fig. 11 shows the processing method of 90° rotation when one pixel is expressed by 2 bits. In this embodiment, processing is performed in units of blocks each consisting of 1 byte x 4 lines, and the rotation processing described above as the first embodiment is performed in units of 2 bits. More specifically, in step S112, 32 bytes for 4 lines are packed in a single variable tmp. Fig. 19 is a view showing the rotation processing for one line, in which the first rotated line is formed in step S113 in Fig. 11. By the processing in step S112, data are packed in the variable tmp, as shown in state 1 in Fig. 19. Thereafter, the contents of the variable tmp are shifted to the right by 6 digits to mask digits other than two digits at the end of each byte with 0 (operation 1). The reason why the contents of tmp are shifted by 6 digits is that the upper 2 bits of each byte are to be processed. In this case, if the lowermost 2 bits of each byte are to be processed, no shift operation is required. On the other hand, if next lower 2 bits of each byte are to be processed, the contents of tmp are shifted to the right by 2 digits. Furthermore, if the still next lower 2 bits of each byte are to be processed, the contents of tmp are shifted to the right by 4 digits. In this manner, data set in state 2 are obtained. This state remains the same independently of the line number. Subsequently, the data in state 2 are shifted to the right by 6 digits, and the shifted data and the data in state 2 are ORed (operation 2), thus obtaining data in state 3. Furthermore, the data in state 3 are shifted to the right by 12 digits, and the shifted data and the data in state 3 are ORed (operation 3), thus obtaining data in state 4. The lowermost one byte of the data in state 4 corresponds to one rotated line. The above-mentioned operations are performed for all the four lines, and the obtained lines are stored as lines corresponding to digits before processing, thus obtaining 90'-rotated image data. In Fig. 19, a block is rotated so that upper digits form upper lines, and lower digits form lower lines. As described above, although the basically the same processing as in the first embodiment is performed, the number of digits to be operated is not 1 bit but 2 bits unlike in the first embodiment. As described above, the present invention can also be applied to a multi-value image. [Third Embodiment] [Processing for a Plurality of Lines] Fig. 12 shows the processing method of 90° rotation when one pixel is expressed by 2 bits. Using the same variables tmp1 and tmp2 as in Fig. 1, processing "tmp1 | =tmp1<<14;tmp2 | =tmp2<<14" is performed in step S122 to prevent identical arithmetic operations from being repeated in step S123. As a result, rotated data for two lines are generated in the variable work in a macro "bitcombine5()". Fig. 20 shows this state. In step S122, as shown in state 1, data of the first line (indicated by symbol a) and the second line (indicated by symbol b) of a non-rotated block are set in the variable tmp2. More. specifically, the second and first lines are stored in turn in the lower 16 bytes of tmp2 (0 is set in other digits), and the OR of the stored value and a value obtained by shifting the stored value to the left by 14 bits is stored in the variable tmp2. The variable tmp1 similarly stores data of the third and fourth lines. For the variables in state 1, the value of tmp2 is shifted to the right by 4 digits to set 0 in bits other than the lower 2 bits of each byte, and 0 is set in bits other than the third and fourth bits from the MSB of each byte in the value of tmp1 (operation 1). These values are respectively stored in variables par2 and par1. The values of the variables tmp1 and tmp2 preferably remain the same for the subsequent processing. The values in state 2 obtained in this manner are ORed (operation 2) to obtain a value in state 3. When the value in state 3 and a value obtained by shifting the value in state 3 to the right by 6 digits are ORed (operation 3), a value in state 4 is obtained. In state 4, two lines after the non-rotated block is rotated through 90° in units of 2 bits are obtained. More specifically, the first line is obtained as the second byte, and the second line is obtained as the fourth byte. The above-mentioned operations are also performed for the third and fourth rotated lines. For this purpose, as two values to be given in state 2, values that are respectively shifted to the left by 4 digits from those shown in Fig. 20 are used; bits 3 and 2 or bits 1 and 0 respectively replace bits 7 and 6 or bits 5 and 4 shown in Fig. 20. As a result, after operations 2 and 3, the third and fourth rotated lines are obtained. [Fourth Embodiment] [Processing for a Plurality of Blocks] Fig. 13 shows the processing method of 90° rotation when one pixel is expressed by 4 bits. According to the first embodiment, when one pixel is expressed by 4 bits, one block consists of 1 byte x 2 lines. However, in this state, if such a block is packed in a 32-bit variable, a blank portion is formed for 2 bytes, and 1/2 of the arithmetic operations are wasted. For this reason, processing is performed while 2 bytes x 2 lines for two blocks are packed in a variable tmp. This packing processing is performed in step S132. In step S132, data are packed in the 4-byte variable tmp in the order of the first line of the second block, the second line of the second block, the first line of the first block, and the second line of the first block. Fig. 21 shows this state. In two blocks A and B in which one pixel is expressed by 4 bits, pixels a1 to a4 and pixels b1 to b4 are defined as shown in Fig. 21. These pixels are packed in step S132, as shown in state 1. The packed data are stored in units of pixels (4 bits) in the 32-bit variable tmp from its LSB side by operation 1. Similarly, pixels which are not stored in tmp are shifted to the right by four digits and are stored in "work" (operation 1). As a result, state 2 shown in Fig. 21 is obtained. The value of the variable tmp obtained as described above, and a value obtained by shifting the value of temp to the right by 4 digits are ORed, and the OR result is stored in the variable tmp (operation 2). The same operation is performed for the variable "work". The obtained two variables in state 3 are stored as two rotated blocks in the order of the second byte of "work", the second byte of tmp, the fourth byte of "work", and the fourth byte of tmp, thus obtaining an image in which blocks A and B are simultaneously rotated through 90°. With the above-mentioned processing, since the total number of arithmetic operations and the number of loops can be reduced, high-speed processing can be assured. When a plurality of variables for packing are prepared, the number of loops can be further reduced. If a processor that can perform 64-bit arithmetic operations is used, it can double the number of blocks to be processed. For example, not only in a case wherein one pixel is expressed by 4 bits, but also in a case wherein one pixel is expressed by 2 bits, as shown in Fig. 11, it is easy to modify processing so as to simultaneously process two blocks. As described above, according to the image processing method and apparatus of embodiments of the present invention, the following effects are expected. Since data on a bitmap across a plurality of bytes are simultaneously stored in a multi-byte length variable, a plurality of bytes can be simultaneously processed, and the number of times of arithmetic operations can be reduced. For this reason, since a plurality of pixels can be simultaneously processed, the number of times of arithmetic operations per pixel can be reduced, and the processing time can be shortened. In the prior art, even when a 64-bit process replaces a 32-bit processor to execute the processing, the processing speed cannot be increased unless the operation frequency or cache contents are changed or the internal architecture is improved. However, according to the present invention, when the bit width of an arithmetic operation increases, higher-speed processing can be realized by positively utilizing the increase in bit width. For this reason, a difference from the prior art can be further increased. Since the number of times of data accesses is small, a decrease in speed is small even in a system with a small data cache. For the same reason, a decrease in speed is small even in a system having no data cache. Since blocks are processed in the order in which the addresses of an original image to be rotated continue, the cache hit rate can be increased with respect to the same capacity of the data cache, thus increasing the processing speed. Since image data across a plurality of bytes are simultaneously stored in a multi-byte length variable, the number of variables can be reduced as compared to a case wherein data are divisionally stored in a plurality of variables. For this reason, a compiler can easily distribute variables to register variables. [Fifth Embodiment] The fifth embodiment of the present invention will be described below with reference to the accompanying drawings. In the following description of the embodiment, the present invention is applied to an electronic filing apparatus. Fig. 22 is a block diagram showing the arrangement of an electronic filing apparatus according to this embodiment. Referring to Fig. 22, a scanner 10 optically reads an original image set on the apparatus to obtain image data. A CPU 11 controls the overall electronic filing apparatus. A ROM 12 stores various control programs to be executed by the CPU 11, data to be looked up in various kinds of processing, and the like. A RAM 13 presents a work memory area for the CPU 11. Also, the RAM 13 stores image data of a document for one page upon discrimination of the original direction (to be described later). An interface 14 connects the scanner 10 and a bus 17. An external storage device 15 stores document image data to be filed. A display 16 makes various display operations. For example, document image data stored in the external storage device 15 is read out, and the readout data can be displayed on the display 16. A print unit 18 forms a visible image on a recording medium. For example, the print unit 18 can form a document image stored in the external storage device 15 on a recording sheet. The operation of the electronic filing apparatus of this embodiment with the above arrangement will be described below. Fig. 23 is a flow chart showing the operation sequence of the electronic filing apparatus of this embodiment. In step S1, the scanner 10 reads a document image, and stores it in the RAM 13 as image data whose document direction is to be discriminated. In step S2, character regions are extracted from the image data stored in the RAM 13. In step S3, one of the character regions extracted in step S2 is selected, and a character is cut out from the selected character region. The character cut-out processing is temporarily completed when the number of cut-out character regions has reached a predetermined value. As will be described later, the number of characters increases/decreases after recognition processing. For this reason, the number of characters to be cut out in step S3 is determined based on experience so that the final number of characters becomes equal to or larger than a threshold value. Note that extraction of character regions and cut-out processing of characters can adopt the state-of-art techniques in, e.g., character recognition techniques. In step S4, recognition processing is performed for cut-out characters in four directions, i.e., 0°, 90°, 180', and 270°, and average similarities in these directions are calculated. In step S5, a direction having the highest average similarity is determined as the direction of the original of interest. In step S6, the image data stored in the RAM 13 is rotated as needed on the basis of the direction of the original determined in step S5, and the data is saved in the external storage device 15 as image filing data. On the other hand, if no character regions are extracted in step S2, the direction detection of an image according to this embodiment cannot be performed. In this case, the flow advances to step S7, and the image data stored in the RAM 13 is saved in the external storage device 15 as electronic filing data without any processing. If a predetermined number of character regions cannot be cut out in step S3, the respective threshold values used for determining the direction (to be described later) may be set to be relatively higher to perform direction detection. The processing operations in steps S3, S4, S5, and S6 described above will be described in more detail below. Fig. 24 is a flow chart showing the sequence of the character cut-out processing (step S3) in this embodiment. In the character cut-out processing, in step S31, one of the character regions extracted in step S2 is selected. In step S32, a character is cut out from the selected character region. If a character can be cut out, the flow advances from step S33 to step S34 to check if the number of cut-out characters has reached a predetermined value. When a predetermined number of characters have been cut out, this processing ends. However, if the number of cut-out characters is smaller than the predetermined value, the flow returns to step S32. If no character is cut out in step S32, the flow advances from step S33 to step S35 to check if non-processed character regions (non-selected character regions) remain. If non-processed character regions remain, the flow returns to step S31, and a new character region is selected. Thereafter, the flow advances to step S32. As described above, the processing is repeated until a predetermined number of characters are cut out. In this case, when all the character regions are processed before a predetermined number of characters are cut out, the flow advances from step S35 to step S7 in Fig. 23. Then, the four-direction recognition processing (step S4) will be described below. Fig. 25 is a flow chart showing the sequence of the four-direction recognition processing in this embodiment. In step S41, each of the regions cut out in step S3 are scanned in the 0° direction to extract a feature amount and to calculate a similarity. A sum total of the similarities of all the cut-out regions is calculated, and is divided with the number of characters to obtain an average or mean similarity. Thereafter, in steps S42, S43, S44, each region is respectively scanned in the 90°, 180°, and 270° directions, and the average similarities are calculated in the same manner as in step S41. Fig. 26 is a view for explaining the scanning direction for feature amount extraction in this embodiment. As described above, in this embodiment, the scanning operations in the four directions, i.e., 0°, 90', 180°, and 270°, and extraction of feature amounts are performed. Note that direction recognition processing may be performed after an image is actually rotated. However, this embodiment uses the method of changing the scanning direction, as shown in Fig. 26, so as to shorten the processing time. The recognition processing is classified into feature extraction processing for extracting a feature from a character image as a feature amount, and recognition processing for performing matching between the obtained feature amount and predetermined features in units of characters. Upon extraction of a feature of a character, by changing the scanning direction of a character image in units of angles, the same feature amount as that obtained upon execution of feature extraction by rotating an image can be extracted without rotating an image. More specifically, as shown in Fig. 26, if the feature amount in the case of 0° is extracted by scanning a character image from the upper left position to the lower right position, the feature amount in the case of 90° can be extracted by scanning the image from the lower left position to the upper left position. The calculation of an average similarity in this embodiment will be explained below. Fig. 27 is a flow chart showing the calculation sequence of an average similarity in a given scanning direction in this embodiment. For example, in step S41 in Fig. 25, an average similarity obtained by the scanning operation in the 0° direction is calculated by executing the respective steps in Fig. 27 while setting a designated angle of 0°. The respective steps of Fig. 27 will be explained below with reference to a case of the scanning operation in the 0° direction. Similar processing is performed for the scanning operations in the 90°, 180°, and 270° directions. In step S401, one cut-out region is scanned in the designated direction to acquire a feature amount. In this case, the cut-out region of interest is scanned in the 0° direction in Fig. 26. Then, a similarity is calculated by performing matching the cut-out region of interest with respective character patterns, and the calculated similarities are accumulated. The scanned cut-out region is counted as one character to count the number of characters. The above-mentioned processing is performed for all the regions cut-out in step S3 (steps S404 and S405). As a result, the sum total of the similarities and the number of characters of all the regions cut-out in step S3 can be obtained. Upon completion of the calculations of the similarities for all the cut-out regions, the flow advances to step S406 to check if cut-out regions are respectively 1-byte characters or constitute a 2-byte character in a portion where 1-byte size regions are successively cut out. More specifically, in a state wherein characters are cut out, only the size information and pitch information of each character are available, as shown in Fig. 28. For this reason, it cannot be discriminated whether a certain portion corresponds to a string of 1-byte characters like "1234" or to a string of 2-byte characters like " " that can be separated into 1-byte size cut-out regions. For this reason, in order to determine if a 1-byte character is a part of a 2-byte character, the best result must be selected from the results obtained by recognizing character images as 1-byte characters and the results obtained by recognizing a plurality of character regions as one character. In step S406, of the cut-out regions, two successive 1-byte size regions are combined to one cut-out region. Each 1-byte size region can be determined based on the ratio between the length and width of a cut-out region. In step S407, the new cut-out region obtained by combining the two 1-byte size regions is scanned in the designated direction (in this case, the region is scanned in the 0° direction) to extract a feature amount and to calculate a similarity. As a result, if the similarity calculated for the combined 2-byte size region becomes larger than the similarity calculated for the non-combined 1-byte size region, it is determined that the cut-out region of interest constitutes a 2-byte character. Then, the accumulated similarity obtained and the count value of the number of characters obtained in steps S401 to S405 above are updated on the basis of the result of the combined cut-out regions (steps S408 and S409). Figs. 29A to 29C are views for explaining an example of combined 1-byte size cut-out regions. As shown in Figs. 29A to 29C, when three 1-byte size regions align in line (Fig. 29A), two different combination methods are available (in Figs. 29B and 29C). In this case, of the sums, b + c + d, f + d, and b + g, of the similarities, a cut-out state with the maximum similarity is selected. The above-mentioned processing is executed for all combinable portions (step S410) to obtain a maximum similarity. The maximum similarity is divided with the count value of the number of characters at that time to obtain an average similarity (step S411). The reason why the average similarity is used is that the number of characters varies in units of angles due to the combining processing when the above-mentioned processing is performed in the scanning directions of 0°, 90°, 180°, and 270°. In the above-mentioned feature amount extraction processing, as shown in Fig. 26 as well, a feature amount equivalent to that obtained by rotating an image is acquired by changing the scanning direction of an image of the cut-out region. However, the feature amount acquisition method corresponding to rotated images is not limited to this method. Another feature amount acquisition method corresponding to rotated images will be described below with reference to Figs. 30 to 32. Fig. 30 is a flow chart for explaining another feature amount acquisition method corresponding to rotated images. Fig. 31 is a view showing divided blocks corresponding to cut-out regions and direction components for feature amount acquisition by the other method. Fig. 32 is a table showing the data storage state by the other feature amount acquisition method. According to the method to be described below, a temporarily extracted feature amount is used as a reference amount, and the feature amount of a rotated character image is extracted by converting the reference amount. In step S421, a character image (cut-out region) is divided into blocks 1 to 16, as shown in Fig. 31. In step S422, the frequencies of direction components of directions 1 to 4 in Fig. 31 are counted for an edge image included in each block, and are used as feature amounts. The obtained feature amounts in units of direction components of each block are stored in the RAM 13, as shown in Fig. 32. After the feature amount of 0° is extracted, the feature amounts of 90°, 180°, and 270' can be generated based on the feature amount of 0°. More specifically, the feature amount of 90° can be generated in such a manner that the feature amounts of directions 1 and 3, and those of directions 2 and 4 are replaced with each other, data of block 1 is moved to block 4, data of block 2 is moved to block 8, and so on. The feature amounts of 180° and 270° can also be acquired by replacing the feature amounts of the respective blocks and direction components. With this method, since the feature amount extraction can be attained by only replacing data without accessing an image, higher-speed processing than the method shown in Fig. 26 can be realized. Either way, an image itself need not be rotated, and feature amount extraction in units of angles can be performed at high speed. After the average similarities are obtained in units of angles, the recognition result is discriminated in step S5. The discrimination processing will be described in more detail below. Fig. 33 is a flow chart showing the direction determination sequence in this embodiment. In step S501, the highest average similarity is extracted. In step S502, it is checked if the average similarity is larger than a predetermined value. Although a direction having the highest average similarity is determined to be a normal direction, that portion of interest may not be a character region at the time of character region extraction. When the type of character region does not match a recognition means used in direction discrimination, e.g., when the type of character region is a halftone dot screen, the direction discrimination cannot be normally performed. In view of this problem, when the average similarity of the direction in the first place is lower than the predetermined value, the flow advances from step S502 to step S508, and another character region is used for discrimination. On the other hand, when characters with large similarities are present like in "1 + 100 = 101" independently of any of the four recognition processing directions, the similarities of the respective directions have a small difference. In addition, in this example, images of numerals 1 and 0 rotated counterclockwise through 270° may be recognized as Chinese numerals "―" and "○" with high probability. For this reason, even when intelligent processing such as grammatical structure analysis is performed, a normal direction cannot be determined (see Fig. 34). Since it is improper to use such a character region in discrimination of the document direction, another character region must be used for direction discrimination. Therefore, in step S503, the difference between the average similarities of the first and second places is calculated. If the difference between the average similarities of the directions in the first and second places is small, the flow advances from step S504 to step S508 to use another character region in direction discrimination in place of the character region of interest. Furthermore, the count values of the numbers of characters in the four directions are different from each other, as described above. When the final number of characters is smaller than a predetermined value, the flow returns to step S3, and the remaining characters in the character region of interest are additionally cut out (steps S505 and S506). If all the characters have been cut out from the character region of interest, the processing is executed for another character region extracted in step S2, as has been described above with reference to the flow chart in Fig. 24. When the above-mentioned condition is satisfied, a direction having the maximum average similarity is determined as the direction of the image of interest, and the discrimination result is output (step S507). As described above, according to this embodiment, the direction of an original is discriminated by discriminating the direction of a character, and an image is rotated as needed on the basis of the discrimination result. Thereafter, the image is stored as electronic filing data. For this reason, even when an original image is read in a wrong direction, the read image is automatically rotated in a normal direction and the rotated image is stored, thus remarkably improving operability. Upon extraction of a feature amount of a rotated image from a cut-out region, since an image itself need not be rotated, the processing speed can be increased. As for 2-byte and 1-byte characters, since cut-out regions are combined to maximize similarity, the similarity can be calculated with high precision. In this embodiment, all the continuous 1-byte size cut-out regions are combined. Alternatively, only 1-byte size regions having similarities equal to or smaller than a predetermined value may be combined. According to the above embodiment, when the difference between the average similarities in the first and second places is equal to or smaller than the predetermined value, it is determined that the direction of an original cannot be discriminated, and direction discrimination processing is repeated using another character region. For this reason, the determination of a direction using numerals or the like which are difficult to identify the direction can be avoided, and the direction of an original can be determined with high precision. When a figure is described in an original document, characters in the figure may often be written in a direction different from a normal document direction. For example, as shown in Fig. 35, numerals that represent dimensions are often written in a direction different from a normal document direction. In the extraction of character regions in step S2 above, if characters in the figure or characters close to the figure are extracted, the character regions in the figure are ignored or are set to have low priority of discrimination processing so as to avoid use of such characters as much as possible. On the other hand, in the case of an original on which only characters in a figure or characters close to a figure are present, if there are a plurality of such originals, the image direction is determined by the majority of the respective discrimination results. Similarly, characters in a table may be numerals with high probability. Numerals such as "11, 6, 8, 9, 0" are difficult to discriminate even when they are rotated and are subjected to recognition processing. Thus, in the extraction of character regions in step S2, the use of a character region in a table is avoided as much as possible by setting low priority of discrimination processing. As a method of discriminating a character region, a figure, and a table from image data obtained by reading an original image, a method of extracting an independent group of black pixels from the image data, and discriminating an image on the basis of the size, arrangement, and the relationship between its inner and outer portions of the group is known. As a method of extracting black pixels, a labelling method, a method based on edge tracing, and the like are available. On the other hand, in step S2, character regions may be sorted in the size order, and may be used in direction discrimination in the order from larger character regions. Alternatively, upon extraction of character regions in step S2, if the number of characters in each character regions can be determined, the character regions may be sorted in the order of larger numbers of characters, and the character regions may be used in direction discrimination in the sorted order. In this manner, since the cut-out regions corresponding to the required number of characters can be obtained from the first character region with high probability, higher-speed processing is realized. Furthermore, in steps S2 and S3, a region having a predetermined size or larger is searched for from the character regions, and the found region may be used in direction discrimination. If this processing is performed up to the last character region, the skipped character region is used in direction discrimination. In this case, since processing such as sorting is not required, high-speed processing is assured when the number of extracted character regions is large. Furthermore, in the character cut-out processing in step S3, a predetermined number or more of characters may be cut out except for characters which cannot be discriminated as 1- or 2-byte size characters, and only the cut-out characters may be subjected to recognition in the 0°, 90°, 180°, and 270° directions to calculate similarities in units of angles. Since only characters which can be determined as either 1- or 2-byte size characters are used, the numbers of characters of the respective angles become equal to each other, and the management of the number of character is simplified. Since only a portion with high character cut-out precision is subjected to direction discrimination processing, the discrimination result can have high reliability. The same effect can be obtained when only 2-byte size cut-out regions are used. Furthermore, in a system in which the direction of an original is limited to either the portrait or landscape direction, discrimination of 0° or 180° need only be performed. In the above embodiment, the present invention is applied to the electronic filing apparatus. However, the present invention is not limited to this. For example, when the present invention is applied to a digital copying machine, if original pages have different directions, images in wrong directions can be automatically rotated, and all the images can be formed on recording sheets in a normal direction. Therefore, the page direction need not be manually adjusted later, thus improving operability. In the above embodiment, after an original image for one page is read, the direction discrimination of the image is performed. However, the present invention is not limited to this. For example, an original image may be read in units of portions (by band processing), and the read portions may be subjected to direction discrimination processing. When the discrimination result is obtained, the processing in units of bands is completed, and direction correction processing is started. With this control, since direction discrimination can be performed while scanning an original, the direction discrimination can be attained more quickly. Characters across bands are combined with those of previous bands. Since the recognition processing is not performed for all the characters in a document, high-speed processing can be performed. Since 2-byte size characters/1-byte size characters are discriminated in the four directions, unnecessary patterns that lower recognition precision can be removed, and the direction discrimination precision can be further improved. Since only characters which are assumed to be 2-byte size characters are used in discrimination, no discrimination based on recognition precision of 2-byte size characters/1-byte size characters is required. Since the numbers of characters in the four directions are equal to each other, the average similarities need not be calculated, and the image direction can be determined based on the sum totals of similarities. The present invention can be applied to a system constituted by a plurality of devices (e.g., host computer, interface, reader, printer) or to an apparatus comprising a single device (e.g., copy machine, facsimile). Further, the object of the present invention can be also achieved by providing a storage medium storing program codes for performing the aforesaid processes to a system or an apparatus, reading the program codes with a computer (e.g., CPU, MPU) of the system or apparatus from the storage medium, then executing the program. In this case, the program codes read from the storage medium realize the functions according to the embodiments, and the storage medium storing the program codes constitutes the invention. Further, the storage medium, such as a floppy disk, a hard disk, an optical disk, a magneto-optical disk, CD-ROM, CD-R, a magnetic tape, a non-volatile type memory card, and ROM can be used for providing the program codes. Furthermore, besides aforesaid functions according to the above embodiments are realized by executing the program codes which are read by a computer, the present invention includes a case where an OS (Operating System) or the like working on the computer performs a part or entire processes in accordance with designations of the program codes and realizes functions according to the above embodiments. Furthermore, the present invention also includes a case where, after the program codes read from the storage medium are written in a function expansion card which is inserted into the computer or in a memory provided in a function expansion unit which is connected to the computer, CPU or the like contained in the function expansion card or unit performs a part or entire process in accordance with designations of the program codes and realizes functions of the above embodiments.

Claims: An image processing apparatus for performing rotation of a bit map image of N bits x N lines image data by a multiple of 90°, said apparatus being characterised by comprising: first processing means (S151) for storing the upper half ( N / 2) lines of the image data in order and next to each other in a first memory (TEMP1) and storing the lower half ( N / 2) lines of the image data in order and next to each other in a second memory (TEMP 2); second processing means (S153, S161-S163) for (i) shifting the content of the first memory by a first predetermined amount and masking bits except for bits at a digit of interest, (ii) shifting the content of the second memory by a second predetermined amount and masking bits except for bits at the digit of interest, and (iii) storing the result obtained by a logical OR operation between the results of operations (i) and (ii) in a third memory (WORK); third processing means for storing in the third memory, the result of a logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory such that image data for a line of interest after rotation is obtained in the third memory; and control means (S154, S155) for repeatedly controlling said second and third processing means so as to perform the above operations N times with the first and the second shift amount being changed each time. Apparatus according to claim 1, wherein the value of N is eight, wherein in the case where the digit of interest in the image data to be rotated is represented by n, said second processing means performs (i) shifting of the content of the first memory to left by (n-4) bits and masking of bits except for the bits at the digit of interest, (ii) shifting the content of the second memory to right by n bits and masking of bits except for the bits at the digit of interest, and (iii) storing the result obtained by a logical OR operation between the results of operations (i) and (ii) to a third memory, wherein said third processing means performs (iv) storing, in the third memory, the result of the logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory to right by seven bits, and (v) storing in the third memory, the result of the logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory to right by fourteen bits, and wherein said control means controls said second and third processing means so as to repeat the operations eight times successively changing the value of n from zero to seven. Apparatus according to claim 2, wherein four pairs of bits in the image are arranged in positions after rotation by said second processing means, wherein two groups of four bits in the image data are arranged on positions after the rotation by operation (iv) performed by said third means, and wherein eight bits in the image data are arranged in positions after the rotation by operation (v) performed by said third means. Apparatus according to any preceding claim, further comprising output means for outputting an image based upon the image data. Apparatus according to claim 4, wherein said output means for outputting an image based upon the image data comprises a printer. An image processing method of performing rotation of a bit map image of N bits x N lines image data by a multiple of 90°, said method being characterised by comprising: utilising first processing means (S151) to store the upper half ( N / 2) lines of the image data in order and next to each other in a first memory (TEMP1) and to store the lower half ( N / 2) lines of the image data in order and next to each other in a second memory (TEMP 2); utilising second processing means (S153, S161-S163) to (i) shifting the content of the first memory by a first predetermined amount and masking bits except for bits at a digit of interest, (ii) shift the content of the second memory by a second predetermined amount and masking bits except for bits at the digit of interest, and (iii) store the result obtained by a logical OR operation between the results of operations (i) and (ii) in a third memory (WORK); and utilising third processing means to store in the third memory, the result of a logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory such that image data for a line of interest after rotation is obtained in the third memory; and repeatedly controlling said second and third processing means so as to perform the above operations N times with the first and the second shift amount being changed each time. A method according to claim 6, wherein the value of N is eight, wherein in the case where the digit of interest in the image data to be rotated is represented by n, said second processing means performs (i) shifting of the content of the first memory to left by (n-4) bits and masking of bits except for the bits at the digit of interest, (ii) shifting the content of the second memory to right by n bits and masking of bits except for the bits at the digit of interest, and (iii) storing the result obtained by a logical OR operation between the results of operations (i) and (ii) to a third memory, wherein said third processing means performs (iv) storing, in the third memory, the result of the logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory to right by seven bits, and (v) storing in the third memory, the result of the logical OR operation between the data stored in the third memory and data obtained by shifting the data stored in the third memory to right by fourteen bits, and wherein said control means controls said second and third processing means so as to repeat the operations eight times successively changing the value of n from zero to seven. A method according to claim 7, wherein four pairs of bits in the image are arranged in positions after rotation by said second processing means, wherein two groups of four bits in the image data are arranged on positions after the rotation by operation (iv) performed by said third means, and wherein eight bits in the image data are arranged in positions after the rotation by operation (v) performed by said third means. A method according to any one of claims 6 to 8, further comprising output means for outputting an image based upon the image data. A method according to claim 9, wherein said output means for outputting an image based upon the image data comprises a printer. A storage medium for storing processor implementable instructions for controlling a processor to carry out the method of any one of claims 6 to 10. An electrical signal carrying processor implementable instructions for controlling a processor to carry out the method of any one of claims 6 to 10.

Inventors: TANAKA TETSUOMI, TANAKA, TETSUOMI
Applicants: CANON KK, CANON KABUSHIKI KAISHA
Application year: 1996
Main classification: G06T3
IPC codes: G06T3