0% found this document useful (0 votes)
23 views5 pages

Experiment No2 Dip

dip lab assign

Uploaded by

Md Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Experiment No2 Dip

dip lab assign

Uploaded by

Md Arslan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ExpErimEnt no- 02

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.

Software Required: Google colaboratory.

Code and Output:

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)

import matplotlib.pyplot as plt


img = cv2.resize(img,(200,200))
plt.imshow(img)
plt.title("Resized image")

img1 = cv2.resize(img, (200, 200))


img2 = cv2.resize(img, (100, 100))
img3 = cv2.resize(img, (50,50))
fig = plt.figure(figsize=(10,7))
fig.add_subplot(1, 3, 1)
plt.imshow(img1)
plt.axis("off")
plt.title("Size=200x200")
fig.add_subplot(1, 3, 2)
plt.imshow(img2)
plt.axis("off")
plt.title("Size=100x100")
fig.add_subplot(1, 3, 3)
plt.imshow(img3)
plt.axis("off")
plt.title("Size=50x50")

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")

#!pip install Pillow#


from PIL import Image
img7 = Image.open("/content/Arslan img.jpg")
img8 = img7.convert("P", palette = Image.ADAPTIVE, colors=32)
img9 = img7.convert("P", palette = Image.ADAPTIVE, colors=16)
img10 = img7.convert("P", palette = Image.ADAPTIVE, colors=10)

fig = plt.figure(figsize=(10, 7))

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.

You might also like