1. Field of the Invention
The present invention relates to an image processing apparatus and an image processing method. More particularly, the invention relates to an apparatus and a method for adjusting the contrast of an input image.
2. Description of the Prior Art
In general, the contrast of an image means the lightness ratio between the bright region and the dark-region of the image. The enhancement of the contrast can lighten the brighter region a little and darken the darker region a little. The enhancement of the contrast sometimes may make the image lose a little bit information, but for most people, a suitable increase of the contrast can be favored.
For a display or a television, the increase of the contrast can be achieved by adjusting the Gamma coefficient, which changes the relation between gray level signals and lightness. Alternatively, it can be achieved by adjusting the gain of the lightness component of the image by the chips of the display (e.g. an image decoder or an image converter). However, a common adjustment for contrast is usually not suitable for all kinds of images.
Please refer to
The realization for the lightness input-output curve after the adjustment can be achieved by the following formula:
L
out
=L
in
*G;
where Lout and Lin represent the output and input lightness of each pixel in the image, respectively. G is a gain in the range of 0 to 2. Different input lightness Lin can correspond to different gains G, that is, G is a function of Lin. The relation between the input lightness Lin and the gain G can be established in a look-up table. After the contrast-adjusting circuit is implemented, a corresponding gain G can be found in the look-up table according to the input lightness Lin, and then the aforementioned formula can be executed to generate the output lightness Lout.
However, the adjustment in the prior art can only increase the contrast of an image with a wide lightness distribution. If the lightness of certain image merely distributes in the range of 0 to the 130 gray level, after the aforementioned treatment by the formula, the lightness of the whole image will further decrease instead of the contrast being increased. As a result, the regions with low lightness in the image become so dark that their details are lost, which results in a bad adjustment. On the contrary, if the lightness of certain image merely distributes in the range of the 130 to the 255 gray level, after the aforementioned treatment, only the lightness of the whole image will further increase instead of the contrast. Consequently, it is observed that the adjustment way in the prior art is not suitable for all kinds of images.
Therefore, to solve the aforementioned problem, the main scope of the invention is to provide an image processing apparatus and an image processing method.
One scope of the invention is to provide an image processing apparatus and an image processing method, for adjusting the contrast of an input image. The input image consists of plural pixels and each pixel has a respective input lightness.
According to an embodiment of the invention, the image processing apparatus contains a first processing module, a second processing module, a gain determining module and a third processing module. The gain determining module is electrically connected to the first processing module and the second processing module. The third processing module is electrically connected to the second processing module and the gain determining module.
The first processing module is used for performing a normalization procedure on the input lightness of plural pixels to obtain a respective normalized lightness of each pixel, and determining, based on the respective normalized lightness and a first gain function, a first gain corresponding to the respective normalized lightness. The second processing module is used for generating, based on the input lightness of the plural pixels, a lightness statistics and determining, based on the lightness statistics, plural threshold lightness. The second processing module also determines, based on the plural threshold lightness and a second gain function, plural second gains corresponding to the plural threshold lightness, respectively. The gain determining module is used for determining, based on the first gain corresponding to the normalized lightness of each pixel, a target second gain, from the second gains, corresponding to the normalized lightness. The third processing module is used for generating, based on the input lightness, the corresponding first gain, and the corresponding target second gain of each pixel, an output lightness corresponding to the input lightness to adjust the contrast of the input image.
It is related to an image processing method according to another embodiment of the invention. An input image consists of plural pixels and each pixel has a respective input lightness.
A normalization procedure is executed on the input lightness of the plural pixels to obtain a respective normalized lightness of each pixel. A lightness statistics is generated based on the input lightness of the plural pixels, and plural threshold lightness can be determined based on the lightness statistics.
Next, based on the respective normalized lightness and a first gain function, a first gain corresponding to the respective normalized lightness can be determined. Based on the plural threshold lightness and a second gain function, plural second gains corresponding to the plural threshold lightness can be determined, respectively.
Then, based on the first gain corresponding to the respective normalized lightness of each pixel, a target second gain corresponding to the respective normalized lightness can be determined from the second gains.
Afterwards, an output lightness corresponding to the input lightness of each pixel can be generated based on the input lightness, the corresponding first gain, and the corresponding target second gain of each pixel. Thereby, the contrast of the input image can be adjusted.
The advantage and spirit of the invention may be understood by the following recitations together with the appended drawings.
Please refer to
As shown in
In this embodiment, the input image Iin conforms to a first color space, e.g. a RGB color space. The converter 22 is used for converting the input image Iin from the RGB color space to a second color space with the separation of lightness and colors. By this way, a respective input lightness Lin of each pixel can be transmitted to the first processing module 10, the second processing module 12, and the third processing module 16. In practical applications, the second color space can be YCbCr, Yuv, YIQ, CIELab, or Luv.
The first processing module 10 is used for performing a normalization procedure on the plural input lightness of the pixels to obtain a respective normalized lightness of each pixel. In one embodiment, the normalized lightness can be calculated by the following formula:
where Lnor represents the normalized lightness, Lin represents the input lightness, Lmin represents a minimum lightness of the image, and Lmax represents a maximum lightness of the image.
In general, the pixels of a digital image are recorded in 8 bits. Therefore, the lightness distribution of each pixel is in the range of 0 to 255 gray levels, i.e. 256 gray levels. However, the lightness of a natural image may not be uniformly distributed in the 256 gray levels. For example, the lightness of a darker image may be distributed in the range below the 150 gray level. The advantage of the normalization procedure of the invention is to rearrange the lightness of the whole image and to broaden the lightness distribution for the convenience of a following treatment. Since the 255 gray level is the maximum gray level of an eight-bit image, the distribution of the normalized lightness Lnor after the normalized procedure can be broaden in the range of 0 to 255 gray levels, which is achieved by the above formula.
The first processing module 10 is used for determining a first gain corresponding to the normalized lightness Lnor, based on the normalized lightness Lnor and a first gain function. In one embodiment, as shown in
When the plural input lightness Lin of the plural pixels are transmitted to the second processing module 12, the second processing module 12 is used for generating a lightness statistics, based on the plural input lightness Lin of the plural pixels, and for determining plural threshold lightness based on the lightness statistics. The second processing module 12 is also used for determining plural second gains corresponding to the plural threshold lightness, based on the plural threshold lightness and a second gain function.
In one embodiment, as shown in
In the following, an example is illustrated to further explain the idea of the invention. In this example, a dark-region threshold lightness and a bright-region threshold lightness can be determined, based on the lightness statistics, by the second processing module 12. As shown in
In one embodiment, the dark-region threshold lightness has a specific gray level in the lightness statistical graph such that the ratio of the calculated area under the curve, from the smallest gray level to the specific gray level (e.g. the left marked area in
The gain determining module 14 can be for determining, based on the first gain GA corresponding to the normalized lightness LN of each pixel, a target second gain corresponding to the normalized lightness LN from the second gains. In practical applications, the gain determining module 14 can be a multiplexer.
In this embodiment, the first gain GA can be in the range of −1 to 1. The aforementioned example can be used herein to explain the function of the gain determining module 14 in detail. When the first gain GA received by the gain determining module 14 is bigger than or equal to 0, the bright-region lightness gain GBH will be outputted to the third processing module 16 by the gain determining module 14; when the first gain GA received by the gain determining module 14 is smaller than 0, the dark-region lightness gain GBL will be outputted by the gain determining module 14.
The third processing module 16 is used for generating an output lightness Lout corresponding to the input lightness Lin of each pixel, based on the input lightness Lin, the corresponding first gain GA, and the corresponding target second gain of each pixel. Thereby, the contrast of the input image Iin can be adjusted.
Please refer to
G(i)=1+A(i)*B(j);
where A(i) represents the first gain, B(j) represents the target second gain, A(i)*B(j) represents the third gain, and G(i) represents the fourth gain. A(i) is in the range of −1 to 1. B(j) is in the range of 0 to 1. G(i) is in the range of 0 to 2. It is noted that the respective ranges of A(i), B(j), and G(i) are designed according to practical applications, and not limited therein.
G(i)=1+A(i)*B(j);
The first multiplier 160 can be used for multiplying the first gain A(i) by the target second gain (i.e. the dark-region lightness gain or the bright-region lightness gain) B(j) to generate the third gain A(i)*B(j). The bright-region lightness gain can correspond to G(i) bigger than 1, and the dark-region lightness gain can correspond to G(i) smaller than 1. Next, adder 162 can be used for adding the third gain A(i)*B(j) and a default value C together to generate the fourth gain G(i). The default value C can be set as 1, but not limited herein. In principle, the default value can be varied with the first gain A(i) and the target second gain B(j). Afterwards, the second multiplier 164 can be used for multiplying the input lightness Lin by the fourth gain G(i) to generate the output lightness Lout corresponding to the input lightness Lin of each pixel.
After the output lightness Lout are generated by the second multiplier 164, the input image Lin can be converted from the second color space (e.g. a Lab color space) to the first color space (e.g. the RGB color space) by the second converter 24, and an output image Iout can be outputted by the second converter 24.
It can be seen from the aforementioned formula that if the target second gain B(j) is varied, then the fourth gain G(i) is also varied correspondingly. It means that by the image processing apparatus 1 of the invention, the fourth gain G(i) can be adjusted dynamically based on the content of the input image Iin to improve the contrast of any kind of image with a specific lightness distribution.
In the following, two examples of different image-adjusting ways are illustrated to highlight the advantage of the image processing apparatus 1 of the invention. Please refer to
Please refer to
Please refer to
In step S100, a normalization procedure can be executed on the plural input lightness of the plural pixels to obtain a respective normalized lightness of each pixel.
In step S102, a lightness statistics can be generated based on the plural input lightness of the plural pixels, and plural threshold lightness can be determined based on the lightness statistics. The processing procedures of the normalized lightness and the plural threshold lightness are disclosed in the preceding paragraphs, and are not repeated herein.
After step S100, based on the normalized lightness and a first gain function, a first gain corresponding to the normalized lightness can be determined by step S104. In one embodiment, step S104 can be executed by using a look-up table. Plural normalized lightness and plural first gains, generated by the first gain function, are recorded in the look-up table in advance. Each normalized lightness corresponds to one of the first gains.
After step S102, based on the plural threshold lightness and a second gain function, plural second gains corresponding to the plural threshold lightness can be determined by step S106. In one embodiment, step S106 can be executed by using a look-up table. Plural threshold lightness and plural second gains, generated by the second gain function, are recorded in the look-up table in advance. Each threshold lightness corresponds to one of the second gains.
After determining the first gain and the second gains, based on the first gain corresponding to the normalized lightness of each pixel, a target second gain corresponding to the normalized lightness can be determined from the second gains by step S108.
Next, based on the input lightness, the corresponding first gain, and the corresponding target second gain of each pixel, an output lightness corresponding to the input lightness of each pixel can be generated by step S110. Thereby, the contrast of the input image can be adjusted.
In one embodiment, step S110 can be achieved by the following steps. First, a third gain is generated by multiplying the first gain by the target second gain. Next, a fourth gain is generated by adding the third gain and a default value together. Afterwards, an output lightness corresponding to the input lightness of each pixel is generated by multiplying the input lightness by the fourth gain.
Compared to the prior art, the lightness of an input image can be adjusted to improve the contrast of the input image by the image processing apparatus and image processing method of the invention. More particularly, appropriate gains can be chosen dynamically for the high-lightness and low-lightness regions of an input image, respectively. Therefore, even an image with a non-uniform lightness distribution still can be adjusted appropriately to improve the contrast of the image, and to further improve the quality of the image.
With the example and explanations above, the features and spirits of the invention will be hopefully well described. Those skilled in the art will readily observe that numerous modifications and alterations of the device may be made while retaining the teaching of the invention. Accordingly, the above disclosure should be construed as limited only by the metes and bounds of the appended claims.
Number | Date | Country | Kind |
---|---|---|---|
097129795 | Aug 2008 | TW | national |