Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Intensity Transformation Operations on Images in Python OpenCV

  • Isha BansalIsha Bansal
  • November 26, 2021
  • Python Modules
Intensity Transformation Operations on Images in Python OpenCV

Hey Folks! In this tutorial, we will have a look into changing the intensity of images using the Python programming language.


Introduction to Image Intensity Transformation

Images are subjected to intensity modifications for contrast manipulation or picture thresholding. These are in the spatial domain, which means they are done directly on the pixels of the picture at hand rather than on the Fourier transform of the image.


Implementing Intensity Transformation Operations on Images – Python OpenCV

The first step involves loading the necessary modules/libraries and loading the image we would like to work on in the program using the cv2.imread function of the OpenCV library.

import cv2
import numpy as np
from google.colab.patches import cv2_imshow

img = cv2.imread('sample.jpg')
cv2_imshow(img)
Intensity Transformations Sample Image
Intensity Transformations Sample Image

Next, we set a gamma value which will define the intensity of the image, and gamma correction is done along the gamma value to get the image of the correct intensity.

As the last step, we save the image using the cv2.imwrite method of the OpenCV library.

for gamma in [0.1, 0.5, 1.2, 2.2]:
	gamma_corrected = np.array(255*(img / 255) ** gamma, dtype = 'uint8')
	cv2.imwrite('gamma_transformed_'+str(gamma)+'.jpg', gamma_corrected)

All the output images for the four gamma values are displayed below.

Gamma Transformed0 1
Gamma Transformed0 1
Gamma Transformed0 5
Gamma Transformed0 5
Gamma Transformed1 2
Gamma Transformed1 2
Gamma Transformed2 2
Gamma Transformed2 2

Conclusion

Congratulations! You just learned how to build a Python program to modify the intensity of images using the OpenCV Library in Python. Hope you enjoyed it! 😇

Liked the tutorial? In any case, I would recommend you to have a look at the tutorials mentioned below:

  1. Visualizing Colors In Images Using Histograms – Python OpenCV
  2. Draw Shapes Using OpenCV – A Complete How-To Guide
  3. Live Sketch Using Webcam with Python OpenCV [Easy Guide]
  4. Python OpenCV filter2D() function – A Complete Guide

Thank you for taking your time out! Hope you learned something new!! 😄


Isha Bansal
Isha Bansal

Hey there stranger!
Do check out my blogs if you are a keen learner!

Hope you like them!

Articles: 185
Numpy dot() – A Complete Guide to Vectors, Numpy, And Calculating Dot Products
Previous Post Numpy dot() - A Complete Guide to Vectors, Numpy, And Calculating Dot Products
Next Post Network Analysis in Python - A Complete Guide
Network Analysis in Python – A Complete Guide

Related Posts

np.linalg.eig: Eigenvalues and Eigenvectors

np.linalg.eig: Eigenvalues and Eigenvectors

  • November 30, 2026
np.sin() in NumPy: Radians, Arrays, and Examples

How to Use np.sin() in NumPy

  • November 30, 2026
cv2.imread: Load Images with OpenCV

cv2.imread: Load Images with OpenCV

  • November 30, 2026

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.