Similar presentations:
Digital Image Processing. Week 3
1.
Week 3Digital Image Processing
Dr. Sajid Khan
2.
Reading image using webcam• I will be playing with frames of my own face.
• I am not photogenic, however, I decided to sacrifice on that one.
3.
import cv2cam_port = 0 #port refers to the webcam. You may try with cam_port=1 if you have any other webcam
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
# showing result, it take frame name and image
# output
cv2.imshow("My image", image)
result, image = cam.read()
cv2.waitKey(1)
4.
5.
Flipping framesimport cv2
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
# showing result, it take frame name and image
# output
img_flip_lr = cv2.flip(image, 1)
cv2.imshow("My image", img_flip_lr)
result, image = cam.read()
cv2.waitKey(1)
6.
7.
Trying to neglect blue reflectionimport cv2
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_noBlue = image
image_noBlue[:,:,0] = 0
image_concat = cv2.hconcat([image, image_noBlue])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
8.
9.
Deep copy comes to the rescueimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_noBlue = copy.copy(image)
image_noBlue[:,:,0] = 0
image_concat = cv2.hconcat([image, image_noBlue])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
10.
11.
No green reflectionimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_noGreen = copy.copy(image)
image_noGreen[:,:,1] = 0
image_concat = cv2.hconcat([image, image_noGreen])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
12.
13.
Only Blue reflectionimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_onlyBlue = copy.copy(image)
image_onlyBlue[:,:,1:3] = 0
image_concat = cv2.hconcat([image, image_onlyBlue])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
14.
15.
import cv2import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_onlyGreen = copy.copy(image)
image_onlyGreen[:,:,0] = 0
image_onlyGreen[:,:,2] = 0
image_concat = cv2.vconcat([image, image_onlyGreen])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
16.
17.
18.
import cv2import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_onlyGreen = copy.copy(image)
image_onlyGreen[:,:,0] = 0
image_onlyGreen[:,:,2] = 0
image_onlyBlue = copy.copy(image)
image_onlyBlue[:,:,1:3] = 0
image_onlyRed = copy.copy(image)
image_onlyRed[:,:,0:2] = 0
image_concat = cv2.vconcat([cv2.hconcat([image, image_onlyGreen]),cv2.hconcat([image_onlyRed, image_onlyBlue])])
cv2.imshow('Processed frames', image_concat)
result, image = cam.read()
cv2.waitKey(1)
19.
Normalizing and multiplying imageimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# image_gray = cv2.normalize(image_gray, None, 0, 1, cv2.NORM_MINMAX, dtype=cv2.CV_32F)
image_gray = image_gray.astype(float) / 255
image_enhance = copy.copy(image_gray)
image_enhance = image_enhance*3
image_concat = cv2.hconcat([image_gray, image_enhance])
cv2.imshow('Processed frames', image_concat)
print(image_enhance)
result, image = cam.read()
cv2.waitKey(1)
20.
Taking square of the imageimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image_gray = image_gray.astype(float) / 255
image_enhance = copy.copy(image_gray)
image_enhance = image_enhance**2
image_concat = cv2.hconcat([image_gray, image_enhance])
cv2.imshow('Processed frames', image_concat)
print(image_enhance)
result, image = cam.read()
cv2.waitKey(1)
21.
22.
Taking cube of the imageimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image_gray = image_gray.astype(float) / 255
image_enhance = copy.copy(image_gray)
image_enhance = image_enhance**3
image_concat = cv2.hconcat([image_gray, image_enhance])
cv2.imshow('Processed frames', image_concat)
print(image_enhance)
result, image = cam.read()
cv2.waitKey(1)
23.
24.
Taking square rootimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image_gray = image_gray.astype(float) / 255
image_enhance = copy.copy(image_gray)
image_enhance = image_enhance**(1/2)
image_concat = cv2.hconcat([image_gray, image_enhance])
cv2.imshow('Processed frames', image_concat)
print(image_enhance)
result, image = cam.read()
cv2.waitKey(1)
25.
26.
Cube root27.
Image Negativeimport cv2
import copy
cam_port = 0
cam = cv2.VideoCapture(cam_port)
result, image = cam.read()
while result:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image_gray = image_gray.astype(float) / 255
image_enhance = copy.copy(image_gray)
image_enhance = 1 - image_enhance
image_concat = cv2.hconcat([image_gray, image_enhance])
cv2.imshow('Processed frames', image_concat)
print(image_enhance)
result, image = cam.read()
cv2.waitKey(1)