Image Intensity Manipulation
Last Updated on January 6, 2023 by Editorial Team
Last Updated on March 27, 2021 by Editorial Team
Author(s): Akula Hemanth Kumar
Computer Vision
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 np
import cv2
from matplotlib import pyplot as plt
img = 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
Adding twoΒ images
Direct adding
Weighted Adding
Subtracting twoΒ 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:
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