1. Field of Invention
The invention relates to an image processing method and, in particular, to a method of rescaling images.
2. Related Art
Bitmap images avoid the drawbacks of vector images. They can be used to generate pictures rich in colors that reproduce scenes in Nature. They can also be readily exchanged among different software programs. However, the bitmap images cannot be used to produce real 3D images. Moreover, the resealing and rotation of a bitmap image often result in distortion. In general, the sizes of such images are larger, thus having higher demands for memory and hard drive space. The principle of bitmap images is to have a set of data of each bitmap pixel. As the resoluation and number of colors increase, the disk space required by the image also becomes larger. Since an image becomes blurred and distorted during the process of magnification, a pixel in the source image will become a block in the destination image.
JPEG, GIF, and PNG documents are all compressed in order to reduce the sizes. However, compression only has limited effects. The bitmap images are still much larger than vector ones. In fact, when expanding the diameter of a bitmap image, the number of pixels becomes four times more.
A conventional method for magnifying bitmap images is to allocate a block or continuous memory from the system according to the size of the destination image. The block of continuous memory is used to store restored bitmap image information. Each pixel in the image is resized in proportion. After the smooth halftone process, the bitmap image information is generated and stored in the memory. This method is slow and occupies a large amount of system memory. Sometimes, one still needs to compress the data in order to save the memory. If the system has a lot of memory fragments or does not have sufficiently large memory, the method cannot be processed because the required large block of memory cannot be allocated.
In view of the foregoing, the invention provides a method of rescaling images to reduce the system memory usage at the same time of increasing the image processing speed.
To achieve the above objective, the invention provides a method of resealing images. The method first determines the rescaling rate from a source image to a destination image. Coordinates of pixels in the destination image are determined from the source image according to the rescaling rate. The source image is then scanned. Adjacent pixels with the same pixel value are combined into a pixel block. The intermediate format information of the pixel block is determined according to the coordinate of the pixel block in the destination image. Afterwards, the pixels are used to form the corresponding halftone bitmap image.
The disclosed method uses the technology of pixel combination to increase the image processing speed. It further utilizes a storage technology to reduce the use of system memory, avoiding the requirement of large continuous memory. Therefore, when there are memory fragments in the system, the method can still process large images. The method can perform similar processes for different color spaces, generating the bitmap information of all color planes.
The invention will become more fully understood from the detailed description given hereinbelow illustration only, and thus are not limitative of the present invention, and wherein:
The specification discloses an image rescaling method. As shown in
The color spaces of an image to be processed can be RGB, CMYK, or Gray. The disclosed method can process different color planes in a similar way, generating the bitmap information of each color plane.
With reference to
ΔX=xScale=DesWidth/SrcWidth
ΔY=yScale=DesHeight/SrcHeight
from which we obtain the overall rescaling rate ScaleRate=xScale*yScale (step 240).
The method then compares the overall rescaling rate and a magnification threshold (step 250). If the former is greater than the latter, the method selects a symbolic command image processing method (step 260); otherwise, a bitmap rendering image processing method is used (step 270).
In the following, we use an 8×8 gray-level planar image as an example to explain the invention. First, the method sets the magnification threshold. In the current embodiment, the magnification threshold is set to be 96. (The user can set the magnification threshold according to the size of the system memory.) The gray-level values of the 8×8 gray-level planar image is:
First, the overall magnification rate of the image is computed. The original 8×8 gray-level image is rescaled in the X and Y directions by the rates of 12 and 10. Therefore, the overall rescaling rate is 12*10=120. Comparing the overall magnification rate 120 and the magnification threshold 96, we see that the former is greater than the latter. Therefore, the symbolic command image processing method is used. The pixel block intermediate format information of the method is shown in
After deciding the image processing method, the image is processed accordingly.
Suppose the value of the first pixel is 0×23, the X and Y coordinates of the upper left corner of the first pixel are (X0,Y0), and those of the lower right corner are (X0+ΔX, Y0+ΔY). The value of the second pixel is 0×15, different from the previous one. Therefore, the first symbolic command is:
The X and Y coordinates of the upper left corner of the second pixel are (X0+ΔX,Y0), those of the lower right corner are (X0+ΔX+ΔX, Y0+ΔY)=(X0+2ΔX, Y0+ΔY). The scanned value of the third pixel is 0×15, same as the previous one. In this case, the X and Y coordinates of the upper left corner of the third pixel are (X0+ΔX+ΔX, Y0)=(XO0+2ΔX, Y0), and those of the lower right corner are (X0+ΔX+ΔX+ΔX, Y0+ΔY) =(X0+3ΔX, Y0+ΔY). The second and third pixels are thus combined into a “big pixel”. The scanned value of the fourth pixel is 0×60, different from its previous one. Therefore, the second symbolic command is
The X and Y coordinates of the upper left corner of the fourth pixel are (X0+3ΔX,Y0) and those of the lower right corner are (X0+4ΔX, Y0+ΔY). The scanned value of the fifth pixel is 0×17, different from its previous one. The third symbolic command is then
The X and Y coordinates of the upper left corner of the fifth pixel are (X0+4ΔX,Y0) and those of the lower right corner are (X0+5ΔX, Y0+ΔY). The scanned value of the fifth pixel is 0×23, different from its previous one. The fourth symbolic command is then
The X and Y coordinates of the upper left corner of the sixth pixel are (X0+5ΔX,Y0) and those of the lower right corner are (X0+6ΔX, Y0+ΔY). The scanned value of the seventh pixel is 0×23, different from its previous one. The X and Y coordinates of the upper left corner of the seventh pixel are (X0+6ΔX,Y0) and those of the lower right corner are (X0+7ΔX, Y0+ΔY). The scanned value of the eighth pixel is 0×72, different from its previous one. The fifth symbolic command is then
The X and Y coordinates of the upper left corner of the eighth pixel are (X0+7ΔX,Y0) and those of the lower right corner are (X0+8ΔX, Y0+ΔY). Since it is the last pixel of the row, we obtain the sixth symbolic command as
After scanning the pixels in the second row, we obtain the corresponding six symbolic commands as
Scanning the pixels in the 3rd, 4th, 5th, 6th, 7th, and 8th row of the image, there are totally 52 symbolic commands, occupying (52*96)/8=624 bytes of memory. This method saves 336 bytes (960−624) than directly generating the bitmap image.
When the system is required to generate a black-and-white bitmap image, it obtains the symbolic command information of each row of pixels in the image (step 450). For different pixels, halftone rendering is performed according to the intermediate format information (step 460). The generated bitmap image is directly stored in the video buffer of the system (step 470) in order to speed up the image processing and to effectively use the system memory.
With reference to
ΔX and ΔY are determined according to the rescaling rate of the image. They are used to determine the coordinates of a pixel in the destination image according to its original coordinates in the source image (step 520). All pixels in the image are scanned (step 530). When the values of adjacent pixels are the same, they are combined into a pixel block (step 540). The scan process is the same as the symbolic command method to determine the intermediate format information of the pixel blocks (step 550). Halftone rendering is processed according to the intermediate format information (step 560) to produce the destination bitmap. The generated bitmap image is stored in the correspondingly allocated memory spaces (step 570).
The only difference from the previous case is the processing means done to the scanned result. In one case, the invention generates the symbolic command of the image; whereas in the other case, the invention further performs halftone rendering to generate the destination bitmap image and to store it in the allocated memory spaces.
For the pixels in the first row, the bitmap rendering method is as follows:
For the region of (X0, Y0) to (X0+ΔX, Y0+ΔY), the halftone rendering of the pixel value of 0×23 is performed to generate a bitmap image that is to be stored in the corresponding memory space.
Combining the second and third pixels, the region of (X0+ΔX, Y0) to (X0+3ΔX, Y0+ΔY) is halftone rendered to have a pixel value of 0×15. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+3ΔX, Y0) to (X0+4ΔX, Y0+ΔY) is halftone rendered to have a pixel value of 0×60. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+4ΔX, Y0) to (X0+5ΔX, Y0+ΔY) is halftone rendered to have a pixel value of 0×17. The bitmap image is generated and stored in the corresponding memory space.
Combining the sixth and seventh pixels, the region of (X0+5ΔX, Y0) to (X0+7ΔX, Y0+ΔY) is halftone rendered to have a pixel value of 0×23. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+7ΔX, Y0) to (X0+8ΔX, Y0+ΔY) is halftone rendered to have a pixel value of 0×72. The bitmap image is generated and stored in the corresponding memory space.
For the pixels in the second row, the bitmap rendering method is as follows:
The region of (X0, Y0+ΔY) to (X0+ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×11. The bitmap image is generated and stored in the corresponding memory space.
Combining the second, third, and fourth pixels, the region of (X0+ΔX, Y0+ΔY) to (X0+4ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×27. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+4ΔX, Y0+ΔY) to (X0+5ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×43. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+5ΔX, Y0+ΔY) to (X0+6ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×56. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+6ΔX, Y0+ΔY) to (X0+7ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×21. The bitmap image is generated and stored in the corresponding memory space.
The region of (X0+7ΔX, Y0+ΔY) to (X0+8ΔX, Y0+2ΔY) is halftone rendered to have a pixel value of 0×18. The bitmap image is generated and stored in the corresponding memory space.
The same method is used to scan the 3rd, 4th, 5th, 6th, 7th, and 8th rows of pixels in the image. The same halftone rendering is processed to generate the bitmap images and to store them in the corresponding memory spaces.
Certain variations would be apparent to those skilled in the art, which variations are considered within the spirit and scope of the claimed invention.