65.9K
CodeProject is changing. Read more.
Home

Extracting RAW Images from Flir JPEG on Linux

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Oct 20, 2017

MIT
viewsIcon

16503

This article describes how to extract RAW image information from Thermal Flir JPEG images

Introduction

Many Flir tools output a JPEG file with information encoded in the EXIF format within the JPEG file. For processing these files, it is needed to extract RAW data from these files and then start creating algorithms that make use of this data.

Since Flir do not provide an opensource tool for extracting this data from their JPEG files, I have found a quick way of doing that and I'm sharing this with everyone in the hope that it can be useful for humanity.

Printing EXIF Information from Flir JPEG File

There is a tool in Ubuntu repository, called exiftool that can read EXIF header from multiple file formats.

If you need a Flir JPEG file example, you can download one here:

Then, by using exiftool with the following parameters, you are able to see every relevant field in the file in the JSON format:

exiftool -j -b /tmp/Man_in_water_-_IR_image.jpg

Now it is just a matter of saving the RawThermalImage field in a TIFF file.

For that, I've written a simple Qt tool as follows:

#include <iostream>
#include <QProcess>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>

int main(int argc, char** argv)
{
    QString filepath(argv[1]);

    QProcess exiftoolProcess;
    exiftoolProcess.start("exiftool", QStringList() << "-j" << "-b" << filepath);
    if(!exiftoolProcess.waitForFinished(100000))
    {
        qInfo() << "exiftool timed out";
    }

    QByteArray data = exiftoolProcess.readAllStandardOutput();
    QJsonDocument exiftoolDoc = QJsonDocument::fromJson(data);

    QJsonArray dataArray = exiftoolDoc.array();
    
    QJsonValue value = dataArray[0];

    QJsonObject obj = value.toObject();

    qInfo() << obj.keys();
    
    int width = obj["RawThermalImageWidth"].toDouble();
    int height = obj["RawThermalImageHeight"].toDouble();

    qInfo() << "Resolution: " << width << "x" << height;
    
    QString imgBase64Str = obj["RawThermalImage"].toString();
    imgBase64Str.remove(0,7);

    QByteArray image = QByteArray::fromBase64(imgBase64Str.toLocal8Bit());

    qInfo() << image.size();

    QFile file("./output.tif");
    file.open(QIODevice::WriteOnly);
    file.write(image);
    file.close();
}