Skip to content

Instantly share code, notes, and snippets.

@j-medland
Last active July 25, 2022 21:10
Show Gist options
  • Save j-medland/2268dc11f64deb0daa4d415c96f27233 to your computer and use it in GitHub Desktop.
Save j-medland/2268dc11f64deb0daa4d415c96f27233 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
def threshold(data):
gray = np.array(data,dtype=np.uint8)
# perform threshold operation
ret, thresh1 = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
#
# create an RGB image to demonstrate output
#
height = 200
width = 300
rgb = np.zeros((height,width,3), np.uint8)
# create RGB verticle stripes
# note cv2 channels are arranged BGR
# red stripe
rgb[:,0:width//3] = (0,0,255)
# green stripe
rgb[:,width//3:2*width//3] = (0,255,0)
# blue stripe
rgb[:,2*width//3:width] = (255,0,0)
# return rgb 3d-array
return rgb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment