"False Colour" NIR Images, First Attempts with Python.

This is a very brief post outlining initial experiments I've been doing with creating 'false colour' images from NIR/VIS shots I've been taking lately.

First, let me explain. I happen to have a Canon EOS that has been modified to remove the "hot mirror", or "IR blocking filter", allowing its sensor to pick up IR/NIR light - basically, it can shoot in infrared.

Most importantly - it does not have an "IR only" filter installed, which would block the visible spectrum of light. I can choose to install that on the lens if I see fit. For this experiment, I didn't bother.

Anyway, here is a photo taken in "(almost) full spectrum" (Visible + NIR/IR - I can't capture UV... yet).

fullspectrum cat.

As you can see, the NIR really hammers the red levels in the image, giving it kind of a washed out look. You can really see this in the spectrum in Rawtherapee.

look at that red peak.

Now, what a lot of folks do is flip the red and blue channels in the image, to give a "false colour" image that looks really quite good. It looks even better when you use photos taken with a IR only filter, but I'll post an update next week when I get to trying that out.

Flipping the channels can be done in Lightroom or whatever, but honestly, it takes me ages, I hate using image editing software with a passion, and I figured I could google some stackoverflow nonsense and write a short Python script to automate it for me.

This is pretty much the simplest implementation of "swap red and blue channels". There are likely other postprocessing steps that are worth doing, and it probably won't work on raw's. I'll deal with that later.

import cv2
from PIL import Image
import sys
def main():
    if len(sys.argv) != 2:
        sys.exit("use: script.py image.jpg")
    image = sys.argv[1]
    image = cv2.imread(image) # open image
    image = image[:, :, ::-1] # flip red and blue chans
    saveas = 'flipped_%s' %(sys.argv[1])
    print(saveas)
    cv2.imwrite(saveas, image) # save image.

if __name__ == "__main__":
    main()
flip.py

Here is the output image.

cat - inverted red and blue channels.

Honestly, I like it. It gave me exactly what I expected it to.

I'll post more tests next week after I take the camera for an outing with an IR only filter onboard.