Click here to Skip to main content
15,881,455 members
Articles / Desktop Programming / QT
Tip/Trick

Extracting RAW Images from Flir JPEG on Linux

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Oct 2017MIT 16K   2   2
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:

C++
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:

C++
#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();
}

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionI try to use this code Pin
Member 1395764022-Aug-18 1:05
Member 1395764022-Aug-18 1:05 
PraiseThank you Pin
Member 1347992222-Oct-17 22:56
Member 1347992222-Oct-17 22:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.