Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Correcting image white balance with Python PIL and Numpy

I started writing another blog post about my new keyboard today, and when uploading the unboxing video to my YouTube channel, I realized they have no “auto white balance” option, not in their new or old video editor either. Shoot. After googling for free video editors, I settled on OpenShot.

And guess what? OpenShot doesn’t have a white balance setting either! The author himself said this on Reddit, asking for help to Implement it. I was pretty shocked, as it seems like the first filter I would implement myself, and thought “surely it doesn’t take more than five minutes to implement one, right?”. So I did. Well, it took maybe 15 minutes, plus 45 fiddling with Jupyter notebooks to get PIL and numpy commands right.

The Python 3 code above basically loads an image (either local if you run it with Jupyter notebook locally, or over network), get a small subportion of it to act as a grey reference, and adjusts color channel balance with two alternate methods: RGB or YCbCr. More advanced versions should be easy to add as well.

You can view the above gist in Github or just copy-paste the code to your own / cloud based notebook to try it out:

https://gist.github.com/jokkebk/7a0feab274356768b515db6b05f124bf

If you don’t have access to anything that can run a ipynb file, you can just take a look at the PDF version of a sample run. Enjoy!



This post first appeared on Code And Life – Programming, Electronics And Oth, please read the originial post: here

Share the post

Correcting image white balance with Python PIL and Numpy

×

Subscribe to Code And Life – Programming, Electronics And Oth

Get updates delivered right to your inbox!

Thank you for your subscription

×