enhancement: extract binary data from FLIR radiometric jpg

Started by tomas123, March 20, 2013, 12:49:46 PM

Previous topic - Next topic

Phil Harvey

Hi Hans,

You can extract the raw thermal image as binary data using ExifTool:

exiftool -rawthermalimage -b test1.jpg > out.dat

But that is as far as ExifTool goes.  There are scripts posted here that convert the raw data to temperatures, and they could probably be modified to output CSV format, but it would take some programming skill.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

hansss

Hi Phil,

Thank you for making such a great tool and giving me hope!

Thank you for the command:

exiftool -rawthermalimage -b test1.jpg > out.dat

I tried it and it does extract an image that I can open as a png.

One question:

Tomas123 in one post in this thread got these results using FLIR.pm

RAW    Grad Celsius
0   -40,011
18498   25,791
18598   26,319
18722   26,969
18861   27,694
18980   28,311
19080   28,826
19180   29,34

Is it possible get similar info from test1.jpg using exiftool?

Hans
Zurich

Phil Harvey

Hi Hans,

Sorry, no.  ExifTool doesn't do manipulations with the raw thermal data.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

hansss

Hi Phil,

Thank you very much for your response. I have downloaded perl for windows and will experiment with FLIR.pm in order to try to extract these values:


RAW    Grad Celsius
0   -40,011
18498   25,791
18598   26,319
18722   26,969
18861   27,694
18980   28,311

Hans
Zurich

tomas123

sorry for my late response

the flir i3 has a changed byte order

see sample code here for expanding raw datas from flir image and calculating the temperature from a raw value (draw a temperature scale)
https://exiftool.org/forum/index.php/topic,4898.msg24230.html#msg24230

expand raw data with
$ exiftool -b -RawThermalImage test1.jpg | convert - gray:- | convert -depth 16 -endian msb -size 60x60 gray:- raw.png

you can preview your result with
$ convert raw.png -auto-level myfoot.jpg

now expand the raw values to a text file
$ convert raw.png  -compress none raw.pgm

open raw.pgm with a text editor (see: http://en.wikipedia.org/wiki/Netpbm_format )
P2
60 60
65535
12781 12789 12789 12784 12779 12786 12781 12788 12777 12787 12792 12783 12781
12791 12783 12778 12782 12775 12778 12781 12773 12774 12772 12786 12780 12782
12769 12785 12780 12792 12797 12780 12785 12785 12772 12781 12778 12789 12778
12781 12780 12777 12776 12787 12774 12787 12773 12779 12779 12785 12782 12786
12787 12772 12779 12789 12788 12786 12775 12777 12785 12778 12778 12781 12786
12788 12780 12775 12788 12779 12785 12774 12781 12783 12782 12783 12780 12787
12780 12773 12781 12777 12785 12773 12780 12781 12788 12783 12783 12793 12787


now you can simple calculate with excel (or a small script for batch processing) the temperature of every point:
your values are:

$ exiftool -Pl* test1.jpg
Planck R1                       : 14145.437
Planck B                        : 1381.9
Planck F                        : 1.35
Planck O                        : -6635
Planck R2                       : 0.022316413


see formulas and theory
https://exiftool.org/forum/index.php/topic,4898.msg23972.html#msg23972



hansss

Hi  Tomas,

THANK YOU very much for your kind support!!  I look forward to trying this out!

hans
zurich

Alexgm

I'm working on a website where among other things, I can load an image, in my case from the Flir E40, and point at different parts of the image and see the temperature.
And I just finished (yea!!!) a bash/awk script to generate a file that contains a matrix with all the temperatures on any given image that I can then use on the site.
So, first I want to thank Phil Harvey for the amazing ExifTool and also Tomas123 for all his great posts for doing this -- you guys are awesome!
Also I found a very slight difference, of between 0.07 and 0.08 degrees Celsius higher, between the temperatures generated by Tomas123's scripts and the temperatures generated by Flir's QuickReport tool.
It doesn't make any difference to my project but I just wanted to share that.
Thanks for all the great work!
-- Alex

tomas123

Quote from: tomas123 on April 18, 2013, 05:23:46 PM

I ignore the Emission of atmosphera. The influence is low by short distance. The calculation effort is high (distance, humidity).
Our calculated temperature is 100% identical with Flir temperature if you set the object distance to zero and let external optics transmission by 1.0!!

read my full post for more informations about calculation

and this
https://exiftool.org/forum/index.php/topic,4898.msg24310.html#msg24310

emiliozb

Phil and Tomas123, great work.

Should I use the Reflected Apparent Temperature for the T_refl on your formula?

Thanks,
E.

tomas123

Answer: yes

I think you mean T_refl from this post
https://exiftool.org/forum/index.php/topic,4898.msg23972.html#msg23972

see this post for a code sample (php)
Quote from: tomas123 on May 14, 2013, 04:03:02 PM
Options Summary:
--tref temp         overwrite embedded Reflected Apparent Temperature (degree Celsius)


filippo

Good morning everybody,
I'm new to this conversation (and to this forum too)... first I would like to do many compliments to tomas123 for his work.
I was trying to rewrite the original script from tomas123 in Python, just to extract raw thermal data from a jpg image coming from a FLIR camera, exiftool doesn't work with my images and so I decided to try this way.
I followed step-by step your reverse-engineering work, all seems to be similar in my picture except to the fact that I cannot find a segment with size equal to the image size computed from sensor dimensions (w*h*2+32).
My camera is the FLIR B335 one, I attached to this message a picture taken with this camera, can you suggest me a solution to properly extract raw thermal data?
Thank you a lot, regards

Phil Harvey

Quote from: filippo on November 07, 2013, 11:08:45 AM
just to extract raw thermal data from a jpg image coming from a FLIR camera, exiftool doesn't work with my images

Thanks for the sample.

I can extract the raw thermal PNG image just fine from the sample you posted:

exiftool FLIR_B335.jpg -rawthermalimage -b > out.png

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

tomas123

#102
Quote from: filippo on November 07, 2013, 11:08:45 AM
exiftool doesn't work with my images and so I decided to try this way.
no - exiftool works fine

you png has a reverse byte order
change it with imagemagick convert
>exiftool FLIR_B335.jpg -b -RawThermalImage | convert.exe - gray:- | convert.exe -depth 16 -endian msb -size 320x240 gray:- -auto-level out.png

my php script from this post
https://exiftool.org/forum/index.php/topic,4898.msg24230.html#msg24230
make all necessary steps (extract real image, IR image and color palette)

>php flir.php --pip -i FLIR_B335.jpg -o x6.jpg

Reflected Apparent Temperature: 20.0 degree Celsius
Emissivity: 0.95
Plancks values: 15076.116 0.010758856 1399.9 -6029 1

RAW Temp Range FLIR setting: 19240 21208
RAW Temp Range select      : 19240 21208
RAW reflected: 17949
RAW Temp Range from sensor : 19221 21214
wrote "x6.jpg" with Temp-Range: 26.7 / 36.2 degree Celsius


compare x6.jpg  with your image (doupled sized real and IR image)

filippo

Hi Tomas and Phil,
thank you a lot for your explanation, I was just wrong using exiftool...

Now I obtained my thermal image but I would like to have it in false color. I try to explain my procedure step by step!

First I took out the full embedded visible image:

exiftool FLIR_B335.jpg -b -EmbeddedImage | convert -  -set colorspace YCbCr -colorspace RGB FLIR_B335full.jpg

Then I took out the palette (NB: I'm not sure about this step for 2 reasons: first I obtain an inverted palette, as you will see in the follow... I resolved this with a very stupid trick rotating palette but I think this is not a good idea and also the color of resulting thermal color image seem to be "compressed" in a tighter dinamic compared with the color thermal image of the original FLIR format):

exiftool FLIR_B335.jpg -b -Palette | convert -size 224X1 -depth 8 YCbCr:- -separate -swap 1,2 -set colorspace YCbCr -combine -colorspace RGB palette.png

Now I took out the raw thermal image; before I read the radiometric EXIF data to compute the temperature range:

exiftool FLIR_B335.jpg -raw*

   Raw Value Median                : 20224
   Raw Value Range                 : 1968
   ...

So:
   min temperature: 20224-1968/2=19240
   max temperature: 20224+1968/2=21208

And:

exiftool FLIR_B335.jpg -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian msb -size 320x240 gray:- -level 21208,19240 rawThermal.png

Finally I applyied the palette to the thermal image:

convert rawThermal.png palette.png -clut colorThermal.png

Now, as you can see, colors in colorThermal image are inverted.
As you told before, if I just rotate the palette (it's a stupid way, I know...) and I apply new palette to raw thermal image I obtain something similar to the desired result:

convert palette.png -rotate 180 paletteRotated.png
convert rawThermal.png paletteRotated.png -clut colorThermal2.png

Resulting image is near to what I expected to obtain but, as I told before, the color dynamic seems to be not correct... can you help me to understand where I'm wrong? I think I'm doing just something stupid, I'm sorry, but I'm not an expert in image processing :( .

I attached all images  in an archive to this message, thank you all a lot!!!

tomas123

#104
hi filippo,

this not not a imagemagick forum. Phil supports only questions to exiftool ;-)

But I don't know a better forum for your problem :-(

As you can see in my post above (image x6.jpg) my php script makes all required steps for converting the RAW image to a false color image.
The result is near original flir. You can't get 100% original. Compare Camera Image, Flir Tools and Flir Quickreport - there are also differences.

read the script step by step with my comments until end !!


some hints for better results:

the Flir palette is a Video PAL with level 16 to 235 (see comment line 172 in script, try sRGB and RGB - ImageMagick was modified as of version 6.7.7-8 )
use -auto-level for better results ( jpg level is 0-255)

from this post https://exiftool.org/forum/index.php/topic,4898.msg24230.html#msg24230 you can download more palettes

use imagemagick mathematics for converting the non linear raw image to the linear temperature scale (line 234 from my script)
http://www.imagemagick.org/Usage/compose/#mathematics

if you use windows you find here text files with the color values of palettes
C:\ProgramData\FLIR Systems\Palettes