%pylab inline import flirimageextractor from matplotlib import cm import matplotlib.pyplot as plt import numpy as np flir = flirimageextractor.FlirImageExtractor(palettes=[cm.jet, cm.bwr, cm.gist_ncar]) flir.process_image('./cviceni_5/FLIR0805.jpg') flir.plot() img = flir.get_thermal_np() plt.figure(1, figsize(10,10)) plt.imshow(img, cmap="gray") print(type(img[0,0]), np.min(img), np.max(img)) meta = flir.get_metadata('cviceni_5/FLIR0811.jpg') print(meta.keys()) print(meta["Emissivity"]) print(meta["CameraTemperatureRangeMax"]) raw_data = meta.get("RawThermalImage") print(raw_data) import io import os import subprocess from PIL import Image thermal_img_bytes = subprocess.check_output(["exiftool", "-RawThermalImage", "-b", 'cviceni_5/FLIR0811.jpg']) print(thermal_img_bytes) thermal_img_stream = io.BytesIO(thermal_img_bytes) thermal_img_stream.seek(0) thermal_img = Image.open(thermal_img_stream) thermal_np = np.array(thermal_img) plt.figure(1, figsize(10,10)) plt.imshow(thermal_np, cmap="gray") print(type(thermal_np[0,0]), np.min(thermal_np), np.max(thermal_np)) args = [ "exiftool", "-Emissivity", "-SubjectDistance", "-AtmosphericTemperature", "-ReflectedApparentTemperature", "-IRWindowTemperature", "-IRWindowTransmission", "-RelativeHumidity", "-PlanckR1", "-PlanckB", "-PlanckF", "-PlanckO", "-PlanckR2", "-j", "-", ] def raw2temp( raw, E=1, OD=1, RTemp=20, ATemp=20, IRWTemp=20, IRT=1, RH=50, PR1=21106.77, PB=1501, PF=1, PO=-7340, PR2=0.012545258, ): """ convert raw values from the flir sensor to temperatures in C # this calculation has been ported to python from # https://github.com/gtatters/Thermimage/blob/master/R/raw2temp.R # a detailed explanation of what is going on here can be found there """ # constants ATA1 = 0.006569 ATA2 = 0.01262 ATB1 = -0.002276 ATB2 = -0.00667 ATX = 1.9 # transmission through window (calibrated) emiss_wind = 1 - IRT refl_wind = 0 # transmission through the air h2o = (RH / 100) * exp( 1.5587 + 0.06939 * (ATemp) - 0.00027816 * (ATemp) ** 2 + 0.00000068455 * (ATemp) ** 3 ) tau1 = ATX * exp(-sqrt(OD / 2) * (ATA1 + ATB1 * sqrt(h2o))) + (1 - ATX) * exp( -sqrt(OD / 2) * (ATA2 + ATB2 * sqrt(h2o)) ) tau2 = ATX * exp(-sqrt(OD / 2) * (ATA1 + ATB1 * sqrt(h2o))) + (1 - ATX) * exp( -sqrt(OD / 2) * (ATA2 + ATB2 * sqrt(h2o)) ) # radiance from the environment raw_refl1 = PR1 / (PR2 * (exp(PB / (RTemp + 273.15)) - PF)) - PO raw_refl1_attn = (1 - E) / E * raw_refl1 raw_atm1 = PR1 / (PR2 * (exp(PB / (ATemp + 273.15)) - PF)) - PO raw_atm1_attn = (1 - tau1) / E / tau1 * raw_atm1 raw_wind = PR1 / (PR2 * (exp(PB / (IRWTemp + 273.15)) - PF)) - PO raw_wind_attn = emiss_wind / E / tau1 / IRT * raw_wind raw_refl2 = PR1 / (PR2 * (exp(PB / (RTemp + 273.15)) - PF)) - PO raw_refl2_attn = refl_wind / E / tau1 / IRT * raw_refl2 raw_atm2 = PR1 / (PR2 * (exp(PB / (ATemp + 273.15)) - PF)) - PO raw_atm2_attn = (1 - tau2) / E / tau1 / IRT / tau2 * raw_atm2 raw_obj = ( raw / E / tau1 / IRT / tau2 - raw_atm1_attn - raw_atm2_attn - raw_wind_attn - raw_refl1_attn - raw_refl2_attn ) # temperature from radiance temp_celcius = PB / np.log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15 return temp_celcius