Experiment 7 Aim: To Study and Implement Image Negative, Gray Level Slicing and Thresholding Code: 1. Negative of An Image
Experiment 7 Aim: To Study and Implement Image Negative, Gray Level Slicing and Thresholding Code: 1. Negative of An Image
Experiment 7 Aim: To Study and Implement Image Negative, Gray Level Slicing and Thresholding Code: 1. Negative of An Image
Experiment 7
Aim: To study and implement image negative , gray level slicing and thresholding
Code:
1. Negative of an image:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('flower.jpeg')
grey_level= range(0,256)
print("Original image")
cv2_imshow(img)
L=256
S=[(255-i) for i in img]
a=np.asarray(S)
OUTPUT:
2. Gray level Slicing:
img = cv2.imread('wiki.jpg',0)
r1=int(input("Enter the starting range value: "))
r2=int(input("Enter the starting range value: "))
img = cv2.imread('flower.jpeg',0)
print("Original image : ")
cv2_imshow(img)
w= np.arange(r1,r2,1)
final=[]
for pix in img:
S=[]
for i in pix:
if i in w:
S.append(255)
else:
S.append(0)
final.append(S)
final=np.asarray(final)
3. Thresholding:
img = cv2.imread('wiki.jpg',0)
thresh=int(input("Enter threshold value : "))
final=[]
for pix in img:
S=[]
for i in pix:
if i > thresh:
S.append(255)
else:
S.append(0)
final.append(S)
final=np.asarray(final)
OUTPUT: