Help Please: Converting image into Black and white/Greyscale & Inverting it

Hi Everyone,

Basic idea is, I trained my MNIST dataset (Devnagri Script) (based on lesson 2). It doesn’t work well when testing with images having black text having white background.

So my objective is:

  1. I want to convert my FastAI Image into a black and white/greyscale
  2. Invert the colors (b/w)

I have looked for every forum and yet to figure out a solution.

I tried the convert_mod = ‘L’, however it doesn’t convert it to black and white.

img=open_image(“Img Path”,convert_mode=‘L’)
display(img)

Attaching the images before and after conversionScreenshot 2020-05-21 at 1.53.47 PM Screenshot 2020-05-22 at 2.02.55 AM

Lastly, I want the final file in the Fast AI Image format, and not PIL image or open CV, since I am not able to use those while deployong app on render.

Any and all help will be deeply appreciated.