An open API service indexing awesome lists of open source software.

https://github.com/gtatters/thermimagebash

Command line tools for converting FLIR thermal image files
https://github.com/gtatters/thermimagebash

Last synced: 2 months ago
JSON representation

Command line tools for converting FLIR thermal image files

Awesome Lists containing this project

README

        

---
title: "Command Line Instructions for Converting FLIR Video and JPG files for import to ImageJ"
output: github_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

These instructions are for converting certain flir file types using command line tools. Variants of these functions are also incorporated into the Thermimage package through the functions, convertflirJPG(), converflirVID(), and ffmpegcall(). If these functions are not working in R, try following the command line instructions here to diagnose your system.

### System Requirements

Exiftool: https://www.sno.phy.queensu.ca/~phil/exiftool/

Imagemagick: https://www.imagemagick.org/script/index.php

Perl: https://www.perl.org/get.html

### Download and extract sample files to SampleFLIR folder on desktop:
https://github.com/gtatters/ThermImageJ/blob/master/SampleFLIR.zip

```{bash}
cd ~/IRconvert/SampleFLIR
ls
```

### Download and extract this perl script (split.pl) to a scripts folder in an IRconvert folder:
https://github.com/gtatters/ThermimageBash/blob/master/Uploads/split.pl

```{bash}
cd ~/IRconvert/scripts
ls
```

### Workflow to convert csq (1024x768) to avi file

1. Break video into .fff files into a temp/ subfolder
2. Extract times from each frame (this is optional but allows a quick check that the fff files are valid).
3. Put raw thermal data from fff into one thermalvid.raw file in temp folder.
4. Break thermalvid.raw video from .CSQ file into .jpegls files into temp folder.
5. Convert all jpegls files into avi file.
-----Use -codec png for compatibility, -codec jpegls for greater compression.
-----Use -pix_fmt gray16be for big endian export format, -pix_fmt gray16le for little endian format.
-----Use -f image2 -codec png to export a series of PNG files instead of an avi.
6. Import avi into ImageJ using File->Import->Movie(ffmpeg) import routine.
-----Import png files into ImageJ using File->Import->Image Sequence

```{bash}
cd ~/IRconvert
perl -f ~/IRconvert/scripts/split.pl -i ~/IRconvert/SampleFLIR/SampleFLIR.csq -o temp -b frame -p fff -x fff
ls temp
rm temp/frame00008.fff # remove 8th frame - due to file corruption
echo

exiftool -DateTimeOriginal temp/*.fff
exiftool -b -RawThermalImage temp/*.fff > temp/thermalvid.raw
ls temp/*.raw
echo

perl ~/IRconvert/scripts/split.pl -i temp/thermalvid.raw -o temp -b frame -p jpegls -x jpegls
ls temp/*.jpegls
echo

cd ~/IRconvert/SampleFLIR
ffmpeg -f image2 -vcodec jpegls -r 30 -s 1024x768 -i ~/IRconvert/temp/frame%05d.jpegls -pix_fmt gray16be -vcodec jpegls -s 1024x768 CSQconverted.avi -y
echo

ffmpeg -f image2 -vcodec jpegls -r 30 -s 1024x768 -i ~/IRconvert/temp/frame%05d.jpegls -f image2 -pix_fmt gray16be -vcodec png -s 1024x768 output/frame%05d.png -y

ls output/*.avi
ls output/*.png
cd ~/IRconvert
rm -r temp
```

Which produces the following output:

https://github.com/gtatters/ThermimageBash/blob/master/Uploads/CSQconverted.avi?raw=true

The above avi should open up in VLC player, but may or may not play properly. In ImageJ, with the ffmpeg plugin installed, the jpegls compression should work.

The above PNG file is a sample image of the 16 bit grayscale image. Although it looks washed out, it can be imported into ImageJ and the Brightness/Contrast changed for optimal viewing.

### Workflow to convert seq (640x480) to avi file

