This week we performed further image manipulation in the form of adding, circles and lines and borders on images loaded into OpenCV. We also looked into Threholding and were introduced to the Histogram in relation to image Processing.
Code for the lab tasks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 1. Open a user-selected image; # 2. Show this image on the screen; # 3. Capture the user’s click on the image; import numpy as np import cv2 from matplotlib import pyplot as plt from matplotlib import image as image import easygui I = cv2.imread("colors.jpg") Original = I.copy() def draw(event,x,y,flags,param): if event == cv2.EVENT_LBUTTONDOWN: cv2.circle(img = I, center = (x,y),radius = 5, color = (255,255,255), thickness = -1) cv2.imshow("image", I) cv2.namedWindow("image") cv2.setMouseCallback("image", draw) cv2.imshow("image", I) key = cv2.waitKey(0) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 4. Draw a 201 x 201, 5-pixel thick red square around this location; # 5. Convert the pixels within the square to YUV. import numpy as np import cv2 from matplotlib import pyplot as plt from matplotlib import image as image import easygui I = cv2.imread("colors.jpg") YUV = cv2.cvtColor(I, cv2.COLOR_BGR2YUV) cv2.rectangle(img = I, pt1 = (4,4), pt2 = (270,177), color = (0,0,255), thickness = 10) cv2.imshow("image", I) key = cv2.waitKey(0) |