Skip to content

Instantly share code, notes, and snippets.

@sjaustirni
Created September 11, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjaustirni/260f57ff7ee75d990740e12cd7b5c105 to your computer and use it in GitHub Desktop.
Save sjaustirni/260f57ff7ee75d990740e12cd7b5c105 to your computer and use it in GitHub Desktop.
MED3 Point Processing
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