# Patent

## Title
Apparatus, method, and computer-readable storage medium for lossy and lossless encoding of image data in accordance with an attribute of the image data

## Abstract

Encoded data of a target data amount can be generated by one image input operation in which both lossless encoding and lossy encoding are adopted. For this purpose, a first encoding unit, which generates lossy encoded data, a second encoding unit, which generates lossless encoded data, and an attribute determination unit, which detects a number of colors in a pixel block to be encoded parallel-process a same pixel block. When a number of colors in the pixel block of interest is equal to or smaller than a predetermined number, an encoding sequence control unit stores lossless encoded data in a first memory. When the number of colors exceeds the predetermined number, the encoding sequence control unit stores encoded data of a shorter code length among lossy encoded data and lossless encoded data in the first memory.

## Background
CLAIM OF PRIORITY
This application claims priority from Japanese Patent Application Nos. 2004-331114, filed on Nov. 15, 2004, and 2005-322691, filed on Nov. 7, 2005, which are hereby incorporated by reference herein.
FIELD OF THE INVENTION
The present invention relates to a technique of encoding image data.
BACKGROUND OF THE INVENTION
Conventionally, still image data is often compressed by a method using discrete cosine transform or a method using Wavelet transform. Encoding of this type is variable-length encoding, and hence the encoded data amount changes for each image to be encoded.
According to JPEG encoding as an international standardization scheme, only one quantization matrix can be defined for an image, and it is difficult to make encoded data of one image (document) fall within a target encoded data amount without pre-scan. When JPEG encoding is used in a system which stores data in a limited memory, a memory overflow may occur.
In order to prevent this, there is a method of re-reading the same document upon changing the compression ratio parameter when the actual encoded data amount exceeds an expected encoded data amount. There is also proposed a method of estimating an encoded data amount in advance by pre-scan and re-setting quantization parameters to adjust the encoded data amount.
As described above, pre-scan and actual scan are generally executed, but a document must be read at least two times at poor efficiency. Especially when a copying machine encodes a document of a plurality of sheets (pages) while successively reading it page by page by an ADF (Auto Document Feeder), it is impossible in terms of the process time to read the same document twice.
There is known a technique of eliminating these two, pre-scan and actual scan operations, and encoding one entire image using a common encoding parameter to compress the encoded data into a target encoded data amount (Japanese Patent Laid-Open No. 2003-8903 (corresponding US Pre-Grant Publication No. AA2003002743); to be referred to as reference 1 hereinafter). According to this technique, encoded data are sequentially stored in two memories during one image input operation (for one page). When the amount of encoded data in a predetermined memory exceeds a predetermined size during this operation, the data in the predetermined memory is discarded, and the current encoding parameter is updated to a new encoding parameter for increasing the compression ratio. At the updated encoding parameter, encoding of image data of an unencoded part continues (encoded data obtained at this time is defined as the first encoded data). At this time, encoded data obtained by encoding before the compression ratio is increased are stored in the other memory. The encoded data are re-encoded in accordance with the updated parameter, attaining encoded data identical to those obtained by encoding data at the new parameter from the beginning (encoded data obtained by re-encoding is defined as the second encoded data). The first and second encoded data are concatenated. As a result, data (complying with JPEG encoding) which is encoded at a common encoding parameter (updated encoding parameter) for one entire image (of one page) can be obtained. In addition, the encoded data amount can be suppressed to a target encoded data amount.
Unlike the technique of executing re-encoding in accordance with the encoded data amount in the process of encoding, as described in reference 1, there is also known a technique of keeping an entire image at a predetermined encoded data amount while selectively applying either of lossless encoding and lossy encoding to a plurality of areas in an image (e.g., Japanese Patent Laid-Open No. 10-224640 (corresponding U.S. Pat. No. 6,067,382)).
Compression encoding in reference 1 adopts only a lossy compression technique such as JPEG.
According to the encoded data amount control technique in reference 1, when an encoded data amount generated during encoding of a 1-page image exceeds a predetermined size, a process equivalent to uniquely increasing the compression ratio for the entire page is executed. This may partially degrade the image quality more than expected. This problem becomes more serious in compressing an image containing a character/line image.
There is known a lossless encoding technique “JPEG-LS”. “JPEG” is prefixed to this technique, but its encoding algorithm is completely different from general lossy JPEG. JPEG-LS is known to be lower in compression ratio for natural images than JPEG, but be able to lossless encode character/line images and computer graphics at a higher compression ratio.
Considering this, when a document image containing both photographic and character images in one page is to be compressed, lossless compression should be applied to a character/line image part as much as possible.
SUMMARY OF THE INVENTION
Hence, demands arise for a technique using both lossy compression and lossless compression in order to make an encoded data amount fall within a target data amount by one image data input operation, i.e., without inputting image data again, similar to reference 1, when a document is to be compressed. In an application of lossy encoding to part or all of an image, a common encoding parameter needs to be used for the image. It is an object of the present invention to solve these problems.
In order to solve the problems, an image encoding apparatus according to the present invention has, for example, the following arrangement.
That is, there is provided an image encoding apparatus which receives image data and encodes the image data, comprising
first encoding means for lossy encoding input image data for each predetermined pixel block in accordance with a first parameter to generate lossy encoded data,
second encoding means for lossless encoding input image data for the predetermined pixel block to generate lossless encoded data,
a first memory which stores one of the encoded data from the first encoding means and the second encoding means,
a second memory which stores the encoded data generated by the second encoding means,
monitoring means for determining whether an encoded data amount stored in the first memory has exceeded a predetermined target data amount,
attribute determination means for detecting an attribute of a predetermined pixel block in input image data and determining whether detected attribute information satisfies a predetermined condition,
first selection means for, when the attribute determination means determines that the detected attribute information satisfies the predetermined condition, selecting the lossless encoded data from the second encoding means in order to store the lossless encoded data in the first memory,
second selection means for, when the attribute determination means determines that the detected attribute information does not satisfy the predetermined condition, selecting encoded data of a shorter code length among the encoded data from the first encoding means and the second encoding means in order to store the encoded data in the first memory,
re-encoding means for decoding the lossless encoded data in the second memory, re-encoding the decoded data in accordance with a second parameter to generate lossy encoded data, and storing, in the first memory, encoded data of a shorter code length among the lossy encoded data obtained after re-encoding and the lossless encoded data before re-encoding,
determination condition change means for, when the monitoring means determines that the encoded data amount has exceeded the predetermined data amount, changing a determination condition of the attribute determination means, and
parameter update means for, when the monitoring means determines that the encoded data amount has exceeded the predetermined data amount, (a) discarding the encoded data in the first memory, (b) updating the first parameter set for the first encoding means to a parameter having a high compression ratio, and causing the first encoding means to continue encoding of the image data, and (c) setting, as the second parameter, the same parameter as the updated first parameter for the re-encoding means, and causing the re-encoding means to re-encode lossless encoded data obtained before the encoded data amount exceeds the predetermined data amount.
Other features and advantages of the present invention will be apparent from the following description taken in conjunction with the accompanying drawings, in which like reference characters designate the same or similar parts throughout the figures thereof.



BRIEF DESCRIPTION OF THE DRAWINGS
The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the invention and, together with the description, serve to explain the principles of the invention.
FIG. 1 is a block diagram showing an encoding unit according to the first embodiment;
FIG. 2 is a block diagram showing a modification of the encoding unit according to the first embodiment;
FIG. 3 is a flowchart showing a simplified flow of a process according to the first embodiment;
FIG. 4 is a view showing a data flow and memory contents in the encoding phase in an initial state according to the first embodiment;
FIG. 5 is a view showing a data flow and memory contents at the start of the encoding/re-encoding phase according to the first embodiment;
FIG. 6 is a view showing a data flow and memory contents at the end of the encoding/re-encoding phase according to the first embodiment;
FIG. 7 is a view showing a data flow and memory contents in the transfer phase according to the first embodiment;
FIG. 8 is a view showing a data flow and memory contents in the encoding phase after the transfer phase according to the first embodiment;
FIG. 9 is a flowchart showing details of the process according to the first embodiment;
FIG. 10 is a view showing a data flow and memory contents at the start of the encoding/re-encoding phase in the arrangement of FIG. 2;
FIG. 11 is a view showing a data flow and memory contents in the transfer phase in the arrangement of FIG. 2;
FIG. 12 is a view showing a data flow and memory contents in the encoding phase after the transfer phase in the arrangement of FIG. 2;
FIG. 13 is a timing chart showing an example of transition of the value of the first counter according to the first embodiment;
FIG. 14 is a block diagram showing another modification of the encoding unit according to the first embodiment;
FIG. 15 is a flowchart showing a process sequence in the arrangement of FIG. 14;
FIG. 16 is a view showing a data flow and memory contents in the encoding phase in an initial state in the arrangement of FIG. 14;
FIG. 17 is a view showing a data flow and memory contents when the encoded data amount exceeds a target data amount in the arrangement of FIG. 14;
FIG. 18 is a view showing a data flow and memory contents upon the completion of the encoding/re-encoding phase in the arrangement of FIG. 14;
FIG. 19 is a view showing a data flow and memory contents in the encoding phase after the encoding/re-encoding phase in the arrangement of FIG. 14;
FIG. 20 is a block diagram showing a re-encoding unit according to the embodiment;
FIG. 21 is a view showing a quantization matrix table used in the embodiment:
FIG. 22 is a block diagram showing a copying machine to which the embodiment is applied;
FIG. 23 is a flowchart showing an encoded data selection process sequence according to the first embodiment;
FIG. 24 is a flowchart showing an encoded data selection process sequence according to the second embodiment;
FIG. 25 is a flowchart showing an encoded data selection process sequence according to the third embodiment;
FIG. 26 is a block diagram showing an encoding unit according to the fourth embodiment;
FIG. 27 is a graph showing the change curve of a weighting coefficient α according to the fourth embodiment; and
FIG. 28 is a flowchart showing an encoded data selection process sequence according to the fourth embodiment.



DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
Preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
<Description of Outline of Apparatus>
FIG. 22 is a block diagram showing a copying machine to which an embodiment is applied.
In FIG. 22, reference numeral 1 denotes a control unit which controls the overall apparatus, and is made up of a CPU, ROM, RAM, and the like. Reference numeral 2 denotes an operation unit which is made up of an LCD display, various switches, buttons, and the like. Reference numeral 3 denotes a document reading unit (image scanner unit) which includes an ADF (Auto Document Feeder). The document reading unit 3 outputs a read image as digital data of 8 bits (256 gray levels) for each of R, G, and B color components. Reference numeral 4 denotes a rendering unit which renders a print image on the basis of PDL print data received via an interface (including a network interface: not shown). Reference numeral 5 denotes a selector which selects and outputs one of bitmap images output from the document reading unit 3 and rendering unit 4 in accordance with an instruction from the control unit 1.
Reference numeral 6 denotes an encoding unit which is a feature of the embodiment. Although details of the encoding unit 6 will be described later, the encoding unit 6 encodes image data.
Reference numeral 7 denotes a secondary storage device (in the embodiment, a hard disk drive) which sequentially stores encoded data output from the encoding unit 6.
Reference numeral 8 denotes a decoding unit which reads out and decodes, in the storage order, compression-encoded image data that are stored in the secondary storage device 7. Reference numeral 9 denotes an image processing unit which receives a decoded image from the decoding unit 8, and performs conversion from an RGB color space into a YMC print color space, a UCR (Under Color Removal) process, and in addition an image data correction process.
Reference numeral 10 denotes a printer engine unit whose printing mechanism is a laser beam printer engine, but can be of an arbitrary type for, e.g., discharging liquid ink.
In the above arrangement, for example, the user operates the operation unit 2 to select a copy mode, sets a document on (the ADF of) the document reading unit 3, and presses a copy start key. Then, document image data read by the document reading unit 3 are transferred in the raster order to the encoding unit 6 via the selector 5, compression-encoded by the encoding unit 6, and stored in the secondary storage device 7.
When print data is externally received, the selector 5 selects the rendering unit 4, an image based on print data generated by the rendering unit 4 is compression-encoded, and the encoded data is stored in the secondary storage device 7.
The decoding unit 8 reads out compression-encoded data from the secondary storage device 7, and decodes the readout data in accordance with the print speed of the printer engine 10. The image processing unit 9 generates print image data of Y, M, C, and K components from the decoded image data. The image processing unit 9 outputs the process result to the printer engine unit 10 to print.
As described above, a compression-encoded data storage process to the secondary storage device 7 and a read process for decoding and printing are asynchronous. That is, the secondary storage device 7 functions as a buffer interposed between an image compression process and a decoding process. Since a document reading/encoding process is independent of a decoding/printing process, many documents can be read at a high speed, and the process can quickly shift to document reading of the next job.
The arrangement of the overall apparatus in the embodiment has-been described. The encoding unit 6 as a feature of the apparatus will be explained in the following embodiments.
First Embodiment
FIG. 1 is a block diagram showing an encoding unit 6 according to the first embodiment. Each unit in FIG. 1 will be briefly explained.
An input unit 101 incorporates a line buffer memory for a plurality of lines. As described above, the input unit 101 receives image data from a document reading unit 3 or rendering unit 4 via a selector 5 in the raster order, and stores the image data in the internal line buffer. The input unit 101 then reads out image data by a block of N×M pixels (in the first embodiment, a block of 8×8 pixels), and outputs the image data.
A first encoding unit 102 is a lossy encoding unit which compression-encodes each pixel block input from the input unit 101 in accordance with a parameter that influences the compression ratio, and outputs the result (encoded data). An identification bit representing that data has been encoded by the first encoding unit 102 is added at the start of the encoded data.
The image encoding unit 102 according to the first embodiment adopts JPEG encoding (lossy encoding). More specifically, image data corresponding to 8×8 pixels is orthogonally transformed, quantized using a quantization step (to be described later), and undergoes a Huffman encoding process. The quantization step determines a generated amount of encoded data, and is set by an encoding sequence control unit 110 as an encoding parameter which influences the compression ratio. JPEG encoding is known as a technique suitable for natural images.
FIG. 21 shows quantization matrix tables Q0, Q1, and Q2 which are used to quantize the frequency coefficient after DCT transformation (which are stored and held in the encoding sequence control unit 110). Values Qi(0,0) to Qi(7,7) (i=0, 1, 2, . . . ) in the quantization matrix table mean quantization step values. Quantization step values substantially satisfy Q0<Q1<Q2 . . . . As the quantization step value increases, a possible range of the frequency coefficient value after quantization narrows, and the compression ratio increases.
A second encoding unit 103 is a lossless encoding unit, unlike the first encoding unit 102. Because of lossless encoding, the decoding result is identical to an image before encoding, and the image quality does not degrade in principle. In the first embodiment, the second encoding unit 103 adopts JPEG-LS. “JPEG” is prefixed to JPEG-LS, but its algorithm is completely different from lossy encoding “JPEG” which is employed in the first encoding unit. JPEG-LS encoding is suited to character/line images and computer graphics. An encoded data amount obtained when such an image is encoded using JPEG-LS can be decreased from an encoded data amount generated at a quantization step “1” (substantially lossless) given to lossy encoding “JPEG”, and also a relatively small quantization step value such as “2” or “3”.
At substantially the same timing as that of the first encoding unit 102, the second encoding unit 103 encodes the same pixel block and outputs encoded data. In outputting encoded data, the second encoding unit 103 adds at the start of the encoded data an identification bit representing that the data has been encoded by the second encoding unit 103.
A first code length detection unit 108 detects the encoded data length (including one bit serving as an identification bit) for a pixel block that is that is output from the first encoding unit 102, and outputs the detected length to the encoding sequence control unit 110. A second code length detection unit 109 detects the encoded data length (including one bit serving as an identification bit) of a pixel block output from the second encoding unit 103, and outputs the detected length to the encoding sequence control unit 110.
An attribute determination unit 130 determines the attribute of an 8×8 pixel block at almost the same timing as those of the first and second encoding units 102 and 103, and outputs the determination result to the encoding sequence control unit 110. In order to simplify calculation, the attribute determination unit 130 in the first embodiment counts the number of colors present in an 8×8 pixel block, and outputs color count information to the encoding sequence control unit 110. Because of 8×8 pixels, the maximum number of colors is 64, and the minimum number of colors is 1.
The encoding sequence control unit 110 controls the encoding unit 6 in the first embodiment. One of processes by the encoding sequence control unit 110 is a process of generating a control signal to a first memory control unit 104 so that encoded data from either the first encoding unit 102 or the second encoding unit 103 is stored in a first memory 105 on the basis of signals from the first code length detection unit 108, second code length detection unit 109, and attribute determination unit 130.
More specifically, when the number of colors in a block of interest that is announced from the attribute determination unit 130 is equal to or smaller than a predetermined number (n colors), the encoding sequence control unit 110 generates a signal for unconditionally adopting encoded data from the second encoding unit 103 as encoded data of the block. When the number of colors in a block of interest exceeds the predetermined number, the encoding sequence control unit 110 compares a code length from the first code length detection unit 108 and that from the second code length detection unit 109, and generates a signal for adopting encoded data of a shorter code length.
When the encoded data amount exceeds a target data amount after the start of encoding one page, the encoding sequence control unit 110 sets the threshold of the number of colors in the attribute determination unit to the number of (n-1 colors) which is smaller than the current number of colors.
With this setting, when the encoded data amount exceeds a target data amount, the rate at which encoded data from the second encoding unit 103 is unconditionally employed can be decreased, and the total encoded data amount can be decreased by comparing code lengths based on the two encoding methods.
As described above, the encoding sequence control unit 110 generates a control signal for storing encoded data from either the first encoding unit 102 or the second encoding unit 103 in the first memory 105 for each block.
A process which implements the above operation is, e.g., a process shown in FIG. 23. More specifically, in step S2301, it is determined whether the value of a counter 111 has exceeded a target data amount even once during encoding of one page after the start of encoding the page. At the start of encoding one page, the result of determination is “NO”, and the flow advances to step S2302. In step S2302, it is determined whether the number of colors in a pixel block of interest (output from the attribute determination unit 130) is equal to or smaller than a predetermined number. If the number of colors is equal to or smaller than the predetermined number, encoded data from the second encoding unit 103 is selected as encoded data to be stored in the first memory 105. At this time, code length information from the second code length detection unit 109 is accumulated and added to the first counter 111.
If YES in step S2301 or NO in step S2302, the flow advances to step S2304 to select encoded data of a shorter code length among two encoded data as encoded data to be stored in the first memory 105. At this time, code length information of the selected encoded data is accumulated and added to the first counter 111. Note that a flag which is cleared to 0 at the start of encoding one page may be prepared for determination in step S2301. If it is determined that the value of the first counter 111 exceeds a target data amount even once, the flag is set to 1. Based on the flag, determination is made.
In this manner, the first counter 114 in the encoding sequence control unit 110 is reset at the start of encoding one page, and the code length of encoded data stored in the first memory 105 for each pixel block is accumulated and added to the first counter 111.
The first memory control unit 104 writes/deletes encoded data in/from the first memory 105 under the control of the encoding sequence control unit 110. The first memory 105 stores encoded data which is finally defined upon the completion of 1-page encoding, and stores encoded data to be output to a secondary storage device 7.
A second memory control unit 106 performs a process of storing encoded data generated by the second encoding unit 103 in a second memory 107, and a process of reading out encoded data from the second memory 107 under the control of the encoding sequence control unit 110. The second memory 107 is used as a work area when 1-page image data is encoded.
A re-encoding unit 112 re-encodes encoded data in a range designated by the encoding sequence control unit 110 out of encoded data (lossless encoded data) stored in the second memory 107. The re-encoding unit 112 has, e.g., an arrangement in FIG. 20.
Since the second memory 107 stores data encoded by the second encoding unit (JPEG-LS encoding unit) 103, the encoded data is decoded (reconstructed) into a pixel block of an original image by a JPEG-LS decoding unit 112a. A JPEG encoding unit 112b JPEG-encodes (lossy encodes) the reconstructed pixel block in accordance with a quantization matrix table set by the encoding sequence control unit 110. A selector 112c selects and outputs a smaller one of the lossy encoded data output from the JPEG encoding unit 112b and the lossless encoded data before re-encoding. This process is repetitively executed for a range designated by the encoding sequence control unit 110. A second counter 113 is reset at the start of re-encoding by the re-encoding unit 112, and accumulates and counts an encoded data amount generated by the re-encoding unit 112. Upon the completion of re-encoding in the set range, a value (encoded data amount generated by re-encoding) held in the second counter is output to the encoding sequence control unit 110.
The arrangement in FIG. 1 has been described, and the overall process will be explained in more detail.
When encoding of 1-page image data starts, a target data amount corresponding to an input image size is set by a control unit 1 in the encoding sequence control unit 110. The encoding sequence control unit 110 sets the initial quantization matrix table Q0 (encoding parameter corresponding to the highest image quality and lowest compression ratio) for the first encoding unit 102, and clears the first counter 111 to 0. The encoding sequence control unit 110 causes the first and second encoding units 102 and 103 to start an encoding process.
The following description pertains to an encoding process immediately after input of 1-page image data starts.
The first and second code length detection units 108 and 109 output encoded data of the same pixel block, and obtain code lengths. The attribute determination unit 130 outputs color count information of the pixel block to the encoding sequence control unit 110. When the number of colors that is announced from the attribute determination unit 130 is equal to or smaller than a predetermined number, the encoding sequence control unit 110 adds the data length of encoded data from the second encoding unit 103 to the first counter 111. At this time, the encoding sequence control unit 110 issues a control signal to the first memory control unit 104 so as to store encoded data from the second encoding unit 103 in the first memory 105.
When the number of colors that is announced from the attribute determination unit 130 exceeds the predetermined number, the encoding sequence control unit 110 selects a shorter one of the code lengths from the first and second code length detection units 108 and 109, and adds the selected code length to the first counter 111. At this time, the encoding sequence control unit 110 outputs to the first memory control unit 104 a control signal representing which of the code lengths has been selected, and stores encoded data of the shorter code length in the first memory 105. When the two code lengths are equal to each other, the encoding sequence control unit 110 outputs a control signal representing that lossless encoded data has been selected.
The first memory control unit 104 receives the control signal from the encoding sequence control unit 110, selects one of encoded data output from the first and second encoding units 102 and 103, and stores the selected encoded data in the first memory 105.
As a result, the first memory 105 stores encoded data of a shorter code length for each pixel block of image data. That is, the first memory 105 stores both lossless encoded data and lossy encoded data. To the contrary, the second memory 107 stores only lossless encoded data.
It should be noted that the first counter 111 stores information representing the total encoded data amount of encoded data stored in the first memory 105.
While the encoding process for a 1-page image progresses, the encoding sequence control unit 110 monitors the value of the first counter 111, i.e., the total amount of encoded data stored in the first memory 105, and determines whether the total amount has exceeded the target data amount (or determines whether the total amount has reached the target data amount). If the encoding sequence control unit 110 determines that the value (total encoded data amount) held by the first counter 111 has exceeded the target data amount, the encoding sequence control unit 110 executes the following process.

    1. The encoding sequence control unit 110 outputs a control signal to the first memory control unit 104 so as to discard data stored in the first memory 105. Based on the control signal, the first memory control unit 104 discards the stored encoded data by clearing the memory address counter or clearing the encoded-data management table.
    2. The encoding sequence control unit 110 clears the first counter 111 to 0 (input of an image from the input unit 101 continues).
    3. The encoding sequence control unit 110 updates the quantization matrix table in order to cause the first encoding unit 102 to perform encoding at a compression ratio higher than the current one. When the currently set quantization matrix table is Qi, the encoding sequence control unit 110 sets a quantization matrix table Qi+1. Since the quantization matrix table Q0 is set in the initial state, the quantization matrix table Q1 is set when it is determined for the first time that the total amount has exceeded the target amount.
    4. The encoding sequence control unit 110 clears the second counter 113 to 0, sets the quantization matrix table Qi+1 for the re-encoding unit 112, and starts re-encoding of encoded data stored in the second memory 107. Encoded data (including both lossless and lossy encoded data) obtained by re-encoding are stored again in the second memory 107. The second memory 107 also stores encoded data from the second encoding unit 103, and the encoded data from the first and second encoding units 102 and 103 are distinctively stored.
    5. Upon the completion of re-encoding, the encoding sequence control unit 110 transfers the encoded data stored “again” in the second memory 107 to the first memory 105, and deletes the data from the second memory (encoded data from the encoding unit 103 is not deleted). The encoding sequence control unit 110 reads out the value of the second counter 113, and adds it to the first counter 111. As a result, the first counter 111 indicates again the total amount of encoded data stored in the first memory.
    6. The encoding sequence control unit 110 changes the threshold (predetermined number of colors) of the number of colors used to determine the number of colors by the attribute determination unit 130 to a smaller threshold.


Note that information from the attribute determination unit 130 may be excluded from conditions for selecting encoded data for the first memory 105. In this case, encoded data of a shorter code length is stored in the first memory 105 on the basis of two pieces of code length information from the first and second code length detection units 108 and 109.
Whether the re-encoding process has ended is detected by the second memory control unit 106. If no data to be read out for the re-encoding process is detected, the second memory control unit 106 notifies the encoding sequence control unit 110 of the end of the re-encoding process. In practice, the encoding process is completed after not only the read process by the second control unit 106 but also the process of the re-encoding unit 112 end.
If the encoding sequence control unit 110 determines that the total encoded data amount has exceeded the target data amount again before input and encoding of a 1-page image are completed, the encoding sequence control unit 110 executes steps 1 to 6 above. Finally, the first memory 105 stores encoded data of the target data amount or less.
The process sequence of the encoding sequence control unit 110 in the arrangement of FIG. 1 is shown in the flowchart of FIG. 9. For descriptive convenience, this process will be described first with reference to the simplified flowchart of FIG. 3.
The flowchart of FIG. 3 is roughly divided into the following three process phases:
(1) an encoding phase,
(2) an encoding/re-encoding phase, and
(3) a transfer phase.
FIGS. 4 to 8 visually and simply show how image data, encoded data, and the like flow and are processed and how they are stored in the memories in the respective process phases.
FIG. 4 shows the initial state of the encoding phase corresponding to steps S303 and S305 in the flowchart of FIG. 3.
Note that a switch 40 in FIG. 4 selects either of encoded data from the first and second encoding units 102 and 103 in accordance with pieces of information from the first code length detection unit 108, second code length detection unit 109, and attribute determination unit 130 while it is determined that the value of the first counter 111 does not exceed a target data amount after the start of encoding one page. The switch 40 is implemented by the functions of the encoding sequence control unit 110 and first memory control unit 104. The first memory 105 stores encoded data of a shorter code length among encoded data from the two encoding units. This maintains a relation in which a data amount I in the first memory 105 is smaller than a data amount I′ in the second memory 107.
FIG. 5 shows a state when the quantization matrix table is changed in step S309. As shown in FIG. 5, no encoded data is stored in the first memory 105.
FIG. 6 shows the process state of the encoding/re-encoding phase corresponding to steps S311 to S315. FIG. 7 shows the process state of the transfer phase corresponding to step S317. FIG. 8 shows the process state of the encoding phase after the transfer phase. Each phase will be described below.
<<Encoding Phase>>
An encoding process of 1-page image data starts from an encoding parameter initialization process (step S301). Step S301 is a process of setting the quantization matrix table Q0 to be applied to the first encoding unit 102, and a target data amount for an encoded data amount that is uniquely determined from an image size (paper size read by the input unit 101 for page description rendering or the like) subjected to an encoding process.
In step S303, an encoding process starts by the first encoding unit 102, second encoding unit 103, and attribute determination unit 130.
Consequently, the first memory 105 stores, for each pixel block, encoded data from the second encoding unit 103 unconditionally when the number of colors in the pixel block is equal to or smaller than a predetermined number. When the number of colors in the pixel block exceeds the predetermined number, encoded data of a shorter code length among encoded data from the first and second encoding units 102 and 103 is stored in the first memory 105. The encoded data amount in the first memory 105 is counted by the first counter, as described above. The second memory 107 stores encoded data from the second encoding unit 103. FIG. 4 shows this state. The area I representing a data amount in the first memory 105 is at least equal to or narrower than the area I′ representing a data amount in the second memory 107.
In step S305, it is checked whether the count value of the data amount has exceeded the target value. If NO in step S305, the first and second encoding processes in step S303 continue. This is the encoding phase in the initial state.
<<Encoding/Re-Encoding Phase>>
As the encoding process proceeds and the total encoded data amount in the first memory exceeds the target amount, encoded data in the first memory 105 is discarded in step S307. In step S309, the quantization matrix table Q0 set for the first encoding unit 102 is updated to the next quantization matrix table Q1. That the total encoded data amount exceeds a target data amount means that the data amount after compression does not fall within the target amount. Since it is useless to continue the encoding process by using the same quantization step, the quantization step is changed to the quantization step Q1 which is larger in quantization step width than the quantization step Q0.
After the quantization step is changed, the encoding process by the first and second encoding units 102 and 103 resumes in step S311. After that, i.e., after it is determined for the first time that the value of the first counter 111 exceeds the target data amount, the encoding sequence control unit 110 further decreases the threshold for color count information from the attribute determination unit 130. The encoding sequence control unit 110 changes the process such that encoded data from the second encoding unit 103 is unconditionally adopted when the number of colors present in an 8×8 pixel block is equal to or smaller than a predetermined threshold of the number of colors, or encoded data of a shorter code length among the two encoded data is stored in the first memory 105 when the number of colors exceeds the threshold.
The encoding sequence control unit 110 sets the quantization matrix table Q1 (identical to the updated quantization matrix table set for the first encoding unit) for the re-encoding unit 112. The encoding sequence control unit 110 causes the re-encoding unit 112 to start re-encoding of the encoded data amount in the second memory. The re-encoding result is stored again in the second memory. This state is shown in FIG. 5.
In step S315, the flow waits until the re-encoding process is completed.
<<Transfer Phase>>
FIG. 6 shows the storage state of encoded data in the first and second memories 105 and 107 when it is determined in step S315 that re-encoding is completed. In FIG. 6, areas II and II′ represent encoded data corresponding to newly input image data during the re-encoding process. The area I represents the result (including both lossy and lossless encoded data) of re-encoding encoded data stored in the area I′.
In step S317, as shown in FIG. 7, re-encoded data (area I in FIG. 7) stored in the second memory 107 is transferred to the first memory 105. Upon the completion of transfer, the data in the area I of the second memory 107 is discarded (or overwrite is permitted).
After the end of the transfer phase, the flow returns to the encoding phase in steps S303 and S305. As a result, as shown in FIG. 8, encoded data III and III′ of newly input image data are stored in the respective memories. This encoding phase is slightly different from the encoding phase in the initial state (FIG. 4). The difference is that the quantization step used for encoding by the first encoding unit 102 is changed from Q0 to Q1, and that the order of encoded data stored in the first memory 105 does not coincide with the image input order. Except these differences, the encoding phase immediately after the transfer phase and that in the initial state can be regarded to be identical. The order of encoded data is not always time series, as shown in FIG. 8. However, the storage address in each phase is separately stored, and when an encoding process for one page is completed and the encoded data is to be output to the secondary storage device 7, the encoded data are read out and output in time series from the first memory 105.
By repeating the three, encoding, encoding/re-encoding, and transfer phases, codes obtained by compressing 1-page image data into a set data amount or less can be finally stored in the first memory 105. The input unit 101 only continues input operation until the end of a series of processes. That is, no image need be input again from the beginning.
The flowchart shown in FIG. 3 describes only processes corresponding to the respective phases shown in FIGS. 4 to 8 for easy understanding. In practice, however, input of 1-page image data comes to an end in some phase. Depending on the phase where the input operation comes to an end, the subsequent process slightly differs. The flowchart of FIG. 9 shows the flow of a process in consideration of this. The flowchart of FIG. 9 is based on the relationship between the completion of input of 1-page image data and each kind of process described with reference to FIG. 3. In this case, steps S801, S803, S805, and S807 are added to the flowchart of FIG. 3.
In steps S801, S803, and S805, it is checked whether input of 1-page image data from the input unit 101 is completed in the encoding phase, encoding/re-encoding phase, and transfer phase.
If it is detected that input of 1-page image data is completed in the encoding phase and transfer phase (steps S801 and S805), the flow advances to step S807 to terminate a compression encoding process for the page. If there is image data of one page or more to be compressed next, the compression encoding process for the next 1-page image data starts. If there is no data to be compressed, a halt condition is set. To start encoding from the start of one page, information from the attribute determination unit 130 is added to conditions for storage in the first memory 105.
If the end of input of 1-page image data is detected in the encoding/re-encoding phase (step S803), the operation of the first and second encoding units 102 and 103 need be stopped until there is no image data to be re-encoded. For this reason, the encoding process in step S311 is passed, and only the re-encoding process is continued in step S313 to suppress, within a predetermined encoded data amount, image data which have already been encoded by the first and second encoding units 102 and 103. If the subsequent transfer process is not terminated after the re-encoding process is terminated for all data, the overall encoded data of 1-page image data is not collected in the first memory. Thus, the re-encoding process and subsequent transfer process must be continuously performed even after the end of input of 1-page image data. In this case, if it is detected in step S315 that the re-encoding process is terminated for all data, the encoded data stored in only the second memory 107 is transferred to the first memory during the encoding/re-encoding phase (step S317). Thereafter, the end of input of 1-page image data is detected in step S805, and the flow advances to step S807.
The above description has been made for operation in the first embodiment and is also a description of the operation in FIG. 9.
As described above, according to the first embodiment, when the number of colors in a pixel block of interest is equal to or smaller than a predetermined number during an encoding process from the start of a 1-page image for each pixel block, this means that the block is a character/line image at high probability. Thus, encoded data from the second encoding unit 103 which performs lossless encoding is preferentially stored in the first memory 105. When the number of colors in a pixel block of interest exceeds the predetermined number, encoded data of a shorter code length among encoded data from the two encoding units is stored in the first memory 105.
Resultantly, when encoding of one page is completed before encoded data stored in the first memory 105 exceeds a target encoded data amount, the decoded image maintains high quality. If the encoded data amount exceeds a target data amount during the encoding process, the condition on the number of colors in a pixel block is relaxed, and encoded data of a shorter code length tends to be stored. Encoded data of a target encoded data amount or less can be generated without interrupting input of a 1-page image while different encoding techniques provided by the first encoding unit 102 which generates lossy encoded data and the second encoding unit 103 which generates lossless encoded data are adopted.
It should be noted that the first embodiment uses the two, JPEG and JPEG-LS techniques. JPEG encoding is known to have a high compression ratio for natural images. To the contrary, JPEG-LS encoding is known to have a high compression ratio for character-line images.
For this reason, the image encoding unit 6 according to the first embodiment can be expected to provide the following operation effects. In the following description, a target encoded data amount is set on the assumption that one entire page is a natural image.

    1. For a general document which is formed from only characters, JPEG-LS-encoded data (lossless encoded data) from the second encoding unit 103 is highly likely to be selected as encoded data of each pixel block that is to be stored in the first memory 105 under the condition of the number of colors and the condition of the code length. Also, it can be expected that the compression ratio at this time is very high and encoding is completed while the total encoded data amount is suppressed within a target encoded data amount. Because of lossless encoded data, the print result is faithful to an original image, and the image quality of the print result becomes substantially equal to that obtained without the mediacy of encoding.
    2. When a document is formed from only a natural image, JPEG-encoded data (lossy encoded data) from the first encoding unit 102 is highly likely to be selected as encoded data which is to be stored in the first memory 105. Also, the total data amount is highly likely to exceed a target data amount several times. However, the original is a natural image, tone reproduction is a factor which determines the image quality and encoded data can be printed at a sufficient image quality.
    3. When a document contains both a natural image and characters, JPEG-LS-encoded data is highly likely to be selected in the character/line image area, and JPEG-encoded data is highly likely to be selected for the natural image. In the character/line image area, JPEG-LS encoding having a high compression ratio is selected at high possibility. This means that an encoded data amount assigned to the natural image area can be increased at a ratio equal to or more than the ratio of the natural image area and character/line image area which occupy one page. In other words, it can be expected that the encoding process is completed while the quantization step value of a photographic image is kept relatively small. Degradation of the image quality in the character/line image area and also the photographic image area can be suppressed.


FIG. 13 shows an example of transition of the first counter 111 (encoded data amount) along the time axis.
In FIG. 13, input of a document image starts at timing T0, and is completed at timing T5. Timing T5 is fixed as far as the size of an input document is fixed. A process at each timing will be explained.
Timing T0:
Timing T0 is an image input start (encoding start) timing. At this time, the quantization matrix table Q0 is set as an initial value for the first encoding unit 102, and the first counter 111 is initialized to “0”. After that, as input and encoding of an image continue, the image data is encoded, and the count value of the first counter 111 gradually increases.
Timing T1:
At timing T1, the encoded data amount of image data reaches (or exceeds) a target encoded data amount. At this time, encoded data of image data in the first memory 105 is discarded, the first counter 111 is cleared to 0, and the quantization matrix table set for the first encoding unit 102 is updated to Q1. The quantization matrix table Q1 is also set for the re-encoding unit 112, and the re-encoding process starts.
Timing T2:
At timing T2, the re-encoding and transfer processes are completed. Upon the completion of re-encoding, re-encoded data is transferred from the second memory 107 to the first memory 105, and the value of the second counter 113 representing the re-encoded data amount is added to the first counter 111. Consequently, the first and second memories 105 and 107 store encoded data equivalent to data obtained such that image data input from the start of one page till timing T2 are encoded on the basis of the quantization matrix table Q1.
Timing T3:
At timing T3, the encoded data amount of image data reaches (or exceeds) a target encoded data amount again. At this time, encoded data of image data in the first memory 105 is discarded, the first counter 111 is cleared to 0, and the quantization matrix table of the first encoding unit 102 is changed to Q2. The quantization matrix table Q2 is also set for the re-encoding unit 112, and the re-encoding process starts.
Timing T4:
At timing T4, the re-encoding and transfer processes are completed. Upon the completion of re-encoding, re-encoded data is transferred from the second memory 107 to the first memory 105, and the value of the second counter 113 representing the re-encoded data amount is added to the first counter 111. As a result, the first and second memories 105 and 107 store encoded data equivalent to data obtained such that image data input from the start of one page till timing T2 are encoded on the basis of the quantization matrix table Q2.
Timing T5:
At timing T5, input of the 1-page document is completed. In this case, the first memory 105 stores encoded data of the 1-page image, and outputs the result to the secondary storage device 7.
To read the second document image, the process is repeated from timing T1.
Depending on an image, the value of the first counter 111 may exceed a target amount immediately before timing T5 at which input of a document image is completed. In this case, the re-encoding and transfer processes are done after timing T5. A condition that encoded data stored in the first memory 105 is output to the secondary storage device 7 is that input of a document image is completed and encoding (re-encoding and transfer) is also completed.
An encoded data amount to be re-encoded by the re-encoding unit 112 tends to increase as the number by which the value of the first counter 111 exceeds a target data value increases. In other words, as the number by which the value exceeds the target value is smaller, the time taken for the encoding process is shorter.
<First Modification of Encoding Unit 6>
FIG. 2 shows a modification of the arrangement in FIG. 1. The arrangement in FIG. 2 is different from that in FIG. 1 in that the storage destination of data re-encoded by the re-encoding unit 112 is changed to the first memory 105. The remaining arrangement is the same as that in FIG. 1.
FIG. 10 shows a state in which the total encoded data amount in the first memory 105 exceeds a target data amount, data in the first memory 105 is discarded, and re-encoding of encoded data (area I′ in FIG. 10) stored in the second memory 107 starts.
As shown in FIG. 10, the first memory 105 is set as the storage destination of re-encoding by the re-encoding unit 112, and re-encoding starts.
FIG. 11 shows the storage state of encoded data in two memories upon the completion of re-encoding. Upon the completion of re-encoding, as shown in FIG. 11, the first memory 105 stores encoded data represented in the area I. Encoded data in the area I corresponds to encoded data obtained when image data input before it is determined that the total data amount has exceeded a target data amount is encoded on the basis of the quantization matrix table Q1.
Since input and encoding of image data are performed even during re-encoding, the areas II and II′ exist, as shown in FIG. 11.
Since a free area 105a is ensured in the first memory 105, encoded data in the area II shown in FIG. 11 is moved to the end position in the area I. Thereafter, the encoding phase resumes, and the storage state in the memory at this time is illustrated in FIG. 12.
The advantage of the arrangement in FIG. 2 over that in FIG. 1 is that data transfer after re-encoding is substantially omitted.
This modification omits only the transfer phase, and is substantially the same as the preceding description in terms of repeating the three phases. Therefore, the contents of the process are almost the same as those in FIGS. 3 and 9, and a description thereof will be omitted. In FIG. 11, data is moved in the first memory 105 in order to eliminate the free area 105a, but internal transfer is not always necessary when a file management table for managing the connection relationship between areas, a packet management table, or the like is employed.
<Second Modification of Encoding Unit 6>
In the first embodiment and first modification, when the encoded data amount in the first memory 105 exceeds a target data amount, encoded data in the second memory 107 is re-encoded by the re-encoding unit 112. In other words, the re-encoding unit 112 does not execute re-encoding while the encoded data amount in the first memory 105 falls within the target data amount.
An example of effectively using this period will be explained as the second modification.
The following description is directed to a process while lossless encoded data from the second encoding unit 103 is stored in the second memory 107 when the encoded data amount in the first memory 105 falls within the target data amount, under the condition that the quantization matrix table set for the first encoding unit 102 is Qi.
Similar to the above embodiment, lossless encoded data from the second encoding unit 103 is stored in the second memory 107. However, the re-encoding unit 112 moves up a process of sequentially reading out stored lossless encoded data, re-encoding it on the basis of the quantization matrix Qi+1 to generate lossy encoded data, and storing the result in the second memory 107.
Thus, it is promised that lossy encoded data exists to a certain degree in the second memory 107 in addition to lossless encoded data when encoded data in the first memory 105 exceeds the target data amount. For the same pixel block position, encoded data in a smaller amount is transferred to the first memory. The process in FIG. 20 is performed for only a pixel block whose lossy encoded data to be compared does not exist.
Upon the completion of transfer from the second memory 107 to the first memory 105, lossy encoded data stored in the second memory is discarded, the quantization matrix Qi+2 is set this time, and re-encoding starts. Consequently, the process associated with re-encoding can be further shortened.
<Third Modification of Encoding Unit 6>
In the first embodiment described above, the first counter is temporarily cleared to 0 when the encoded data amount (value of the first counter 111) exceeds a target value during input of a 1-page image. The first counter 111 holds an accurate total encoded data amount again after re-encoding by the re-encoding unit 112 is completed. That is, the encoded data amount becomes temporarily unknown at an interval between timings T1 and T2 and an interval between timings T3 and T4 in FIG. 13. When input of a document image ends at timing T5, but the total encoded data amount accidentally exceeds the target value immediately before timing T5, no next document image can be input until re-encoding by the re-encoding unit 112 is completed.
The third modification solves the above problem. The arrangement of the encoding unit 6 according to the third modification is shown in FIG. 14.
The arrangement in FIG. 14 is different from that in FIG. 1 in that the encoding unit 6 adopts a third encoding unit 114 serving as a JPEG (lossy) encoding unit, a third code length detection unit 115 which detects the code length of a pixel block that is generated by the third encoding unit 114, a third counter 116, a third memory control unit 117, and a third memory 118. Similar to the first embodiment, the third encoding unit 114 adds a bit representing JPEG encoding (lossy-encoding) at the start of generated encoded data.
In FIG. 1, only one JPEG encoding unit performs lossy (JPEG) encoding. To the contrary, in FIG. 14 according to the third modification, two, first and third image encoding units 102 and 114 are arranged, and these two lossy encoding units parallel-execute an encoding process. The first and third encoding units 102 and 114 are different in a set parameter. More specifically, when a quantization matrix table Qi is set for the first encoding unit 102, a quantization matrix table Qi+1 larger by one step is always set for the third encoding unit 114. At the initial stage at the start of encoding one page, a quantization matrix table set for the first encoding unit 102 is Q0, and that set for the third encoding unit 114 is Q1.
The first, second, and third encoding units 102, 103, and 114 execute an encoding process for the same pixel block at almost the same timing, and generate and output encoded data at almost the same timing. The attribute determination unit 130 detects the number of colors in the same pixel block at almost the same timing.
Furthermore, lossless encoded data output from the second encoding unit 103 is unconditionally stored in the third memory 118 via the third memory control unit 117. Upon the completion of encoding one page, encoded data stored in the first memory 105 is finally obtained encoded data, similar to the first embodiment.
An outline of a process by the encoding sequence control unit 110 in the arrangement of FIG. 14 will be explained.
A basic process for each pixel block in the encoding sequence control unit 110 according to the third modification is as follows.

    1. Letting Qi be a quantization matrix table set for the first encoding unit 102 (Q0 at the initial stage), the encoding sequence control unit 110 always sets for the third encoding unit 114 a quantization matrix table Qi+1 (Q1 at the initial stage) larger by one step.
    2. When the number of colors that is announced from the attribute determination unit 130 is equal to or smaller than a predetermined number at the start of encoding from the start of one page, the encoding sequence control unit 110 outputs a control signal so as to select lossless encoded data output from the second encoding unit 103 and store it in the first memory 105. When the number of colors exceeds the predetermined number, the encoding sequence control unit 110 outputs a control signal to the first memory control unit so as to store in the first memory 105 a smaller one of lossy encoded data output from the first encoding unit 102 and lossless encoded data output from the second encoding unit 103. The encoding sequence control unit 110 accumulates and adds, to the first counter 111, the code length of encoded data to be stored in the first memory 105. That is, the first counter 111 stores information representing an encoded data amount in the first memory 105, similar to the first embodiment.
    3. The encoding sequence control unit 110 outputs a control signal so as to store in the second memory 107 a smaller one of lossy encoded data output from the third encoding unit 114 and lossless encoded data output from the second encoding unit 103. The encoding sequence control unit 110 accumulates and adds a shorter one of the code lengths of the two encoded data to the third counter 116.


An outline of a process by the encoding sequence control unit 110 during an encoding process for one page will be explained.
The encoding sequence control unit 110 determines whether the value (encoded data amount in the first memory 105) of the first counter 111 has exceeded a target data amount. If the encoding sequence control unit 110 determines that the value does not exceed the target data amount and an encoding process for one page is completed, the encoding sequence control unit 110 outputs, to the secondary storage device 7, encoded data stored in the first memory 105 as the encoding result of the encoding unit 6 according to the third modification.
If the encoding sequence control unit 110 determines that the value of the first counter 111 has exceeded the target data amount, the encoding sequence control unit 110 executes the following steps.

    Step 1: The encoding sequence control unit 110 requests the first memory control unit 104 to discard encoded data of image data in the first memory 105. The encoding sequence control unit 110 relaxes the condition on color count information from the attribute determination unit 130 (further decreases the threshold).
    Step 2: The encoding sequence control unit 110 transfers encoded data (data containing both lossy and lossless encoded data on the basis of the quantization matrix table Qi+1) stored in the second memory 107 to the first memory 105. Along with this, the value of the first counter 111 is updated to the value of the third counter 116 (the value of the third counter 116 is overwritten in the first counter 111).
    Step 3: Upon the completion of transfer from the second memory 107 to the first memory 105, the encoding sequence control unit 110 outputs a control signal to the second memory 107 so as to discard data in the second memory 107.
    Step 4: The encoding sequence control unit 110 updates the quantization matrix table for the first encoding unit 102 to Qi+1, that for the third encoding unit 114 to Qi+2, and continues encoding.
    Step 5: The encoding sequence control unit 110 sets the quantization matrix table Qi+2 (identical to the updated quantization matrix table for the third encoding unit 114) for the re-encoding unit 112, and causes the re-encoding unit 112 to re-encode the lossless encoded data stored in the third memory 118. The re-encoding unit 112 has the same arrangement as that in the first embodiment, and a description thereof will be omitted. Re-encoded data obtained by the re-encoding process is stored again in the third memory. At this time, the encoded data amount generated by the re-encoding process is represented by the second counter 113.
    Step 6: Upon the completion of re-encoding in step 5, the encoding sequence control unit 110 transfers the re-encoded data obtained by the re-encoding process to the second memory, and adds the value of the second counter 113 to the third counter 116.


Of steps 1 to 6, steps 1 to 5 can be performed at a speed high enough to input image data from the input unit 101. For this reason, a period during which the encoded data amount is unknown, like an interval between timings T1 and T2 or an interval between timings T3 and T4 in FIG. 13, can be shortened. In particular, the update process for the first counter 111 in step 2 may be performed before the completion of the transfer process. In this case, the period during which the encoded data amount is unknown can be substantially ignored.
If the encoded data amount given by the first counter 111 exceeds the target value immediately before timing T5 in FIG. 13, the process starts from step 1. Upon the completion of step 2, the target encoded data has been stored in the first memory 105. After that, the data in the first memory 105 can be written in the secondary storage device 7, and loading and encoding processes for the next page can start without performing the process from step 3.
An outline of operation in the arrangement of FIG. 14 has been described. When two lossy encoding units and one lossless encoding unit are juxtaposed, like the third modification, 1-page image data is encoded on the basis of the flowchart shown in FIG. 15.
Note that most of the process in FIG. 15 is similar to that in FIG. 9, the process will be described in three phases, and points different from those in FIG. 9 will be mainly described below.
The largest difference between the flow of FIG. 9 and that of the third modification is that the transfer process from the second memory 107 to the first memory 105 in step S317 is moved between step S307 and step S309. In addition to this, a process (step S320) of discarding data in the second memory 107 is added after the end of the transfer process, and a transfer process (step S321) from the third memory to the second memory is added upon the completion of a re-encoding process.
In initial setting of encoding parameters in step S8301, an initial quantization matrix table Q0 to be set for the first image encoding unit 102 is determined, and a quantization matrix table Q1 larger by one step is set for the third image encoding unit 114.
In the encoding phase, steps S801, S303, and S305 are repetitively executed. FIG. 16 shows the storage state of encoded data in the first to third memories in the encoding phase. In FIG. 16, the switch 40 is identical to that in the first embodiment. A switch 41 is implemented by the second memory control unit 106 and encoding sequence control unit 110. That is, the switch 40 selects, for each pixel block, encoded data of a shorter code length among encoded data output from the first and second encoding units 102 and 103, and the selected encoded data is stored in the first memory 105. The switch 41 selects, for each pixel block, encoded data of a shorter code length among encoded data output from the third and second encoding units 114 and 103, and the selected encoded data is stored in the second memory 107. The third memory 118 unconditionally stores encoded data from the second encoding unit 103.
A case wherein the encoded data amount (area I shown in FIG. 16) in the first memory 105 exceeds a target value will be examined. This is a case wherein it is determined in step S305 that the encoded data amount has exceeded the target data amount.
At this time, encoded data held in the first memory 105 is discarded (step S307). Encoded data (area I′) having a high compression ratio that is held in the second memory 107 is transferred to the first memory 105, and the value of the third counter 116 is written in the first counter 111 (step S317). After transfer, the encoded data stored in the second memory 107 is discarded, and the value of the third counter is cleared to 0 (step S320). A new quantization matrix table Q1 is set for the first-encoding unit 102, and a new quantization matrix table Q2 is set for the second encoding unit 103 (step S309).
FIG. 17 shows the storage state of each memory immediately after step S309. In step S311, the processes of the first, third, and second encoding units 102, 114, and 103 continue. In other words, the first encoding unit 102 continues encoding on the basis of the newly set quantization matrix table Q1. Encoded data of image data input after it is determined that the encoded data amount has exceeded the target data amount is stored in the second memory 107, but no preceding encoded data exists.
The re-encoding unit 112 starts re-encoding encoded data (lossless encoded data) in the area I′′ in FIG. 16 that is stored in the third memory 118. The arrangement of the re-encoding unit 112 is the same as that described in the first embodiment except that the set quantization matrix table is Q2 which is also set for the third encoding unit 114. Re-encoded data obtained by the re-encoding process is stored again in the third memory 118.
FIG. 18 shows the storage state of each memory immediately after it is determined that the re-encoding process has been completed. As shown in FIG. 18, the third memory 118 stores re-encoded data (area I′ in FIG. 18) corresponding to the area I′′ in FIG. 18. The re-encoding process requires a slightly long time, and encoded data are newly stored as represented by the areas II, II′, and II′′ in FIG. 18.
Upon the completion of re-encoding, encoded data in the area I′ that is stored in the third memory 118 is transferred to the second memory 107. The value of the second counter 113 representing the encoded data amount of re-encoding is added to the third counter 116 (step S321). After that, the process returns to the encoding sequence from step S801. FIG. 19 shows a state in which the process returns to the encoding sequence and encoding progresses to a certain degree (areas III, III′, and III′′ shown in FIG. 19 are added). In FIG. 19, a free area exists between the areas I′ and II′ in the second memory 107, but may be eliminated by transfer within the memory 107. However, no problem occurs because the second memory 107 is auxiliary, and if the encoded data amount exceeds the target data amount again, encoded data in the areas I′, II′, and III′ in FIG. 19 are transferred to the first memory 105 in the order named.
The third modification has been described. According to the third modification, when the encoded data amount in the first memory 105 exceeds a target data amount, encoded data which has a compression ratio higher by one step and is stored in the second memory 107 is kept used as data before the encoded data amount exceeds the target data amount. The period during which the value of the first counter 111 becomes unknown can be substantially ignored or shortened. The re-encoding process suffices to be performed before the encoded data amount exceeds the target data amount again, and thus the process of the re-encoding unit 112 need not be as fast as in the first embodiment. Even if the value of the first counter 111 exceeds the target data amount immediately before timing T5 in FIG. 9, a subsequent process, i.e., re-encoding process can be omitted as far as transfer from the second memory 107 to the first memory 105 is completed. That is the process can quickly proceed to encoding of the next page (this corresponds to “YES” in step S1201 of FIG. 15).
The re-encoding result of the re-encoding unit 112 is stored in the third memory 118 in the third modification, but may be stored in the second memory 107, similar to the modifications to the first embodiment.
Second Embodiment
In the first embodiment and the first to third modifications, when the number of colors in a pixel block serving as an encoding unit is equal to or smaller than a predetermined number, priority is given to lossless encoded data before the value of the first counter 111 exceeds a target data amount after the start of encoding one page.
This is convenient for lossless encoding JPEG-LS, but the present invention is not limited to only the number of colors.
In the second embodiment, lossless encoded data may be selected when the ratio at which white pixels occupy a pixel block (in the second embodiment, an area of an 8×8 pixel size) is equal to or higher than a predetermined value. Although the ratio is generally given by %, calculation is simplified by counting the number of white pixels because the total number of pixels is kept at 64.
Note that a white pixel is determined on the basis of R≈G≈B≈255 (each component is expressed by 8 bits).
The arrangement in the second embodiment can adopt those in the first embodiment and the first to third modifications, and a description thereof will be omitted. However, an attribute determination unit 130 detects the number of white pixels in a pixel block.
FIG. 24 is a flowchart showing a process of selecting encoded data to be stored in a first memory 105 by an encoding sequence control unit 110 according to the second embodiment.
In step S2401, it is determined whether the value of a counter 111 has exceeded a target data amount even once during encoding of one page after the start of encoding the page. At the start of encoding one page, the result of determination is “NO”, and the flow advances to step S2402. In step S2402, it is determined whether the number of white pixels in a pixel block of interest (output from the attribute determination unit 130) is equal to or larger than a predetermined number (n). If it is determined that the number of white pixels is equal to or larger than the predetermined number, encoded data from a second encoding unit 103 is selected as encoded data to be stored in the first memory 105. At this time, code length information from a second code length detection unit 109 is accumulated and added to the first counter 111.
If the value of the first counter 111 exceeds a target data amount, the white pixel threshold (n white pixels) is decreased to (n−1 white pixels).
If YES in step S2401 or NO in step S2402, the flow advances to step S2404 to select encoded data of a shorter code length among two encoded data as encoded data to be stored in the first memory 105. At this time, code length information of the selected encoded data is accumulated and added to the first counter 111.
As described above, the second embodiment can also successfully obtain the same operation effects as those of the first embodiment.
Third Embodiment
The third embodiment will exemplify a case wherein an attribute determination unit 130 detects the number of white pixels in a pixel block (the ratio at which white pixels occupy a pixel block) and determines the character/line image attribute of the pixel block. The remaining arrangement can directly employ those in the first embodiment and the first to third modifications, and a description thereof will be omitted.
In general, a character/line image is characterized by a steep change in edge brightness (density). In determination of a character/line image, when a pixel of interest and an adjacent pixel have a predetermined brightness difference or more, the pixel of interest is determined as (the edge of) a character/line image. When there are a predetermined number of pixels which are determined to have a predetermined brightness difference or more, a pixel block of interest is determined as a character/line image block.
Determination of a character/line image block becomes slightly complicated because difference operation between adjacent pixel values, a comparison process with a threshold, and a counting process are added. However, when the attribute determination unit 130 in the third embodiment is implemented by hardware, the process is much simpler than those of the first and second encoding units, and does not influence other processes. However, it should be noted that when an encoding unit 6 is implemented by software, the process may influence parallel operation of the CPU.
The process in the third embodiment will be explained with reference to the flowchart of FIG. 25.
In step S2501, it is determined whether the value of a counter 111 has exceeded a target data amount during encoding of one page after the start of encoding the page. At the start of encoding one page, the result of determination is “NO”, and the flow advances to step S2502. In step S2502, it is determined whether the number of white pixels in a pixel block of interest (output from the attribute determination unit 130) is equal to or larger than a predetermined number (n). If the number of white pixels is equal to or larger than the predetermined number, the flow advances to step S2503 to determine whether the pixel block of interest is a character/line image area. If it is determined that the pixel block of interest is a character/line image area, the flow advances to step S2504 to select encoded data from a second encoding unit 103 as encoded data to be stored in a first memory 105. At this time, code length information from a second code length detection unit 109 is accumulated and added to the first counter 111.
If YES in step S2501, NO in step S2502, or NO in step S2503, the flow advances to step S2505 to select encoded data of a shorter code length among two encoded data as encoded data to be stored in the first memory 105. At this time, code length information of the selected encoded data is accumulated and added to the first counter 111.
As described above, the third embodiment can also successfully obtain the same operation effects as those of the first embodiment.
Fourth Embodiment
In the first embodiment (including its modifications) to the third embodiment, encoding starts from the start of a page, and encoded data to be stored in the first memory 105 is selected in consideration of even information from the attribute determination unit 130.
To encode an image, lossless encoding is desirably employed beyond question. On the other hand, to satisfy a condition that the encoded data amount is suppressed within a target data amount and a condition that encoding is done without interrupting input of a 1-page image or inputting a 1-page image again, both lossless encoding and lossy encoding must be used.
In general, a document to be copied by a copying machine is often formed from only a text, and it is desirable to select lossless encoded data as much as possible. In the first to third embodiments, JPEG and JPEG-LS are respectively employed as lossy encoding and lossless encoding, and encoded data of a shorter code length is selected. For a general document, lossless encoded data is basically selected at a high rate, which, however, is not guaranteed.
From this, the fourth embodiment will describe an example in which lossless encoded data is highly likely to be selected at the initial stage during an encoding process for one page.
FIG. 26 is a block diagram showing an encoding unit 6 according to the fourth embodiment. The arrangement in FIG. 26 is based on that in FIG. 1, but as is apparent from the following description, may also be based on that in FIG. 2 or 14.
The difference between FIGS. 26 and 1 is that the attribute determination unit 130 is omitted from the arrangement in FIG. 26, but a weighting coefficient generation unit 131 which generates a weighting coefficient α based on a code length detected by a second code length detection unit 109 is arranged in an encoding sequence control unit 110. The remaining arrangement is the same as that in the first embodiment, and the same reference numerals denote the same parts. Hence, processes by the building components are also the same as those described in the first embodiment.
The weighting coefficients α (α0, α1, α2, . . . ) generated by the weighting coefficient generation unit 131 in the fourth embodiment draw a curve as shown in FIG. 27. In FIG. 27, α0 is a weighting coefficient selected in the initial state. The weighting coefficient becomes larger as the lossless code length of a pixel block of interest-becomes smaller, and comes close to “1” as the lossless code length becomes larger.
Let L1 be a code length detected by a first code length detection unit 108, and L2 be a code length detected by the second code length detection unit 109.
According to the fourth embodiment, when condition 1:

