Skip to content

Instantly share code, notes, and snippets.

@FilipeChagasDev
Last active February 8, 2024 14:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FilipeChagasDev/bb63f46278ecb4ffe5429a84926ff812 to your computer and use it in GitHub Desktop.
Save FilipeChagasDev/bb63f46278ecb4ffe5429a84926ff812 to your computer and use it in GitHub Desktop.
Applies the "sepia" effect to an image using OpenCV and Numpy
# Author: Filipe Chagas
# Email: filipe.ferraz0@gmail.com
# Github profile: github.com/FilipeChagasDev
# Description: Applies the "sepia" effect to an image using OpenCV and Numpy
import numpy as np
import cv2
def sepia(src_image):
gray = cv2.cvtColor(src_image, cv2.COLOR_BGR2GRAY)
normalized_gray = np.array(gray, np.float32)/255
#solid color
sepia = np.ones(src_image.shape)
sepia[:,:,0] *= 153 #B
sepia[:,:,1] *= 204 #G
sepia[:,:,2] *= 255 #R
#hadamard
sepia[:,:,0] *= normalized_gray #B
sepia[:,:,1] *= normalized_gray #G
sepia[:,:,2] *= normalized_gray #R
return np.array(sepia, np.uint8)
image = cv2.imread(raw_input('source filename: '))
image2 = sepia(image)
cv2.imshow('', image2)
cv2.waitKey()
@burnfire123
Copy link

Thank you for your code!

@bartoalheiros
Copy link

Valeu, Filipe, me ajudou num trabalho da faculdade!

@otaviokamel
Copy link

Thank you!

@rtessler
Copy link

rtessler commented Feb 8, 2024

the generated images look great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment