Skip to content

Instantly share code, notes, and snippets.

@ChongyeWang
Created March 15, 2019 06:04
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 ChongyeWang/4337e0c134ea36eb2fb2e1d390d68d6d to your computer and use it in GitHub Desktop.
Save ChongyeWang/4337e0c134ea36eb2fb2e1d390d68d6d to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
image = cv2.imread('images/input.jpg')
# Create a matrix of ones, then multiply it by a scaler of 100
# This gives a matrix with same dimesions of our image with all values being 100
M = np.ones(image.shape, dtype = "uint8") * 175
# We use this to add this matrix M, to our image
# Notice the increase in brightness
added = cv2.add(image, M)
cv2.imshow("Added", added)
# Likewise we can also subtract
# Notice the decrease in brightness
subtracted = cv2.subtract(image, M)
cv2.imshow("Subtracted", subtracted)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment