Skip to content
Advertisement

How to inverse the rgb image color from “white-black” to “black-white” in matplotlib

The following two images are from the Mnist dataset.

The image_7 is a gray image with shape (28, 28) while image_2 is (28, 28, 3).

I want to inverse the image colors and display it in the matplotlib.

JavaScript

enter image description here

As you can see, the second image is inversed.

But how to inverse the fourth image from “white-black” to “black-white“.

Advertisement

Answer

A tilde operator can do your task:

JavaScript

inverted_image

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement