Logarithm value of a number is a number that raises power to a base number which gives the same number as in input. Simply, the logarithm is the inversion of exponential value of a number.
log(exp(x)) = x
How log value of a number is calculated?
Let’s see an example,
By applying logarithm in both sides,
log(2^3) = log(8) 3 * log(2) = log(8) 3 = log(8) / log(2) Log(8) = 3 (base is 2)
We know, value of a number with power 0 is equal to 1. So,
log1 = 0
log0 = infinity
We can find the log value of a number using Python as follow:
Input : 8 Output : Natural log value of the input number is 2.0794415416798357 Log value of the number with base 2 is 3.0 Log value of the number with base 10 is 0.9030899869919435 Input : 255 Output : Natural log value of the input number is 5.541263545158426 Log value of the number with base 2 is 7.994353436858858 Log value of the number with base 10 is 2.406540180433955
Note: You can see log function in Python by visiting here.
Logarithmic transformation of an image is one of the gray level image transformations. Log transformation of an image means replacing all pixel values, present in the image, with its logarithmic values. Log transformation is used for image enhancement as it expands dark pixels of the image as compared to higher pixel values.
The formula for applying log transformation in an image is,
S = c * log (1 + r) where, R = input pixel value, C = scaling constant and S = output pixel value
The value of ‘c’ is chosen such that we get the maximum output value corresponding to the bit size used. So, the formula for calculating ‘c’ is as follows:
c = 255 / (log (1 + max_input_pixel_value))
When we apply log transformation in an image and any pixel value is ‘0’ then its log value will become infinite. That’s why we are adding ‘1’ to each pixel value at the time of log transformation so that if any pixel value is ‘0’, it will become ‘1’ and its log value will be ‘0’.
Let’s apply log transformation in an image using Python.
Input File –
Log transformation of gives actual information by enhancing the image. If we apply this method in an image having higher pixel values then it will enhance the image more and actual information of the image will be lost. So, this method can’t be applied everywhere. It can be applied in images where low pixel values are more than higher ones.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Negative transformation of an image using Python and OpenCV
- Perspective Transformation - Python OpenCV
- Python OpenCV - Affine Transformation
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Image resizing using Seam carving using OpenCV in Python
- Find Circles and Ellipses in an Image using OpenCV | Python
- Cartooning an Image using OpenCV - Python
- OpenCV Python Program to analyze an image using Histogram
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Reading an image in OpenCV using Python
- Python | Detect corner of an image using OpenCV
- Image Pyramid using OpenCV | Python
- Python | Image blurring using OpenCV
- Image Resizing using OpenCV | Python
- Image Translation using OpenCV | Python
- Image Registration using OpenCV | Python
- Python | Detect Polygons in an Image using OpenCV
- Image Steganography using OpenCV in Python
- Create Local Binary Pattern of an image using OpenCV-Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.