Join thousands of AI enthusiasts and experts at the Learn AI Community.

Latest

# Image Intensity Manipulation

Last Updated on January 6, 2023 by Editorial Team

Last Updated on March 27, 2021 by Editorial Team

### What counts as intensity manipulation

• Explicit changes to pixel values in any of the channels.
• Mathematical operations on images.
• Brightness changes.
• Contrast changes.
• Gamma manipulation.
• Histogram equalization
• Advanced manipulation-filtering, enhancements etc.

Load Image using OpenCV

`import numpy as npimport cv2from matplotlib import pyplot as pltimg = cv2.imread(folder_path + "imgs/chapter3/man.jpg", 0);plt.imshow(img, cmap = "gray");plt.show()`

Adding a constant value to input image using Opencv

`img = cv2.imread(folder_path + "imgs/chapter3/man.jpg", 0);`
`##########################FOCUS############################img = cv2.add(img, 120);###########################################################`
`plt.imshow(img, cmap = "gray");plt.show()`

Subtracting a constant value to input image using Opencv

`img = cv2.imread(folder_path + "imgs/chapter3/man.jpg", 0);`
`##########################FOCUS############################img = cv2.subtract(img, 120);####################################################################`
`plt.imshow(img, cmap = "gray");plt.show()`

### Mean Subtraction from Image

Method 1

• Split Image into its channels.
• For each channel calculate its mean.
• Subtract that mean from each pixel in that channel

Method 2 (Used in Deep Learning)

• Split all images into their respective channels

For each channel of all images.

• Find mean of that channel for each image.
• Find mean of all the means calculated.

Applications

• Part of batch normalization.

### Negative images

Negative of Gray Scale

Negative of RGB images

### Brightness

• The quality or state of giving out or reflecting light.
• Brightness is a relative term. It depends on your visual perception.
• Brightness can be defined as the amount of energy output by a source of light relative to the source we are comparing it to.

### Contrast

• Contrast is the difference in luminance or color that makes an object ( or its representation in an image or display) distinguishable.
• Visualized as difference between maximum and minimum pixel intensity in an image.
• Contrast is determined by the difference in the color and brightness of the objects within the same field of view.

Manipulating contrast in an image

### Gamma

• Gamma correction, or often simply gamma, is a non linear operation used to encode and decode luminance.
• All color and Gray Scale digital image files contain gamma data.
• Gamma is about translating between digital sensitivity and human eye sensitivity , providing many advantages on one hand but adding complexity on the other hand.
• Gamma optimizes the contrast and brightness in the midtones.

Manipulating gamma using Opencv

### Histogram equalization

Histogram

• A histogram is a graph. A graph that shows frequency of anything.
• Image pixel histogram represents frequency of pixels having certain intensity values.

Histogram equalization

• Histogram equalization is used to enhance contrast.
• This method increases the global contrast of Images.

Histogram visualization using Numpy

Histogram Equalization using OpenCV

You can find the complete jupyter notebook here.

If you have any questions, you can reach Abhishek . Feel free to reach out to him.

I am extremely passionate about computer vision and deep learning. I am an open-source contributor to Monk Libraries.

You can also see my other writings at:

Akula Hemanth Kumar – Medium

Image Intensity Manipulation was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

Published via Towards AI