L1×α≧L2

is satisfied, the encoding sequence control unit 110 stores lossless encoded data from a second encoding unit 103 in a first memory 105. When condition 1 is not satisfied, the encoding sequence control unit 110 stores lossy encoded data from a first encoding unit 102 in the first memory 105.

When the value of a first counter 111 exceeds a target encoded data amount, α1 smaller than the weighting coefficient α (α0 in the initial state) is used as a new weighting coefficient α.
Also in selecting encoded data for re-encoding by a re-encoding unit 112, the process is performed in accordance with the weighting coefficient α.
Assume that the encoded data amount exceeds a target encoded data amount during encoding using the weighting coefficient α (=α0). In this case, the re-encoding unit 112 compares the product of the code length of lossy encoded data obtained by re-encoding and α1 (equal to an updated parameter for the first encoding unit 102) with the code length of lossless encoded data before re-encoding, and stores encoded data of a shorter code length in a second memory 107.
By setting condition 1, as the lossless encoded data amount decreases, the probability at which lossless encoded data is selected can be increased. When an encoding process for one page is completed before a generated encoded data amount (the value of the first counter 111) exceeds a target encoded data amount, the rate at which lossless encoded data is selected becomes higher than in a case wherein a simple comparison process for L1 and L2 is executed. Accordingly, encoded data at high image quality can be generated.
As an encoded data selection process in the encoding sequence control unit 110, a process shown in FIG. 28 suffices to be executed.
In step S2802, the weighting coefficient α is calculated on the basis of a code length detected by the second code length detection unit 109. In step S2803, it is determined whether the condition: “L1×α≧L2” (α=α0 at the start of encoding one page) is satisfied. If it is determined that the condition is satisfied, the flow advances to step S2804 to generate a control signal so as to select encoded data from the second encoding unit 103 as encoded data to be stored in the first memory 105.
As described above, according to the fourth embodiment, encoded data of a target data amount can be generated by one image input while both lossless encoding and lossy encoding are used. Since the probability at which lossless encoded data is selected is increased, a decoded image can be maintained at high image quality.
The embodiments (including the first to third modifications to the first embodiment) according to the present invention have been described. In the embodiments, the first, second, and third memories 105, 107, and 118 are described as physically different memories. It is one of features of the present invention to independently arrange these memories. However, the present invention incorporates even a case wherein these memories are not physically different memories. Assume that two (or three) areas corresponding to the first and second (and third) memories are ensured in physically one memory when the transfer speed of a memory is high enough. In this case, it is obvious from the above description with the first and second memories being replaced with the first and second memory areas that the present invention can be realized by one memory.
If each embodiment described above is implemented by one memory, some steps in the data transfer process described with reference to the transfer phase become unnecessary. Details of each of such cases can be easily expected, and hence a description thereof will be omitted. When the two areas are strictly separated from each other and used, the data transfer process is required as in the case wherein physically two memories are used. If identical data are shared between the two areas, the data transfer process can be omitted, and the storage capacity can also be reduced.
For example, a case wherein encoded data held in the second memory area is transferred to the first memory area will be examined. In this case, two kinds of information on the start address at which the encoded data is stored and the data size of the encoded data are transferred from the second memory control unit to the first memory control unit, thereby obtaining the same effects as transferring the encoded data.
If the encoded data is stored in a file or packet form, the amount of information to be transferred between the memory control units slightly increases, and management table information associated with the encoded data must be transferred.
In the above embodiments, encoding is targeted to an 8×8 pixel block size, but this size does not limit the present invention. In short, two encoded data amounts generated for the same image area suffice to be compared using two (or more) different encoding techniques. For example, JPEG encoding can be done for each N×M pixel block, and JPEG-LS can be done for each 2N×2M pixel block. In this case, four JPEG-encoded data and one JPEG-LS encoded data may be compared.
In the above embodiments, lossy encoding “JPEG” and lossless encoding “JPEG-LS” are adopted as two encoding techniques. These two encoding techniques are different in whether the technique is lossless or lossy. At the same time, JPEG is suitable for natural images, JPEG-LS is suitable for character/line images and computer graphics, and these techniques are different in encoding efficiency. The use of two encoding techniques which have different properties in terms of whether the technique is lossless encoding or lossy encoding and is suited to character/line images or natural images acts advantageously to the present invention.
In the above embodiments, the present invention is applied to the copying machine shown in FIG. 22. It is apparent that the present invention can also be applied to a case wherein an image input apparatus such as an image scanner is connected to a general-purpose information processing apparatus such as a personal computer to encoded data. In this case, a function of ensuring an area corresponding to the first, second, or third memory in the RAM, HDD, or the like, a program associated with the process shown in FIG. 3 (or FIG. 9) or FIG. 15, and the processes in FIGS. 23 to 25 and 27 suffice to be executed. The computer program apparently falls within the scope of the present invention. In general, the computer program can be executed by setting a computer-readable storage medium such as a CD-ROM in a computer, and copying or installing the computer program into the system. As a matter of course, the computer-readable storage medium also falls within the scope of the present invention.
As has been described above, according to the present invention, while both lossless encoding and lossy encoding are employed, encoded data of an entire image can be suppressed within a predetermined data amount by one image input. In an application of lossy encoding to part or all of an image, a common encoding parameter can be used for the image. Although the encoded data amount slightly increases, encoded data generated by a lossless encoding process is preferentially used for an area of an attribute which is highly likely to be a character/line image area. Thus, encoded data at high image quality can be generated.
Also, while both lossless encoding and lossy encoding are employed, encoded data of an entire image can be suppressed within a target data amount by one image input. In an application of lossy encoding to part or all of an image, a common encoding parameter can be used for the image. By positively increasing the probability at which lossless encoded data is contained in final encoded data, encoded data at high image quality can be generated.
As many apparently widely different embodiments of the present invention can be made without departing from the spirit and scope thereof, it is to be understood that the invention is not limited to the specific embodiments thereof except as defined in the claims.

