A thermal simulation python code where a heat image is generated based on a real image and then simplified to an 8x8 heatmap
This project converts a normal RGB image into a thermal-like representation and then reduces it to an 8×8 sensor array, similar in format to the output of an AMG8833 thermal sensor.
The project does not produce real thermal measurements. Instead, it uses image brightness, color information, blurring, downscaling, and simulated noise to create an approximation of thermal sensor data.
The program follows these main steps:
- Load an RGB image.
- Convert the image to grayscale to obtain brightness information.
- Invert the brightness values to create a basic temperature-like representation.
- Detect warm-colored regions such as red and orange.
- Apply a small increase to those regions.
- Apply Gaussian blur to simulate the lower spatial resolution and diffusion of thermal information.
- Apply a thermal-style color map for visualization.
- Resize the simulated thermal data to 8×8 pixels.
- Add random sensor noise.
- Apply a nonlinear transformation to produce the final heater-array values.
- Display the original image, thermal-like image, and 8×8 output.
The following Python libraries are required:
- Python 3
- OpenCV (
cv2) - NumPy
- Matplotlib
Install them with:
pip install opencv-python numpy matplotlibThe program expects an image named:
images.jpg
The image should be placed in the same directory as the Python script, or the path should be changed in:
img = cv2.imread("images.jpg")The input image is loaded using OpenCV and converted from BGR to RGB for correct Matplotlib visualization.
The image is converted to grayscale:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)The grayscale values are normalized between 0 and 1.
The values are then inverted:
thermal = 1 - grayThis creates a simple approximation where darker regions produce higher temperature-like values.
The image is converted to HSV color space. A mask is created to identify colors associated with warm regions.
The detected warm regions receive an additional value:
thermal = thermal + 0.25 * warm_mask.astype(np.float32)The values are then clipped to remain between 0 and 1.
A strong Gaussian blur is applied:
thermal_blur = cv2.GaussianBlur(thermal, (55, 55), 18)This reduces small-scale image details and produces a smoother representation.
The processed image is converted into a color representation using the Inferno colormap:
thermal_color = cv2.applyColorMap(
(thermal_blur * 255).astype(np.uint8),
cv2.COLORMAP_INFERNO
)This creates an image that visually resembles common thermal-camera color schemes.
The processed thermal data is reduced to an 8×8 grid:
thermal_8x8 = cv2.resize(
thermal_blur,
(8, 8),
interpolation=cv2.INTER_AREA
)This represents the low-resolution output of an 8×8 thermal sensor.
Random Gaussian noise is added:
noise = np.random.normal(0, 0.015, (8, 8))This makes the simulated sensor output less perfectly uniform.
The final 8×8 values are amplified using:
heater = thermal_8x8 ** 1.6The resulting array represents the simulated sensor/heater values.
The program displays three visualizations:
The input RGB image.
A blurred, color-mapped representation based on the original image.
The final low-resolution sensor array displayed as a heatmap.
The numerical 8×8 array is also printed in the terminal:
8×8 Heater Array:
[[... ... ...]
[... ... ...]
...
[... ... ...]]
This project is a simulation, not a true thermal imaging system.
An AMG8833 detects infrared radiation and measures actual temperature-related signals. This program instead estimates temperature-like values from visible-light image information.
Therefore, the output should be considered pseudo-thermal data rather than real temperature measurements.
A simple project structure can be:
project/
│
├── simulation.py
├── images.jpg
└── README.md
The simulation could be improved by:
- Using a more realistic temperature estimation model.
- Correcting the HSV hue range for OpenCV.
- Adding configurable sensor noise.
- Simulating the AMG8833's temperature range.
- Adding interpolation between the 8×8 sensor values.
- Comparing the simulated output with actual AMG8833 measurements.
- Using real thermal images as a reference.
- Adding a configurable ambient/background temperature.
- Modeling sensor-specific characteristics such as measurement noise and response behavior.
The generated 8×8 values are not actual temperatures in °C. They are normalized simulated values designed to demonstrate how an RGB image could be transformed into a low-resolution thermal-like representation.