In [3]:
#Question 1: OpenCV(for Python) installed while installing Anaconda(for Windows), which installs packages and Jupyter Notebook
#This HTML file consisting of Python code is generated from Jupyter.
import cv2
import imutils
import numpy as np,sys
import os
from IPython.display import Image
image = cv2.imread('Suma_Dixit_1MB.jpg')
#Question 2: Converting color image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite('Suma_Dixit_1MB_gray.jpg',gray_image)
Image(filename='Suma_Dixit_1MB_gray.jpg')
Out[3]:
In [66]:
#Question 3: Applying transformations on color image
#Transformation 1 : Changing color schemes BGR to HSV
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
cv2.imwrite('Suma_Dixit_1MB_hsv_color.jpg',hsv_image)
Image(filename='Suma_Dixit_1MB_hsv_color.jpg')
Out[66]:
In [67]:
#Transformation 2 : Changing color schemes BGR to YCrCb
YCrCb_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
cv2.imwrite('Suma_Dixit_1MB_YCrCb_image_color.jpg',YCrCb_image)
Image(filename='Suma_Dixit_1MB_YCrCb_image_color.jpg')
Out[67]:
In [68]:
#Transformation 3 : Changing color schemes BGR to RGB
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.imwrite('Suma_Dixit_1MB_rgb_image_color.jpg',rgb_image)
Image(filename='Suma_Dixit_1MB_rgb_image_color.jpg')
Out[68]:
In [69]:
#Transformation 4 : Blurring (Homogenous/Average Blurring)
blur = cv2.blur(image,(35,35))
cv2.imwrite('Suma_Dixit_1MB_blur1_color.jpg',blur)
Image(filename='Suma_Dixit_1MB_blur1_color.jpg')
Out[69]:
In [70]:
#Transformation 5 : Blurring (Guassian Blurring)
blur = cv2.blur(image,(41,41))
cv2.imwrite('Suma_Dixit_1MB_blur2_color.jpg',blur)
Image(filename='Suma_Dixit_1MB_blur2_color.jpg')
Out[70]:
In [71]:
#Transformation 6 : Blurring (Median Blurring)
median = cv2.medianBlur(image,35)
cv2.imwrite('Suma_Dixit_1MB_blur3_color.jpg',median)
Image(filename='Suma_Dixit_1MB_blur3_color.jpg')
Out[71]:
In [72]:
#Transformation 7 : Blurring (Bilateral Blurring)
blur = cv2.bilateralFilter(image,35,315,315)
cv2.imwrite('Suma_Dixit_1MB_blur4_color.jpg',blur)
Image(filename='Suma_Dixit_1MB_blur4_color.jpg')
Out[72]:
In [ ]:
 
In [73]:
#Transformation 8 : Geometric Transformation (Scaling)
resized_image = cv2.resize(image, (400, 100)) 
cv2.imwrite('Suma_Dixit_1MB_scale_color.jpg',resized_image)
Image(filename='Suma_Dixit_1MB_scale_color.jpg')
Out[73]:
In [74]:
#Transformation 9 : Geometric Transformation (Translation)
rows,cols = image.shape[:2]
M = np.float32([[1,0,100],[0,1,50]])
translated_image = cv2.warpAffine(image,M,(cols,rows)) 
cv2.imwrite('Suma_Dixit_1MB_translate_color.jpg',translated_image)
Image(filename='Suma_Dixit_1MB_translate_color.jpg')
Out[74]: