You are on page 1of 5

WEEK 8

1 from google.colab import drive
2 drive.mount('/content/drive')

Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mou

1 from google.colab.patches import cv2_imshow
2 import cv2

1 img=cv2.imread("/content/drive/MyDrive/ROBO DOG.jpeg",1)
2 cv2_imshow(img)
3 cv2.imwrite("/content/drive/MyDrive/shapes-basic-color.png",img)

True

1
import numpy as np

2
print("image in pixels")

3
print(img)

4
print(img[0][0])

5
img[0,0]=135

6
print(img[0,0])

7
print("\n")

image in pixels

[[[ 90 139 189]

[ 91 138 189]

[ 96 141 192]

...
[224 214 207]

[223 212 208]

[219 210 201]]

[[ 92 140 188]

[ 94 141 192]

[ 94 141 193]

...
[226 217 208]

[226 214 210]

[222 210 204]]

[[ 96 141 192]

[100 145 196]

[100 145 196]

...
[227 219 212]

[226 215 211]

[224 212 206]]

...

[[ 42 86 139]

[ 44 86 133]

[ 42 89 140]

...
[154 163 190]

[154 161 186]

[153 161 184]]

[[ 43 95 148]

[ 37 83 137]

[ 36 82 136]

...
[152 166 189]

[152 166 188]

[155 169 191]]

[[ 41 100 150]

[ 40 93 144]

[ 35 83 135]

...
[160 173 195]

[162 176 195]

[154 168 186]]]

[ 90 139 189]

[135 135 135]

1
dim=img.shape

2
height=img.shape[0]

3
width=img.shape[1]

4
channel=img.shape[2]

5
size=img.size

6
print("dimensions :",dim)

7
print("height :",height)

8
print("width :",width)
9
print("channel: ",channel)

10
print("image size :",size)

dimensions : (317, 359, 3)

height : 317

width : 359

channel: 3

image size : 341409

1
b,r,g=cv2.split(img)

2
print("After splitting")

3
cv2_imshow(b)

4
cv2_imshow(r)

5
cv2_imshow(g)

6
img=cv2.merge((b,r,g))

After splitting

1
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

2
print("gray scale")

3
cv2_imshow(gray)

4
print("\n")

gray scale

1
h,w=img.shape[:2]

2
c=(w/2,h/2)

3
rotate_matrix=cv2.getRotationMatrix2D(center=c,angle=45,scale=1)

4
rotate_img=cv2.warpAffine(src=img,M=rotate_matrix,dsize=(w,h))
5
print("rotated matrix")

6
cv2_imshow(rotate_img)
7
print("\n")

rotated matrix

1
img2=cv2.merge((r,g,b))

2
print("after colour mixing")

3
cv2_imshow(img2)

4
print("\n")

after colour mixing

1
h,w=img.shape[:2]

2
dem=(int(h/3),int(w/3))

3
img1=cv2.resize(img,dem)

4
print("after resize")

5
cv2_imshow(img1)

6
print("\n")

after resize

You might also like