-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
183 lines (122 loc) · 6.88 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
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.
<img src='Uploads/frame00001.png' align="centre">
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*
```
<img src='Uploads/JPGconverted.png' align="centre">
### 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/