Experiment No2 Dip
Experiment No2 Dip
Aim:
(i) Find different resolutions images of an image (input image size: 256x256).
(ii) To read and display the color image and its channels (R, G, and B).
(iii) Resize image into double and half sizes.
(iv) Image color depth changing (8-bits to 7 bits, 16 bits etc.)
(v) Perform and display the channels subtraction in combinations (R-G, B-R, B-G) of
an image.
import cv2
import numpy as np
img = cv2.imread("/content/Arslan img.jpg")
img = cv2.resize(img, (250, 300))
from google.colab.patches import cv2_imshow
cv2_imshow(img)
img4 = img[:, :, 0]
img5 = img[:, :, 1]
img6 = img[:, :, 2]
fig = plt.figure(figsize=(10, 7))
fig.add_subplot(1, 3, 1)
plt.imshow(img4)
plt.axis("off")
plt.title("R_Gray")
fig.add_subplot(1, 3, 2)
plt.imshow(img5)
plt.axis("off")
plt.title("G_Gray")
fig.add_subplot(1, 3, 3)
plt.imshow(img6)
plt.axis("off")
plt.title("B_Gray")
fig = plt.figure(figsize=(10, 7))
fig.add_subplot(1, 3, 1)
plt.imshow(img4, cmap='Reds', vmin=0, vmax=255)
plt.axis("off")
plt.title("R_channel")
fig.add_subplot(1, 3, 2)
plt.imshow(img5, cmap='Greens', vmin=0, vmax=255)
plt.axis("off")
plt.title("G_channel")
fig.add_subplot(1, 3, 3)
plt.imshow(img5, cmap='Blues', vmin=0, vmax=255)
plt.axis("off")
plt.title("B_Channel")
img_b = img[:, :, 0]
img_g = img[:, :, 1]
img_r = img[:, :, 2]
img_rb = cv2.subtract(img_r,img_b)
img_br = cv2.subtract(img_b,img_r)
img_bg = cv2.subtract(img_b,img_g)
fig = plt.figure(figsize=(10,7))
fig.add_subplot(1,3,1)
plt.imshow(img_rb)
plt.axis("off")
plt.title("R - B")
fig.add_subplot(1,3,2)
plt.imshow(img_br)
plt.axis("off")
plt.title("B - R")
fig.add_subplot(1,3,3)
plt.imshow(img_bg)
plt.axis("off")
plt.title("B - G")
fig.add_subplot(1, 4, 1)
plt.imshow(img7)
plt.axis("off")
plt.title("Color_depth = Original")
fig.add_subplot(1, 4, 2)
plt.imshow(img8)
plt.axis("off")
plt.title("Color_depth = 32")
fig.add_subplot(1, 4, 3)
plt.imshow(img9)
plt.axis("off")
plt.title("Color_depth = 16")
fig.add_subplot(1, 4, 4)
plt.imshow(img10)
plt.axis("off")
plt.title("Color_depth = 10")
Result: All the operations on the image like resizing of image, variation in color depth,
RBG channels and subtraction in combination are done.