Dip Lab Report
Dip Lab Report
UID: TNU2018020100016
Stream: B.tech in Computer Science Engineering with Specialization in Cyber Security, 4 th Year, 7th
Semester
Batch:2018-2022
Subject: Image Processing Lab Report
Experiment 2: Implement different types of image enhancement/transformation likes Image negative, log
transformation, power law transformation, intensity level slicing etc. in any programming language.
# load dependencies
import cv2
import matplotlib.pyplot as plt
import numpy as np
import math
Image negative:
Code:
# negative transformation of the image
img_neg = 1 - img
# result of negtaive transformation
cv2.imwrite(‘D:\\image_processing\\Sample Images\\img_neg.jpg', img_neg)
cv2.imshow("Output",img_neg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output Image for Negative Transformation:
Log transformation:
Code:
#log transformation of the image
#gamma correction
gamma_img = np.array(255 * (img / 255) ** gamma, dtype = 'uint8')
Gamma = 0.5
Gamma = 1.2
Gamma = 2.2
Gamma = 3.2
Intensity level slicing:
Code
# image convert into gray scale
img = cv2.imread(‘D:\\image_processing\\Sample Images\\ nature.jpg,0)
# 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:
img2[i,j] = 255
else:
img2[i,j] = 0
# Display the image
cv2.imshow('sliced image', img2)
cv2.waitKey(0)
cv2.destroyAllWindows()