Add a Color Tint with OpenCV

With OpenCV, easily add a color tint (e.g., blue or red) to the image. We will create a blue tint here. Set the red and green channels to 0 for the blue-tint array:

Let us see an example of adding a color tint to an image:

The following is the output:

Add a blue color tint with OpenCV
Explanation:

This Python script demonstrates how to use OpenCV to load an image, apply a blue tint to it, and display the result:

  • The script begins by importing OpenCV and loading an image from the specified file path into the variable image using the cv2.imread() function.
  • To create a blue tint effect, the script first makes a copy of the loaded image and assigns it to the variable blue_tint.
  • Then, it sets the green and red color channels of the copied image to 0, effectively removing those colors. This is achieved by modifying the array representing the image: blue_tint[:, :, 1] = 0 sets the green channel to zero, and blue_tint[:, :, 2] = 0 sets the red channel to zero, leaving only the blue channel active.
  • The resulting image, now tinted blue, is displayed in a window titled “Blue Tint Filter” using the cv2.imshow() function.
  • The script waits for a key press with cv2.waitKey(0) before closing the display window using cv2.destroyAllWindows(). This approach allows users to visualize the applied blue tint effect interactively.

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:

Edge Detection with OpenCV
What Are Instagram Filters
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