Konvertierung von radiometrischen JPG zu TIFF
Verfasst: Montag 20. Dezember 2021, 10:10
Hallo,
ich habe ein Code Snippet gefunden, welches mir radiometrische JPGs zu TIFFs konvertiert. Danach habe ich die Pfade angepasst und mit einem Thermalfoto getestet. Das Code Snippet läuft nicht durch.
Leider habe ich nicht sehr viel Erfahrung mit Python bis jetzt.
Das ist das Code Snippet:
import glob
import os
import subprocess
import PIL.Image
import numpy as np
import io
import json
import skimage
import matplotlib.image
# specify the name format (this should be standard for FLIR jpgs)
INPUT_FILE_MASK = "*_T.jpg"
# input the exiftool location (you may need to download it)
EXIFTOOL = "C:/Users/CopterLogServices/Deskto/TEST_ConvertRJPGtoTIFF/exiftool.exe"
def process_image(filename, radiometric_corr=True, save_false_colour_png=False):
""" Read data from JPG image and write to h5-handler """
# read meta-data and binary image
meta = get_string_meta_data(filename)
img = get_raw_thermal_image(filename)
# extract "IR_xxx" as frame identifier
folder_name = os.path.split(filename)[0]
name = os.path.split(filename)[-1]
name = os.path.splitext(name)[0]
# converison to temperature:
# according to http://u88.n24.queensu.ca/exiftool/foru ... l#msg23972
# extract radiometric parameters
R1, R2, B, F, O = tuple(meta["Planck{}".format(s)]
for s in ("R1", "R2", "B", "F", "O"))
# for the case of emissivity != 1
if radiometric_corr:
emissivity = meta["Emissivity"]
# drop the C on the temp and increase to Kelvin
T_refl = float(meta["ReflectedApparentTemperature"][:-1]) + 273.15
RAW_refl=R1/(R2*(np.exp(B/T_refl)-F))-O
RAW_obj=(img-(1-emissivity)*RAW_refl)/emissivity
T = B / np.log(R1/(R2*(RAW_obj+O))+F)
# (for the case: emissivity == 1)
else:
T = B / np.log(R1/(R2*(img+O))+F)
if save_false_colour_png:
conv_T = skimage.exposure.rescale_intensity(T)
matplotlib.image.imsave("{}.png".format(os.path.join(folder_name, name)), conv_T, cmap='inferno')
T = PIL.Image.fromarray(T)
T.save("{}.tiff".format(os.path.join(folder_name, name)))
def get_raw_thermal_image(filename, key="RawThermalImage"):
""" Use exiftool to extract 'RawThermalImage' from FLIR-JPG """
# call exiftool and extract binary data
cmd = [EXIFTOOL, filename, "-b", "-{}".format(key)]
r_data = subprocess.check_output(cmd)
# read in image (should detect image format)
im = PIL.Image.open(io.BytesIO(r_data))
# convert image to array
return np.array(im)
def get_string_meta_data(filename):
""" Read all exif-data using exiftool """
# call exiftool with 'JSON'-output flag
cmd = [EXIFTOOL, filename, "-j"]
dta = subprocess.check_output(cmd, universal_newlines=True)
# convert to stream and load using 'json' library
data = json.load(io.StringIO(dta))
# reduce dimension if singleton
if isinstance(data, list) and len(data) == 1:
data = data[0]
return data
# set the folder location that holds the radiometric jpgs
# files will be saved as tiff files with the same name
# if specified, the images will also be saved as regular jpegs in a colormap suitable for thermal images
# this option will not produce publishing quality images as there is no contrast adjustment or other processing
filt=INPUT_FILE_MASK
folder="C:/Users/CopterLogServices/Desktop/TEST_ConvertRJPGtoTIFF/footage"
filt = os.path.join(folder, filt)
for filename in glob.iglob(filt):
process_image(filename, radiometric_corr=True, save_false_colour_png=False)
Folgende Fehler erhalte ich, wenn ich das Code Snippet ausführe:
Traceback (most recent call last):
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 92, in <module>
process_image(filename, radiometric_corr=True, save_false_colour_png=False)
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 20, in process_image
meta = get_string_meta_data(filename)
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 72, in get_string_meta_data
dta = subprocess.check_output(cmd, universal_newlines=True)
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
Vielleicht kann mir jemand von euch helfen.
Danke im Voraus!
ich habe ein Code Snippet gefunden, welches mir radiometrische JPGs zu TIFFs konvertiert. Danach habe ich die Pfade angepasst und mit einem Thermalfoto getestet. Das Code Snippet läuft nicht durch.
Leider habe ich nicht sehr viel Erfahrung mit Python bis jetzt.
Das ist das Code Snippet:
import glob
import os
import subprocess
import PIL.Image
import numpy as np
import io
import json
import skimage
import matplotlib.image
# specify the name format (this should be standard for FLIR jpgs)
INPUT_FILE_MASK = "*_T.jpg"
# input the exiftool location (you may need to download it)
EXIFTOOL = "C:/Users/CopterLogServices/Deskto/TEST_ConvertRJPGtoTIFF/exiftool.exe"
def process_image(filename, radiometric_corr=True, save_false_colour_png=False):
""" Read data from JPG image and write to h5-handler """
# read meta-data and binary image
meta = get_string_meta_data(filename)
img = get_raw_thermal_image(filename)
# extract "IR_xxx" as frame identifier
folder_name = os.path.split(filename)[0]
name = os.path.split(filename)[-1]
name = os.path.splitext(name)[0]
# converison to temperature:
# according to http://u88.n24.queensu.ca/exiftool/foru ... l#msg23972
# extract radiometric parameters
R1, R2, B, F, O = tuple(meta["Planck{}".format(s)]
for s in ("R1", "R2", "B", "F", "O"))
# for the case of emissivity != 1
if radiometric_corr:
emissivity = meta["Emissivity"]
# drop the C on the temp and increase to Kelvin
T_refl = float(meta["ReflectedApparentTemperature"][:-1]) + 273.15
RAW_refl=R1/(R2*(np.exp(B/T_refl)-F))-O
RAW_obj=(img-(1-emissivity)*RAW_refl)/emissivity
T = B / np.log(R1/(R2*(RAW_obj+O))+F)
# (for the case: emissivity == 1)
else:
T = B / np.log(R1/(R2*(img+O))+F)
if save_false_colour_png:
conv_T = skimage.exposure.rescale_intensity(T)
matplotlib.image.imsave("{}.png".format(os.path.join(folder_name, name)), conv_T, cmap='inferno')
T = PIL.Image.fromarray(T)
T.save("{}.tiff".format(os.path.join(folder_name, name)))
def get_raw_thermal_image(filename, key="RawThermalImage"):
""" Use exiftool to extract 'RawThermalImage' from FLIR-JPG """
# call exiftool and extract binary data
cmd = [EXIFTOOL, filename, "-b", "-{}".format(key)]
r_data = subprocess.check_output(cmd)
# read in image (should detect image format)
im = PIL.Image.open(io.BytesIO(r_data))
# convert image to array
return np.array(im)
def get_string_meta_data(filename):
""" Read all exif-data using exiftool """
# call exiftool with 'JSON'-output flag
cmd = [EXIFTOOL, filename, "-j"]
dta = subprocess.check_output(cmd, universal_newlines=True)
# convert to stream and load using 'json' library
data = json.load(io.StringIO(dta))
# reduce dimension if singleton
if isinstance(data, list) and len(data) == 1:
data = data[0]
return data
# set the folder location that holds the radiometric jpgs
# files will be saved as tiff files with the same name
# if specified, the images will also be saved as regular jpegs in a colormap suitable for thermal images
# this option will not produce publishing quality images as there is no contrast adjustment or other processing
filt=INPUT_FILE_MASK
folder="C:/Users/CopterLogServices/Desktop/TEST_ConvertRJPGtoTIFF/footage"
filt = os.path.join(folder, filt)
for filename in glob.iglob(filt):
process_image(filename, radiometric_corr=True, save_false_colour_png=False)
Folgende Fehler erhalte ich, wenn ich das Code Snippet ausführe:
Traceback (most recent call last):
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 92, in <module>
process_image(filename, radiometric_corr=True, save_false_colour_png=False)
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 20, in process_image
meta = get_string_meta_data(filename)
File "C:\Users\CopterLogServices\Desktop\TEST_ConvertRJPGtoTIFF\code\ConvertFLIR_mod.py", line 72, in get_string_meta_data
dta = subprocess.check_output(cmd, universal_newlines=True)
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\CopterLogServices\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
Vielleicht kann mir jemand von euch helfen.
Danke im Voraus!