Guns Germs And Steel
I’ve never been a big history fan. Too many names and dates to memorize. But now, free from the pressure of having to learn for the sake of getting good grad...
While working on the first part of my style-transfer project, I ran into lots of image issues. One of the issues was that cv2 uses a BGR channel order instead of RGB, the latter is more common. This resulted in a lot of my images seeming to have a weird tint. I talk about that here. This post will be focusing on a different issue I found while trying to solve the channel issue.
Before I found the correct fix, I did get desperate enough to try looking at some of the raw pixel values and found something very suprising: I was specifying a particular array to be saved but upon loading the saved image, the loaded array had different pixel values! To examine this effect, you can play with this notebook.
I found out that the whole time I was saving images with the .jpg extension, cv2 was carrying out JPEG compression on the array and saving the compressed array. So when it was loaded back in, the values would look extremely different!
There are two things to note here:
I found that PNG offered lossless compression and indeed if you look at the notebook and the values of the png image, they are almost the same as the original array. The difference comes about just from rounding floats to ints. Interestingly, the small differences do add up which you can see in the summed difference of arrays. However, the difference between the original image and the jpg one is 10x more than between the original image and the png one.
The takeaway here is to be aware that depending on the type of extension you choose to use with cv2.imwrite, you’ll end up with different arrays. I spent an embarrasingly large amount of time being baffled by why the arrays looked so different! Hopefully that doesn’t happen to you.
If you’d like to play around more, here’s a notebook for you to tinker with!
I’ve never been a big history fan. Too many names and dates to memorize. But now, free from the pressure of having to learn for the sake of getting good grad...
A little while ago, I read Letters from a Stoic by Seneca (translated and edited by Robin Campbell). I got a lot out of reading Letters and wanted to encoura...
I recently finished reading Every Tool’s a Hammer: Life Is What You Make It1 by Adam Savage. It was an energizing read and I highly recommend this book to fe...
CoordConv
Recently, I binged through the Culture series by Ian M. Banks. It was an amazing read and I thought a write up about it might help ground the experience and ...
I recently the following on Coursera: Learning How to Learn: Powerful mental tools to help you master tough subjects Mindshift: Break Through Obstacles ...
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
While working on the second part of my style-transfer project, I needed to obtain the shape of a tensor. I decided to try using the tf.shape function.
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
While working on the first part of my style-transfer project, I had: A new input variable which would have to be initialized from scratch. The VGG-19 ne...
While working on the first part of my style-transfer project, I found out the hard way that TF is very sensitive to the network’s input’s data type.
While working on the first part of my style-transfer project, I dealt with two main variable groups: The input variable which was the image I was optimizi...
While working on the first part of my style-transfer project, I used pyplot’s imshow to diplay images in the notebook. However, it took me a little bit of pl...
While working on the first part of my style-transfer project, I used Open CV’s cv2.imwrite to save images to disk. However, the images seemed to have a weird...
While working on the first part of my style-transfer project, I ran into lots of image issues. One of the issues was that cv2 uses a BGR channel order inste...
If you’re reading this, I’m assuming that you’ve read the paper Image Style Transfer Using Convolutional Neural Networks and have some familiarity with it.
Cue customary Hello World.