Our terms of service are changing. Learn more.

Publication

Latest

Image Intensity Manipulation

Last Updated on March 27, 2021 by Editorial Team

Author(s): Akula Hemanth Kumar

Computer Vision

Photo by Jonathan Bowers on Unsplash

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.

https://medium.com/media/c33aa632cc9c8ba8c3b51c08e763084b/href

Negative images

Negative of Gray Scale

https://medium.com/media/076621a8e10e6d1b5b2a74f64c433a38/href

Negative of RGB images

https://medium.com/media/02d7dcf708aa142d445c723f22799ec6/href

Adding two images

Direct adding

https://medium.com/media/89f5d704e073cf05815262c266ee06d0/href

Weighted Adding

https://medium.com/media/6ee8c019d0254a78ddeb45fffd2e3e35/href

Subtracting two images

https://medium.com/media/666177a6e891a34dcd84b22bfaf5bef4/href

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.

https://medium.com/media/c418b148882f169eb332eaa80c290c7f/href

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

https://medium.com/media/8d4787d4e3a5d683809f3083655642af/href

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

https://medium.com/media/84529c631afa390872ad9a4cbdb52768/href

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

https://medium.com/media/30589f56f32235b2d88e720cd957b0da/href

Histogram Equalization using OpenCV

https://medium.com/media/975815ce8e514f11359cdc548e21b1e1/href

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

Feedback ↓