You are on page 1of 3

LAB 10 (Assignment)

1. CONTRAST STRETCHING
import cv2
import numpy as np
from google.colab.patches import cv2_imshow
img = cv2.imread('/content/jerry.jpg')
original = img.copy()
xp = [0, 64, 128, 192, 255]
fp = [0, 16, 128, 240, 255]
x = np.arange(256)
table = np.interp(x, xp, fp).astype('uint8')
img = cv2.LUT(img, table)
cv2_imshow(original)
cv2_imshow( img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Original Image Stretched Image

2. CANVY EDGE DETECTION


img = cv2.imread("/content/HD-wallpaper-whatsapp-dp-
cartoon.jpg")
# Setting parameter values
t_lower = 50 # Lower Threshold
t_upper = 150 # Upper threshold
# Applying the Canny Edge filter
edge = cv2.Canny(img, t_lower, t_upper)
cv2_imshow( img)
cv2_imshow( edge)
Original Image Canvy Edge Image
3. SHARPENING
# Load the image
image = cv2.imread('/content/powerpuffgirls.png')

# Show the original image


cv2_imshow(image)

# Sharpen the image using the Laplacian operator


sharpened_image2 = cv2.Laplacian(image, cv2.CV_64F)

# Show the sharpened image


cv2_imshow(sharpened_image2)

Original Image Sharpened Image

4. MEDIAN BLUR
# Reading the image
image = cv2.imread('/content/minions.jpg')

# Applying the filter


medianBlur = cv2.medianBlur(image, 9)

# Showing the image


cv2_imshow(image)
cv2_imshow( medianBlur)
Original Image Median Blur Image
5. MORPHOLOGY
import matplotlib.pyplot as plt
import cv2
# read the image
img = cv2.imread(r"/content/flower.jpg", 0)
# binarize the image
binr = cv2.threshold(img, 0, 255,
cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
# define the kernel
kernel = np.ones((3, 3), np.uint8)
# invert the image
invert = cv2.bitwise_not(binr)
# use morph gradient
morph_gradient = cv2.morphologyEx(invert, cv2.MORPH_GRADIENT,
kernel)

plt.subplot(121)
plt.title("Original Image")
plt.imshow(image, cmap='gray')
plt.subplot(122)
plt.title("Processed Image")
plt.imshow(morph_gradient, cmap='gray')
plt.tight_layout()
plt.show()

You might also like