IR photos with the Boscam HD19, part 1

IR photos with the Boscam HD19, part 1

On my multicopter, I have a Boscam HD19 camera. This camera was explicitely developed for use on UAVs and has some interesting functions, like live video out, full HD recording and taking photos. The recording functions can also be controlled via the UAV’s remote control, which makes it especially useful. The stock lens is very wide-angeled and - in my opinion - not of excessively good quality. Fortunately, the HD19 uses a standard 12x0,5mm thread for lenses and good but cheap lenses in various angles are available from the internet.

As of all digital cameras, the sensor of the HD 19 is also sensitive to infrared light. However, the HD19’s stock lens has an IR-cut filter because IR light is very prominent in the light spectrum and would otherwise cause the picture’s colors to be distorted.

So, to get infrared light, we either have to remove the IR-cut filter from the stock lens or get a lens without filter. As I didn’t like the wide angle of the stock lens and I had some problems with unsharp edges, I decided to buy a 6mm lens on eBay for about 6€ incl. shipping. It is noticeable that the HD19 has a 1/2.5” sensor. Most cheap CCD and CMOS cameras with M12 lenses have 1/3” or 1/4” lenses which leads to a small tunnel effect on photos with the HD19. Thus, only lenses for 1/2.5” sensors should be used. Those lenses are also often called “HD” or “3 Megapixel / 3MP lenses”.

After replacing the lens, the images look like the one to the right (click picture to enlarge). Colors don’t seem to match, especially colors of plants, and the whole picture is tinted red/pink. That is pretty much how it is supposed to look like. The automatic white balance function of digital cameras is calibrated for the visible light spectrum only. IR light throws it off very much and generally, the IR part is very strong on the general spectrum. IR light has a longer wavelength and thus penetrates e.g. fog or clouds much better. This photo was taken at 9 in the evening on a cloudy day, but it’s still very bright. As for the plants, the foliage of a living plant reflects IR light very well. That’s why plants appear very bright in an IR picture. IR reflectivity is also a good indicator of a plant’s health.

But of course, we don’t want all pink pictures, hence we have to do a bit of postprocessing. I use GIMP for postprocessing of photos. The necessary functions are also available in other programs, like Adobe Photoshop. The easiest way to get reasonably good pictures is to use the automatic white balance function of GIMP (menu Colors -> Auto -> White Balance). This already gives a nice result but it’s still very pinkish (see left, click to enlarge). To get better results, we still have to do some corrections and those are best done with color curves (menu Colors -> Curves). Select the Red channel and try to lower the level around 100-120 a bit.

After correcting the Red channel and a tiny little bit also Green and Blue channels, the result is pretty ok (see right, click to enlarge). During the postprocessing, we lose a bit of dynamic range (compare e.g. the door of the black car left of the image’s center), but the normal colors are almost totally correct now. Vegetation still is a bit pinkish but that is not easy to correct without losing a big amount of dynamic range and contrast in the process.

To make things easier, I have written a small Scheme script for GIMP which does the correction automatically. /see below)

Part 2 will cover postprocessing of images which were taken with an IR-passthrough filter.

;
; IR photo postprocessing
;
; Correct colors in photos without IR-cut lens and swap red and blue
; channels in photos with IR passthrough filter.
;
; Stefan Gofferje (stefan@gofferje.net)
; (C) 2013, Valkeakoski, Finland
;
; This script was tested with Gimp 2.8
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
; 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with this program; if not, see <http://www.gnu.org/licenses>.
;
; Define the function
;

(define (script-fu-SGO-IRpostproc InImage InLayer InSwitchRB)
;
; Save history          
;
    (gimp-image-undo-group-start InImage)
;
    (let*   (
            (SwitchLayer (car (gimp-layer-copy InLayer TRUE)))
        )
        (gimp-image-insert-layer InImage SwitchLayer 0 -1)

        (cond
            (
                (= InSwitchRB FALSE)
                ;auto white-balance
                (gimp-levels-stretch SwitchLayer)
                ;correct more
                    (gimp-curves-spline SwitchLayer HISTOGRAM-RED 6 #(0 0 105 45 255 255))
                    (gimp-curves-spline SwitchLayer HISTOGRAM-GREEN 6 #(0 0 100 105 255 255))
                    (gimp-curves-spline SwitchLayer HISTOGRAM-BLUE 6 #(0 0 90 95 255 255))
                ;remove cyan component
                (gimp-hue-saturation SwitchLayer 4 0 0 -100)
            )
        )

        (cond
            (
                (= InSwitchRB TRUE)
                (let*   (
                        (RGBImage (car (plug-in-decompose TRUE InImage SwitchLayer "RGB" TRUE)))
                        (RGBLayer (cadr (gimp-image-get-layers RGBImage)))
                        (CompImage (car (plug-in-drawable-compose TRUE RGBImage (aref RGBLayer 2) (aref RGBLayer 1) (aref RGBLayer 0) -1 "RGB")))
                        (CompLayer (cadr (gimp-image-get-layers CompImage)))
                    )
                    (gimp-selection-all CompImage)
                    (gimp-edit-copy (aref CompLayer 0))
                    (gimp-floating-sel-anchor (car (gimp-edit-paste SwitchLayer FALSE)))
                    (gimp-image-delete CompImage)
                    (gimp-image-delete RGBImage)

                )
            )
        )
    )

;
; Finish work
;
    (gimp-image-undo-group-end InImage)
    (gimp-displays-flush)
;
)
;
(script-fu-register 
    "script-fu-SGO-IRpostproc"
    _"Infrared _Postprocessing"
    "Do some postprocessing on IR images"
    "Stefan Gofferje (stefan@gofferje.net)"
    "Stefan Gofferje, Valkeakoski, Finland"
    "10.08.2013"
    "RGB*"
    SF-IMAGE    "The Image"     0
    SF-DRAWABLE "The Layer"     0
    SF-TOGGLE   "Image was taken with IR passthrough filter"    FALSE
)
;
(script-fu-menu-register "script-fu-SGO-IRpostproc"
                "<Image>/Filters/SGO")
;