Apply Sepia Tone filter with OpenCV

Give your image a warm, vintage look by applying a sepia tone. We have used the NumPy library for this. Initially, we imported the numpy. After that set the array for the sepia filter and use the transform() function:

Let us see the example:

The following is the output:

Apply Sepia Tone filter with OpenCV
Explanation:

This Python script applies a sepia tone effect to an image using the OpenCV and NumPy libraries:

  • It starts by importing the necessary libraries.
  • The script then loads the input image from the specified file path into the variable image using OpenCV’s cv2.imread() function.
  • To create the sepia effect, it defines a 3×3 matrix called sepia_kernel, which contains specific weights for red, green, and blue color channels to mimic the warm tones of sepia.
  • The sepia filter is applied to the image using the cv2.transform() function, which applies the matrix transformation to the image and produces the modified sepia_image.
  • The processed image is then displayed in a window titled “Sepia Tone” using the cv2.imshow() function.
  • The script waits indefinitely for the user to press a key with cv2.waitKey(0) before closing all OpenCV windows via cv2.destroyAllWindows().
  • This workflow allows the user to view the sepia-toned image and close the display window when ready.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Set a Grayscale filter with OpenCV
Blur an image with OpenCV
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading