Created
September 11, 2019 08:56
-
-
Save sjaustirni/260f57ff7ee75d990740e12cd7b5c105 to your computer and use it in GitHub Desktop.
MED3 Point Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
# The RGB image array | |
input_image = cv2.imread('lion.jpg') | |
def show_image(image, source): | |
cv2.imshow(source, image) | |
def loop(image): | |
width = image.shape[0] | |
height = image.shape[1] | |
blank_image = np.zeros((width, height, 3), np.uint8) | |
for i in range(width): | |
for j in range(height): | |
b, g, r = [int(el) for el in image[i, j]] | |
blank_image[i, j] = (r + g + b) / 3 | |
return blank_image | |
def matrix(image): | |
w = np.array([[[0.33, 0.33, 0.33]]]) | |
return cv2.convertScaleAbs(np.sum(image * w, axis=2)) | |
def opencv(image): | |
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
show_image(loop(input_image), "loop") | |
show_image(matrix(input_image), "matrix") | |
show_image(opencv(input_image), "opencv") | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment