Intensity level slicing means highlighting a specific range of intensities in an image. In other words, we segment certain gray level regions from the rest of the image.
Suppose in an image, your region of interest always take value between say 80 to 150. So, intensity level slicing highlights this range and now instead of looking at the whole image, one can now focus on the highlighted region of interest.
Since, one can think of it as piecewise linear transformation function so this can be implemented in several ways. Here, we will discuss the two basic type of slicing that is more often used.
- In the first type, we display the desired range of intensities in white and suppress all other intensities to black or vice versa. This results in a binary image. The transformation function for both the cases is shown below.
- In the second type, we brighten or darken the desired range of intensities(a to b as shown below) and leave other intensities unchanged or vice versa. The transformation function for both the cases, first where the desired range is changed and second where it is unchanged, is shown below.
Let’s see how to do intensity level slicing using OpenCV-Python. Below code is for type 1 as discussed above
import numpy as np
# Load the image
img = cv2.imread('D:/downloads/forest.jpg',0)
# Find width and height of image
row, column = img.shape
# Create an zeros array to store the sliced image
img1 = np.zeros((row,column),dtype = 'uint8')
# Specify the min and max range
min_range = 10
max_range = 60
# Loop over the input image and if pixel value lies in desired range set it to 255 otherwise set it to 0.
for i in range(row):
for j in range(column):
if img[i,j]>min_range and img[i,j]<max_range:
img1[i,j] = 255
img1[i,j] = 0
# Display the image
cv2.imshow('sliced image', img1)
Applications: Mostly used for enhancing features in satellite and X-ray images.
Hope you enjoy reading.
If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.