Objective:
Objective of this topic is to familiarize with different color space eg: RGB and HSI
Description:
Color image processing: The use of color image processing is motivated by two principle factors.
i. Color is a powerful descriptor
ii. Humans can distinguish between thousands of colors shades or intensities compared to about only two dozen shades of gray We have two types of color image processing Pseudo color processing: Pseudo-color processing:
Pseudo-color processing is a technique that maps each of the grey levels of a black and white image into an assigned color. This colored image, when displayed, can make the identification of certain features easier for the observer. The mappings are computationally simple and fast. This makes pseudo-color an attractive technique for use on digital image processing systems that are designed to be used in the interactive mode.
Full color image processing:
Full color image processing fall into two major categories, in the first category we process each component image individually and then form a composite processed color image from individually process components while in second category we work with color pixels directly.
Color model:
The color model aims to facilitate the specifications of colors in some standard way. Different types of color models are used in multiple fields like in hardware, in multiple applications of creating animation, etc.
RGB Model:
In the RGB model, each color appears in its primary components of red, green and blue. This model is based on a Cartesian coordinate system.
Saturation calculation:
Convert it to HSV color space using above mentioned equations. Display each channel (Hue, saturation and intensity/value) separately.
Code
import cv2 as cv
import numpy as np
img = cv.imread('freestudystrom.tif') # read input image
dims =
np.shape(img)
rows = dims[0]
cols = dims[1]
# Function to
Convert RGB image to HSV image
def HSVimage(img):
Hue = np.zeros((rows, cols), dtype=np.uint32)
Saturation = np.zeros((rows, cols), dtype=np.float)
Intensity = np.zeros((rows, cols), dtype=np.float)
for i in range(rows):
for j in range(cols):
value = img[i, j]
#normalize
B = value[0] / 255
G = value[1] / 255
R = value[2] / 255
array = [B, G, R]
Cmax = np.max(array)
Cmin = np.min(array)
Delta = Cmax - Cmin
# Hue Calculation
if Delta == 0:
Hue[i, j] = 0
elif Cmax == R:
Hue[i, j] = 60 * np.mod((G - B) / Delta, 6)
elif Cmax == G:
Hue[i, j] = 60 * (((B - R) / Delta) + 2)
elif Cmax == B:
Hue[i, j] = 60 * (((R - G) / Delta) + 4)
# Saturation Calculation
if Cmax == 0:
Saturation[i, j] = 0
else:
Saturation[i, j] = (Delta
/ Cmax)*255
# Intensity Value
Intensity[i, j] = Cmax*255
return Hue,Saturation,Intensity
#
Normalization
def normalization(out):
minimum = np.min(out)
maximum = np.max(out)
out = np.zeros((rows, cols), dtype=np.uint8)
for i in range(0, rows):
for j in range(0, cols):
out[i][j] = (255*(out[i][j]-minimum))//(maximum-minimum)
return out
Hue, Saturation, Intensity = HSVimage(img)
# Applying
Normalization
Hue =
normalization(Hue)
Saturation = normalization(Saturation)
Intensity = normalization(Intensity)
# display all
channels and overall result
cv.imshow('Hue', Hue)
cv.imshow('Saturation', Saturation)
cv.imshow('Intensity ', Intensity)
Output = cv.merge([Hue,Saturation,Intensity]) #merge all channels to get final
image
cv.imshow('HSV Image ', Output)
cv.waitKey(0)
Output:
Code
import cv2 as cv
import numpy as np
img = cv.imread('freestudystrom.tif') # read input image
dims = np.shape(img)
rows = dims[0]
cols = dims[1]
# Function to
Convert RGB image to HSV image
def HSVimage(img):
Hue = np.zeros((rows, cols), dtype=np.uint32)
Saturation = np.zeros((rows, cols), dtype=np.float)
Intensity = np.zeros((rows, cols), dtype=np.float)
for i in range(rows):
for j in range(cols):
value = img[i, j]
#normalize
B = value[0] / 255
G = value[1] / 255
R = value[2] / 255
array = [B, G, R]
Cmax = np.max(array)
Cmin = np.min(array)
Delta = Cmax - Cmin
# Hue Calculation
if Delta == 0:
Hue[i, j] = 0
elif Cmax == R:
Hue[i, j] = 60 * np.mod((G - B) / Delta, 6)
elif Cmax == G:
Hue[i, j] = 60 * (((B - R) / Delta) + 2)
elif Cmax == B:
Hue[i, j] = 60 * (((R - G) / Delta) + 4)
# Saturation Calculation
if Cmax == 0:
Saturation[i, j] = 0
else:
Saturation[i, j] = (Delta
/ Cmax)*255
# Intensity Value
Intensity[i, j] = Cmax*255
return Hue,Saturation,Intensity
#
Normalization
def normalization(out):
minimum = np.min(out)
maximum = np.max(out)
out = np.zeros((rows, cols), dtype=np.uint8)
for i in range(0, rows):
for j in range(0, cols):
out[i][j] = (255*(out[i][j]-minimum))//(maximum-minimum)
return out
Hue, Saturation, Intensity = HSVimage(img)
# Applying
Normalization
Hue =
normalization(Hue)
Saturation = normalization(Saturation)
Intensity = normalization(Intensity)
# display all
channels and overall result
cv.imshow('Hue', Hue)
cv.imshow('Saturation', Saturation)
cv.imshow('Intensity ', Intensity)
Output = cv.merge([Hue,Saturation,Intensity]) #merge all channels to get final
image
cv.imshow('HSV Image ', Output)
cv.waitKey(0)
Output:
Code
import numpy as np
import cv2 as cv
import math as m
img = cv.imread('freestudystrom.tif',cv.IMREAD_COLOR) # Read input image
b,g,r =
cv.split(img) #split the channels
dims =
np.shape(img) #dimensions of input image
rows = dims[0]
cols = dims[1]
B_img = cv.GaussianBlur(b,(3,3),cv.BORDER_DEFAULT) #smoothen blue channel
G_img =
cv.GaussianBlur(g,(3,3),cv.BORDER_DEFAULT) #smoothen green channel
R_img =
cv.GaussianBlur(r,(3,3),cv.BORDER_DEFAULT) #smoothen red channel
Output =
cv.merge([B_img,G_img,R_img])
#merge all
channels to get final image
#show all channels blurred and overall blurred image
cv.imshow('Blue Channel', B_img)
cv.imshow('Green Channel ', G_img)
cv.imshow(' Red Channel', R_img)
cv.imshow('Blurred Image', Output)
cv.waitKey(0)
Output:
No comments:
Post a Comment