1. Break video into .fff files into temp/ subfolder.
2. Extract times from each frame (this is optional but allows a quick check that the fff files are valid).
3. Put raw thermal data from fff into one thermalvid.raw file in temp folder.
4. Break thermalvid.raw video from .CSQ file into .tiff files into temp folder.
5. Convert all tiff files into avi file.
6. Convert all jpegls files into avi file.
----- Use -codec png for compatibility, -codec jpegls for greater compression.
------Use -pix_fmt gray16be for big endian export format, -pix_fmt gray16le for little endian format.
7. Import avi into ImageJ using File->Import->Movie(ffmpeg) import routine.

```{bash}
cd ~/IRconvert
perl -f ~/IRconvert/scripts/split.pl -i ~/IRconvert/SampleFLIR/SampleFLIR.seq -o temp -b frame -p fff -x fff
ls temp
echo

exiftool -DateTimeOriginal temp/*.fff
exiftool -b -RawThermalImage temp/*.fff > temp/thermalvid.raw
ls temp/*.raw
echo

perl ~/IRconvert/scripts/split.pl -i temp/thermalvid.raw -o temp -b frame -p tiff -x tiff
ls temp/*tiff
echo

cd ~/IRconvert/SampleFLIR
ffmpeg -f image2 -vcodec tiff -r 30 -s 640x480 -i ~/IRconvert/temp/frame%05d.tiff -pix_fmt gray16be -vcodec jpegls -s 640x480 SEQconvertedjpegls.avi -y

ffmpeg -f image2 -vcodec tiff -r 30 -s 640x480 -i ~/IRconvert/temp/frame%05d.tiff -pix_fmt gray16be -vcodec png -s 640x480 SEQconvertedpng.avi -y
echo

ls output/*.avi
cd ~/IRconvert
rm -r temp
```

Which produces the following output:

https://github.com/gtatters/ThermimageBash/blob/master/Uploads/SEQconvertedjpegls.avi?raw=true

https://github.com/gtatters/ThermimageBash/blob/master/Uploads/SEQconvertedpng.avi?raw=true

Note: the above avi should open up in VLC player, but may or may not play properly. In ImageJ, with the ffmpeg plugin installed, the jpegls compression should work.

### Workflow to convert FLIR jpg (640x480) to png file

1. Use exiftool to extract RawThermalImage from the FLIR jpg.
2. Pass the raw thermal image data to imagemagick's convert function to convert to 16 bi grayscale with little endian
3. Convert to PNG (PNG is lossless, compressed, and easiest).
--- Save to different filetype (tiff, bmp, or jpg) as needed (not recommended for further analysis).
4. Use exiftool to extract calibration constants from file (for use in converting raw values)

```{bash}
cd ~/IRconvert/SampleFLIR
exiftool ~/IRconvert/SampleFLIR/SampleFLIR.jpg -b -RawThermalImage | convert - gray:- | convert -depth 16 -endian lsb -size 640x480 gray:- output/JPGconverted.png

exiftool ~/IRconvert/SampleFLIR/SampleFLIR.jpg -*Planck*
```

### Workflow to convert FLIR jpg multi-burst (with ultramax) to png file
Note: this section is a work in progress. Code below is not yet functional, but saved here for reference.

Extract the multiple raw thermal image burts and export as .hex
exiftool -config config.txt -a -b -CompressedBurst -v -W "Image/%.2c.hex" IR_2017-02-10_0003.jpg

Extract the just the first of the multiple raw thermal image burts and export as .hex
exiftool -config config.txt -b -CompressedBurst -v -W "%.2c.hex" IR_2017-02-10_0003.jpg

Convert these .hex files to png
ffmpeg -f image2 -vcodec jpegls -i "%02d.hex" -f image2 -vcodec png burst%02d.png

ffmpeg -f image2 -vcodec jpegls -i "./Image/%02d.hex" -f image2 -vcodec png PNG/burst%02d.png

Then try using fairSIM from github - a plug-in for ImageJ that produces the superresolution image

### References
1. https://www.sno.phy.queensu.ca/~phil/exiftool/

2. https://www.imagemagick.org/script/index.php

3. https://www.eevblog.com/forum/thermal-imaging/csq-file-format/