1

I am using a therm-app camera to take infra-red photos of bats. I would like to draw around parts of the bat and find the hottest, coldest and average temperature and do further analysis.

The software that comes with the camera doesn't let me draw polygons so I would like to load the image in another program such as MATLAB or maybe imageJ (also happy to use Python or other if that would work).

The camera creates 4 files total:

I have a .jpg file, however when I open this in MATLAB it just appears as an image and I think it is just opening as a normal image, not sure how to accurately get the temperatures from this. I used the following to open it:

im=imread('C:\18. Bats\20190321_064039.jpg');
imshow(im);

I also have three other files, two are metadata (e.g. show date-time emissivity settings etc.) and one is a text file.

The text file appears to show the temperature of every pixel in the image.

e.g. (for a photo that had a minimum temperature of 15deg and max of 20deg it would be a text file with a minimum value of 1500 and maximum value of 2000)

1516 1530 1530 1540 1600 1600 1600 1600 1536 1536 ........

This file looks very useful, just wondering if there is some way I can open this as an image, probably in a program like MATLAB, which I think has image analysis so that I could draw around certain parts of the image (e.g. the wing of the bat) and find the average, max, min etc. Has anyone had experience with this type of thing, can I just assign colours to numbers somehow? Or maybe other people have done it already and there is a much easier way. I will keep searching on the internet also and try to find out.

Alternatively maybe I need to open the .jpg image, draw around different parts, write a program to find out which pixels I drew around, find these in the txt file and then do averaging etc? Or somehow link the values in the text file to the .jpg file.

Sorry if this is the wrong place to ask, I can't find an image processing site on stack exchange.

All help is really appreciated, I will continue searching on the internet in the meantime.

10
  • 1
    what's the structure of the text file, is it a CSV type file, or tabs spaced array etc... you can look into csvread or dlmread commands
    – bla
    Commented Jun 21, 2019 at 4:48
  • Hi bla, thanks! it's a .txt file the numbers in the file are separated by one space only, so I guess that's very similar to csv except using space as the separator. Will look up those commands :)
    – Shara
    Commented Jun 21, 2019 at 4:52
  • Thanks, dlmread worked, once I've got everything exactly right I'll reply with more info.
    – Shara
    Commented Jun 21, 2019 at 5:21
  • Sounds cool - maybe share a set of the files via Dropbox or Google Drive along with anything you know about the dimensions of the file and I'll take a look. Commented Jun 21, 2019 at 7:21
  • Specifying the thermal camera make and model would help too. Commented Jun 21, 2019 at 8:00

1 Answer 1

2

the following worked in the end, it was much much easier than I thought it would be. Now a big fan of MATLAB, I thought it could take days to do this.

Just pasting here in case it is useful to someone else. I'm sure there is a more elegant way to write the code, however this is the first time I've used MATLAB in 20 years :p Use at your own risk, I haven't double checked I'm getting the correct results yet (though will do before I use it for anything important).

  • edit, since writing this I've found that the output .txt file of temperatures is actually sensor temperatures which need to be corrected for emissivity and background temperature to obtain the target temperatures. (One way to do this is to use the software which comes free with the camera to create new output .csv files of temperatures and use those instead).

Thanks to bla who put me on the right track with dlmread.

M=dlmread('C:\18. Bats\20190321_064039\20190321_064039_temps.txt')  % read in the text file as a matrix (call it M)
                          % note that file seems to be a list of temperature values for each pixel 
                          % e.g. 1934 1935 1935 1960 2000 2199... 
M = rot90( M , 1 )  % rotate M anti-clockwise by 1*90  (All the pictures were saved sideways for some reason so rotate for easier viewing)
a = min(M(:));      % find the minimum temperature in the image
b = max(M(:));      % find the maximum temperature in the image
imresize(M,1.64);   % resize the image to fit the computer screen prior to showing it on the screen

imshow(M,[a b]);    % show image on the screen and fit the colours so that white is the value with the highest temperature in the image (b) and black is the lowest (a).

h = drawpolygon('FaceAlpha',0);     % Let the user draw a polygon around the region of interest (ROI) 
                                %(this stops code until polygon is drawn)

maskOfROI = h.createMask();         % For each pixel in the image assign a binary number, pixels inside the polygon (ROI) area are given 1 outside are 0
selectedValues = M(maskOfROI);      % Now get the image values for all pixels where the mask value is '1' (i.e. all pixels within the polygon) and call this selectedValues.


averageTemperature = mean(selectedValues);     % Get the mean of selectedValues (i.e. mean of the temperatures inside the polygon area)
maxTemperature = max(selectedValues);          % Get the max of selectedValues
minTemperature = min(selectedValues);          % Get the min of selectedValues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.