Santi-hr / UNI-T-Thermal-Utilities

Small script to extract raw temperature data from UNI-T thermal camera images.
MIT License
57 stars 4 forks source link

FLIR image conversion #1

Open blackbird2908 opened 3 years ago

blackbird2908 commented 3 years ago

My comment in Youtube has been deleted due of quoting web links: Here are just 2 files I have found, but there are plenty of them. https://file.io/8IMuFEnm5icF and https://file.io/du8qtfidmgnZ and some helpful links: https://exiftool.org/TagNames/FLIR.html https://irinfo.org/04-01-2006-colbert/ https://fossies.org/linux/Image-ExifTool/lib/Image/ExifTool/FLIR.pm Thank you so much. You will help many people out there with this

Santi-hr commented 3 years ago

I have been trying today and this is no easy task. I managed to understand how the radiometric data is converted to temperatures, so the inverse operation can be easily done by fixing some of the parameters. Also I read the forum from the exiftool and how they reverse engineered the FLIR propietary metadata.

The blocking point right now is generating a ".jpg" with the required Exif tags. Most of the tools I analized are used only to read and not to write tags. Exiftool was promising, got it working with Python, but has the FLIR tags as not writable (RawThermalImage is the one to overwritte). The only way I see is by writing myself a tool to write the needed tags, however this means a lot investigation and work.

I leave here documentation on the exif tags for myself: https://web.archive.org/web/20190624045241if_/http://www.cipa.jp:80/std/documents/e/DC-008-Translation-2019-E.pdf

Santi-hr commented 3 years ago

Fortunately, I found a workaround to load the images in the ThermoVision from Joe-C as you wanted.

Uni-t Thermal Loaded in ThermoVision

Their program allows for decoding thermal data in byte arrays (Just what a bmp is). For this to work you need to follow these steps:

  1. Run the code below to get a clean grayscale bmp. I used Pillow for saving the image.
  2. In ThemoVision, File, set drop to "IR Decoder Image". Drop the new thermal generated grayscale bmp.
  3. Set the grabber configuration as on the image above. The blue form. You can get the "Start offset" from the script output.
  4. On the Left side bar, under "IR-Image Decoder", set the minimum and maximum temperatures in "Cal2". These temperatures are printed on the script output.

Code to generate the thermal grayscale bmp:

import uniTThermalImage
import PIL.Image

filename_input = "Images/IMG_Typical.bmp"
filename_output = "Images/thermal_output.bmp"

uti_obj = uniTThermalImage.UniTThermalImage()
uti_obj.init_from_image(filename_input)

pillow_img = PIL.Image.fromarray(uti_obj.raw_img_np)
pillow_img.save(filename_output)

try:
    uti_obj_out = uniTThermalImage.UniTThermalImage()
    uti_obj_out.init_from_image(filename_output)
except Exception:
    print("Expected execption as new file does not contain embedded thermal data")
print("Start offset:", uti_obj_out.bmp_header['data_start_byte'])
print("T Min:", uti_obj.temp_min)
print("T Max:", uti_obj.temp_max)
blackbird2908 commented 3 years ago

Bravo. Thank you for your research on this issue. Nice solution and it works very well. The only drawback are the initial settings in the IR decoder import, which would have to be entered always anew manually for each image. By the way I've found another interesting way to analyze and work with the Uni-t thermal images in conjunction with your brillant Python script:

  1. Export a clean csv image with tabulator as delimiter (not comma separated) without any header lines (example: https://file.io/5HwijssRDN3n )
  2. Install FIJI (ImageJ) with ThermImageJ macros according these installation instructions ( https://github.com/gtatters/ThermImageJ )
  3. Now you are able to import the thermal csv image in ImageJ. File --> Import --> Text image --> Select your tab delimited csv file. All temp values are now present and you have many useful functions to work with. imagej1

Add calibration bar tool and thermal LUT menu (e.g. ironbow): imagej2

There are so many plugins and functions. For example, I've installed the "Interactive 3D surface plot plugin": imagej3

Try it out.

flotux2 commented 3 years ago

@Santi-hr, @blackbird2908,

thanks a lot for your contribution to import UTi260B images into ThermoVision from Joe-C.

We might also post in the following forum thread where Joe-C is answering to questions about his great software: https://www.eevblog.com/forum/thermal-imaging/freeware-software-for-thermal-analysis-thermovision_joec

His last answer ist from 2021-01-24. So perhaps he is open to support the direct loading of those special BMP files from UTi260B. Then we wouldn't need to run the Python script each time.

I would let you guys go ahead and ask, since you've had the most work with the subject so far. But I could also pot this request and provide test images to Joe-C.

What do you think?

Best regards Florian

Santi-hr commented 3 years ago

Thanks for your findings @blackbird2908. I added an option to the script to generate those tab-delimited files.

I agree that currently importing the images to ThermoVision is quite tedious. Being an easy to load file I guess he won't have much trouble adding support for these range of thermal cameras. I might later create an account and let him know, thanks @flotux2

blackbird2908 commented 3 years ago

Asking the founder of ThermoVision for adding the UTI260 is a very good idea. By the way I've just seen, that you have posted already in the eevblog.com forum. Thanks

flotux2 commented 3 years ago

joe-c published yesterday a debug version of his great software that seems to support our thermal camera! I will test it now to see if it is really working. I've already sent him some example pictures that he requested in his post.

blackbird2908 commented 3 years ago

Very nice. Thank you for your postback. It works very well except the min max hotspot visualization.