## Claims

1. An image encoding apparatus, which receives image data and encodes the image data, comprising:
first encoding means for lossy encoding input image data for each predetermined pixel block in accordance with a first parameter to generate lossy encoded data;
second encoding means for lossless encoding the input image data for each predetermined pixel block to generate lossless encoded data;
a first memory, which stores one of the encoded data from said first encoding means and said second encoding means;
a second memory which stores the encoded data generated by said second encoding means;
monitoring means for determining whether an encoded data amount stored in said first memory has exceeded a predetermined target data amount;
attribute determination means for detecting an attribute of each predetermined pixel block in the input image data and determining whether detected attribute information satisfies a predetermined condition;
first selection means for, when said attribute determination means determines that the detected attribute information satisfies the predetermined condition, selecting the lossless encoded data from said second encoding means in order to store the lossless encoded data in said first memory;
second selection means for, when said attribute determination means determines that the detected attribute information does not satisfy the predetermined condition, selecting encoded data of a shorter code length among the encoded data from said first encoding means and said second encoding means in order to store the selected encoded data in said first memory;
re-encoding means for decoding the lossless encoded data in said second memory, re-encoding the decoded data in accordance with a second parameter to generate lossy encoded data, and storing, in said first memory, encoded data of a shorter code length among the lossy encoded data obtained after re-encoding and the lossless encoded data before re-encoding;
determination condition change means for, when said monitoring means determines that the encoded data amount has exceeded the predetermined target data amount, changing a determination condition of said attribute determination means; and
parameter update means for, when said monitoring means determines that the encoded data amount has exceeded the predetermined target data amount, (a) discarding the encoded data in said first memory, (b) updating the first parameter set for said first encoding means to a parameter having a high compression ratio, and causing said first encoding means to continue encoding of the input image data, and (c) setting, as the second parameter, a same parameter as the updated first parameter for said re-encoding means, and causing said re-encoding means to re-encode lossless encoded data obtained before the encoded data amount exceeds the predetermined target data amount.

2. The apparatus according to claim 1, wherein JPEG is used for encoding by said first encoding means, and JPEG is used for encoding by said second encoding means.

3. The apparatus according to claim 1, wherein said attribute determination means determines whether a number of colors in a predetermined pixel block currently undergoing processing is not more than a predetermined number.

4. The apparatus according to claim 1, wherein said attribute determination means determines whether a ratio at which a predetermined color occupies a predetermined pixel block currently undergoing processing is not less than a predetermined value.

5. The apparatus according to claim 1, wherein said attribute determination means determines whether a ratio at which a predetermined color occupies a predetermined pixel block currently undergoing processing is not less than a predetermined value, and whether the predetermined pixel block is a character/line image area.

6. A method of controlling an image encoding computer apparatus that includes a first memory and a second memory, and that receives image data and encodes the image data, the method comprising:
a first encoding step of, in the image encoding computer apparatus, lossy encoding input image data for each predetermined pixel block in accordance with a first parameter to generate lossy encoded data;
a second encoding step of, in the image encoding computer apparatus, lossless encoding the input image data for each predetermined pixel block to generate lossless encoded data;
a first storing step of storing one of the encoded data from the first encoding step and the second encoding step in the first memory;
a second storing step of storing the encoded data from the second encoding step in the second memory;
a monitoring step of, in the image encoding computer apparatus, determining whether an encoded data amount stored in the first memory has exceeded a predetermined target data amount;
an attribute determination step of, in the image encoding computer apparatus, detecting an attribute of each predetermined pixel block in the input image data and determining whether detected attribute information satisfies a predetermined condition;
a first selection step of, in the image encoding computer apparatus, when the detected attribute information is determined in the attribute determination step to satisfy the predetermined condition, selecting the lossless encoded data from the second encoding step in order to store the lossless encoded data in the first memory;
a second selection step of, in the image encoding computer apparatus, when the detected attribute information is determined in the attribute determination step not to satisfy the predetermined condition, selecting encoded data of a shorter code length among the encoded data from the first encoding step and the second encoding step in order to store the selected encoded data in the first memory;
a re-encoding step of, in the image encoding computer apparatus, decoding the lossless encoded data in the second memory, re-encoding the decoded data in accordance with a second parameter to generate lossy encoded data, and storing, in the first memory, encoded data of a shorter code length among the lossy encoded data obtained after re-encoding and the lossless encoded data before re-encoding;
a determination condition change step of, in the image encoding computer apparatus, when the encoded data amount is determined in the monitoring step to have exceeded the predetermined target data amount, changing a determination condition of the attribute determination step; and
a parameter update step of, in the image encoding computer apparatus, when the encoded data amount is determined in the monitoring step to have exceeded the predetermined target data amount, (a) discarding the encoded data in the first memory, (b) updating the first parameter set for the first encoding step to a parameter having a high compression ratio to continue encoding of the input image data, and (c) setting, as the second parameter, the same parameter as the updated first parameter for the re-encoding step to re-encode lossless encoded data obtained before the encoded data amount exceeds the predetermined target data amount.

7. A computer-readable storage medium storing a computer program that, when executed by a computer, causes the computer to perform a method of controlling an image encoding apparatus, wherein the method comprises:
a first encoding step of lossy encoding input image data for each predetermined pixel block in accordance with a first parameter to generate lossy encoded data;
a second encoding step of lossless encoding the input image data for each predetermined pixel block to generate lossless encoded data;
a first storing step of storing one of the encoded data from the first encoding step and the second encoding step in a first memory;
a second storing step of storing the encoded data from the second encoding step in a second memory;
a monitoring step of determining whether an encoded data amount stored in the first memory has exceeded a predetermined target data amount;
an attribute determination step of detecting an attribute of each predetermined pixel block in the input image data and determining whether detected attribute information satisfies a predetermined condition;
a first selection step of, when the detected attribute information is determined in the attribute determination step to satisfy the predetermined condition, selecting the lossless encoded data from the second encoding step in order to store the lossless encoded data in the first memory;
a second selection step of, when the detected attribute information is determined in the attribute determination step not to satisfy the predetermined condition, selecting encoded data of a shorter code length among the encoded data from the first encoding step and the second encoding step in order to store the selected encoded data in the first memory;
a re-encoding step of decoding the lossless encoded data in the second memory, re-encoding the decoded data in accordance with a second parameter to generate lossy encoded data, and storing, in the first memory, encoded data of a shorter code length among the lossy encoded data obtained after re-encoding and the lossless encoded data before re-encoding;
a determination condition change step of, when the encoded data amount is determined in the monitoring step to have exceeded the predetermined target data amount, changing a determination condition of the attribute determination step; and
a parameter update step of, when the encoded data amount is determined in the monitoring step to have exceeded the predetermined target data amount, (a) discarding the encoded data in the first memory, (b) updating the first parameter set for the first encoding step to a parameter having a high compression ratio to continue encoding of the input image data, and (c) setting, as the second parameter, the same parameter as the updated first parameter for the re-encoding step to re-encode lossless encoded data obtained before the encoded data amount exceeds the predetermined target data amount.