Help or advice on importing thermal imaging video files - Page 1
Forum section: electronics / testgear

author: gtatters
author_rank: Contributor
timestamp: February 18, 2015, 02:21:20 pm
content: I wonder if this forum could help me with a thermal imaging video loading question?I use infrared thermal imaging a lot in my biological research. I have two thermal cameras in my lab, an older Mikron 7515 model and a new FLIR SC660 model. We use these cameras in the field as well as in the lab. Both cameras come with research acquisition software that allows for the collection of time lapsed (or ‘live’) thermal video files. I also have the software from the companies (which I’ve paid much for!) to fully analyse the images, so am not looking to do a run-around the company's software. However, I lack the capacity to automate the thermal analysis of videos with the existing software packages, given the limitations of the software. I know that FLIR has an SDK that can be used with matlab, but that is an additional expense to add.The actual purpose for wanting to load these videos into R (or matlab) is to apply frame by frame subtraction analysis to score relative movement of animals or objects in the field of view. We don't need to analyse temperature, per se. We have (or shortly will have) hundreds of these videos, so it would be nice to simplify the analysis. I’ve already exported the video files into .txt or .csv files and written my script in R for importing them for analysis, but I was hoping to cut the need to use the thermal camera program out of the entire process and import the thermal image videos directly and perform the analysis on them. (Thermal camera programs I have: MikrospecRT, Thermacam Researcher Pro 2.9, Flir ResearchIR Max).Here’s the catch. You might be thinking that I want to convert the radiometric data directly into temperatures (as I've seen done by Phil Harvey with his exiftool). That would be nice, but for the purposes of frame subtraction, it wouldn’t really be necessary. Since I’m not very savvy at writing code for image importing, I am not privy to any of the file formatting contained in these files. But I am lead to believe from talking to FLIR engineers that the standard flir file contains a ‘thumbnail’ jpg image, but that the radiometric data is also stored in the file as well.If you are willing to take a look at this, I’ve uploaded two thermal videos and their accompanying ‘video conversions’ to a public dropbox account so you can see what they look like. RTV files are the native format for the (now no longer supported) MikroSpecRT program from Mikron. SEQ files are radiometric thermal video files saved directly from the FLIR SC660 camera. One of the videos is of hot air balloons in Brasil and the other is from a bird (Western Sandpiper) flying in a wind tunnel. These are just sample videos, not ones that I really want to analyse, but I thought you might find them interesting.https://www.dropbox.com/sh/0kqpxiya4zxojci/AAC5IkqoPAAavelXzfajbA1ea?dl=0Any pointers from people in this forum would be appreciated.

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 04:02:49 am
content: On the rtv file here is what I found, they are sequential images each frame has a 42 byte header that includes a timestamp and width & height information:Data is little endian (Least significant byte first, most significant byte last, or lower address has lower value if that makes more sense)Values start after 42 byte header that includes time stamp with milliseconds06/28/08 19:12:43.484 (last highlighted red box is actual thermal data)width encoding value at 0x0022 (34 bytes) 17th word but it seems it could be up to a 64 bit (8 bytes) unsigned long long, but the image is small enough that only the first word can tell you the width)320 (0x0140) widthImage height at 0x001a (26 bytes) 13th word (again, it seems the value could be 8 bytes long but only the lower 2 bytes is enough for the small height value)240 (0x00f0) heightFirst frame (equalized and reduced to 8 bits and with an Iron colormap applied):Next frame is at: 320x240x2+42 bytes, the 2 is because each pixel takes two bytes.153642 bytes per frame.that includes a 42 byte header as well and the data, timestamp for the 2nd frame is:06/28/08 19:12:53.562 roughly over 10 seconds later (10.078s)So the whole file has 100 frames in it (15365010/153642) must have a trailer at the end (810 bytes)BTW that's a nice camera

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 06:02:59 am
content: Here is the movie of the balloons at 1 second between frames instead of 10 seconds.Also I didn't apply the Iron colomap but I did equalize the images and they are downsampled to 8 bits per pixel instead of the 16, then again I didn't look at the range of the data so it might not loose that much to begin with.

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 07:39:36 am
content: Same 1st frame but not equalized, you get more details on the balloonsvs the equalized one (more detail on the cold areas)

author: gtatters
author_rank: Contributor
timestamp: February 19, 2015, 04:26:01 pm
content: Thank you for working that out for the rtv file (from my mikron camera).I'm actually interested in finding a way to open these files (the .rtv and the .seq) myself using matlab or R. I only uploaded the .avi files so you could readily see the videos before tackling the raw thermal files.Would you be familiar with how I might achieve that? At least how to pull in the matrix of data that accompanies an individual frame in the video? After that I can do my own analyses on those values.

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 04:53:29 pm
content: Not familiar with matlab at all, but it seems this will do:http://www.mathworks.com/help/matlab/ref/fread.htmluse the one that has the skip and machine format (last one)So to get the first frame it should be something like:fileID = fopen('balloons_1 - 10s interval.rtv')[A,count] = fread(fileID,[320 240],'uint16', 42, 'l')fclose(fileID);then you can loop the fread for each frame as long as your count is 153642 (edit: unsure about this because doc says it the umber of characters read so might be just 76800) you have a valid frame store in a 320 by 240 of unsigned int 16 bits stored in the matrix A.I guess matlab is not that hard to figure out, good documentation at leastEdit: btw, I didn't watch the video at all, I should had but the binary data was pretty obviousas for the .seq, check the E4 and other Flir threads, people already worked on that format for what I've seen in those threads.

author: gtatters
author_rank: Contributor
timestamp: February 19, 2015, 06:01:57 pm
content: Thank you so much!! I will work on implementing this. Might take me a while but I'll post what success/failure I have once I get there. I'll try to get it working for R since R is free. Matlab is pricey.

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 06:41:49 pm
content: FYII've heard that matlab has now a home edition

author: gtatters
author_rank: Contributor
timestamp: February 19, 2015, 06:44:00 pm
content: Ah, i'll look into that.

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 06:49:43 pm
content: Link:https://www.mathworks.com/store/link/products/home/?s_iid=main_buy_home_cta1Not sure if you'll need the image processing package and what comes with the base install for $150each optional package is $45 so don't get them unless you really need them because that will add up quickly

author: gtatters
author_rank: Contributor
timestamp: February 19, 2015, 06:54:00 pm
content: Thanks. I've just never imported binary files, so I'll figure out how it works in matlab but then see if I can work it out in R. R is completely free and has new libraries available on a regular basis. Much more amenable to teaching on a budget!

author: miguelvp
author_rank: Super Contributor
timestamp: February 19, 2015, 07:54:46 pm
content: I know nothing about R, but others in the forum have suggested Octave as an alternative to MatLabhttp://en.wikipedia.org/wiki/GNU_OctaveBut I know nothing about Octave either, I did have use matlab before but probably only a couple of times, but at least I'm more familiar with that.Usually I use VisiQuest (discontinued) and used to use IDL in the past. But I don't do image processing and signal processing so much these days.