- Hands-On Image Processing with Python
- Sandipan Dey
- 195字
- 2025-02-22 06:42:28
Some gray-level transformations
Here we explore a couple of transformations where, using a function, each single pixel value from the input image is transferred to a corresponding pixel value for the output image. The function point() can be used for this. Each pixel has a value in between 0 and 255, inclusive.
Log transformation
The log transformation can be used to effectively compress an image that has a dynamic range of pixel values. The following code uses the point transformation for logarithmic transformation. As can be seen, the range of pixel values is narrowed, the brighter pixels from the input image have become darker, and the darker pixels have become brighter, thereby shrinking the range of values of the pixels:
im_g.point(lambda x: 255*np.log(1+x/255)).show()
The next figure shows the output log-transformed image produced by running the previous line of code:

Power-law transformation
This transformation is used as γ correction for an image. The next line of code shows how to use the point() function for a power-law transformation, where γ = 0.6:
im_g.point(lambda x: 255*(x/255)**0.6).show()
The next figure shows the output power-law-transformed image produced by running the preceding line of code:
