You are on page 1of 10

Lovely Professional University

Topic: Basic Operations on Image

Name: Taha Abdullah Ali Fadhaeel Reg no:12013973


Roll no:RM2071 A-05 Course code:ECE645
Date:16/02/2021 Practicles no: 2
Reading/Uploading an image using cv2: Method 1

import cv2

import numpy

from matplotlib import pyplot as plt

img=cv2.imread('E:/from downloads/Grim-Reaper-6.JPG')

image=cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

#cv2.imshow(image)

plt.imshow(image)

plt.title('RGB Color Image')

plt.show()

print(image.shape)

print("image shape %s" % str (image.shape))

print("image width : %d" % image.shape [0])

print("image height : %d" % image.shape [1])

print("image columns : %d" % image.shape [2])

print("(R G B) = %s" % str(image[200,100]))

Input image
Output Image

(1200, 1920, 3)
image shape (1200, 1920, 3)
image width : 1200
image height : 1920
image columns : 3
(R G B) = [1 1 1]

Reading/Uploading an image using cv2: Method 2

import cv2

# image will be displayed in new window

image = cv2.imread('C:/Users/hp/Desktop/Images_ECE348/parrot.jpg')

cv2.imshow('Original', image)

cv2.waitKey()
print(image.shape)

print("image width : %d" % image.shape [0])

print("image height : %d" % image.shape [1])

print("image columns : %d" % image.shape [2])

INPUT IMAGE

OUTPUT IMAGE

(1280, 720, 3)
image width : 1280
image height : 720
image columns : 3

Reading/Uploading an image using skimage

from skimage import io

from matplotlib import pyplot as plt


image = io.imread('C:/Users/hp/Downloads/Teacher m.JPEG')

io.imshow(image)

print(image.shape)

print("image shape %s" % str (image.shape))

print("image width : %d" % image.shape [0])

print("image height : %d" % image.shape [1])

print("image columns : %d" % image.shape [2])

print("(R G B) = %s" % str(image[200,100]))

plt.imshow(image)

plt.title('RGB Color Image')

plt.show()

Input image

Output image

(1080, 607, 3)
image shape (1080, 607, 3)
image width : 1080
image height : 607
image columns : 3
(R G B) = [52 47 51]
Reading/Uploading an image using PIL

from PIL import Image

import numpy as np

from pylab import *

img=Image.open('C:/Users/hp/Downloads/Taha pic.JPEG')

figure(0)

img.show()

INPUT IMAGE

OUTPUT IMAGE
RGB to Gray-Scale Conversion using cv2

import cv2

image = cv2.imread('E:/from downloads/Grim-Reaper-3.JPG')

cv2.imshow('Original', image)

cv2.waitKey()

gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

cv2.imshow('Grayscale', gray_image)

cv2.waitKey()

INPUT IMAGE

OUTPUT IMAGE
Another Way: RGB to Gray-Scale Conversion using cv2

import cv2

# The second argument zero specifies that

#image is to be read in grayscale mode

img = cv2.imread('C:/Users/hp/Downloads/Taha pic.JPEG',0)

cv2.imshow('Grayscale', img)

cv2.waitKey()

INPUT IMAGE

OUTPUT IMAGE
RGB to Gray-Scale Conversion using skimage

from skimage import io

import matplotlib.pyplot as plt

image_gray= io.imread('C:/Users/hp/Downloads/Teacher m.JPEG',as_gray=True)

imshow(image_gray)

Input image
Output image

You might also like