Thermal Raw Data¶
The Spot CAM+IR payload allows capture of thermal data in the forms of
.pgm files. Raw data files allow for more versatility when compared to a thermal
jpeg image because they allow the thermal data to be rendered or analyzed as needed. For example, re-construction of a thermal image from the raw thermal data enables viewing with custom color palettes or to perform specific image processing in more advanced applications.
Understanding thermal data¶
The raw thermal data from the Spot CAM+IR contains 327,680 (640x512) 16-bit unsigned values. Each value describes a temperature in units of decikelvin. To get the value in units of kelvin, divide the value by 10.
The two bytes encoding each data value are given in big endian, meaning that the most significant byte of the two is given first when reading the data from left to right. There is an exception to this for version 3.1.0 of the Spot CAM+IR software, in which the byte order of the data was reversed to little endian.
|SpotCAM+IR Software Version||Endianness|
|All other versions||Big endian|
Thermal file types (
Raw data captured using the SDK is captured as
.pgm while the same data captured using callbacks is captured as
.raw. Both contain the same data, except that the
.pgm file contains additional header lines. In general,
.pgm files are downloaded when using the spot SDK while
.raw files are downloaded when downloading through the data service. The example script can read both file types, but it throws away any header files. The
.pgm headers are necessary to parse the data if the width and height of the image are variable.
Rendering raw thermal data¶
Some image viewers can natively open .pgm files as a grayscale image. To instead show with a particular color palette, a lookup-table can be referenced to map from temperature to a color. For example, the lookup tables used by matplotlib can be referenced at this link
Scaling the color mapping¶
The left image is a render using the min and max temperatures mapping directly to the the min and max values in the color map. The image on the right shows the same image but with the mapping adjusted so that the lower temperature values are less prominent. This allows for more contrast and improved visibility of the hotter areas.
The following renderings are generated from a single thermal data capture and rendered with OpenCV.
import matplotlib.pyplot as plt import numpy # width and height based on the Spot CAM+IR thermal camera height = 512 width = 640 filename = "/path/to/pgm/or/raw/file" with open(filename, 'rb') as f: buffer = f.read() split_buffer = buffer.splitlines() # the last element for both .pgm and .raw files is the data after splitting by newline data = split_buffer[len(split_buffer) - 1] # '>' for big endian and '<' for little endian processed_data = numpy.frombuffer(data, dtype='>u2').reshape((int(height), int(width))) image = list(processed_data) plt.imshow(image, plt.cm.inferno) # some alternate colormaps: inferno, plasma, viridis, ocean, cubehelix, rainbow plt.show()