Skip to content

Repository files navigation

Thermal-Simulation

A thermal simulation python code where a heat image is generated based on a real image and then simplified to an 8x8 heatmap

RGB to Thermal-Like 8×8 Sensor Simulation

Overview

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.

How It Works

The program follows these main steps:

  1. Load an RGB image.
  2. Convert the image to grayscale to obtain brightness information.
  3. Invert the brightness values to create a basic temperature-like representation.
  4. Detect warm-colored regions such as red and orange.
  5. Apply a small increase to those regions.
  6. Apply Gaussian blur to simulate the lower spatial resolution and diffusion of thermal information.
  7. Apply a thermal-style color map for visualization.
  8. Resize the simulated thermal data to 8×8 pixels.
  9. Add random sensor noise.
  10. Apply a nonlinear transformation to produce the final heater-array values.
  11. Display the original image, thermal-like image, and 8×8 output.

Requirements

The following Python libraries are required:

  • Python 3
  • OpenCV (cv2)
  • NumPy
  • Matplotlib

Install them with:

pip install opencv-python numpy matplotlib

Input

The 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")

Processing Pipeline

1. Load the Image

The input image is loaded using OpenCV and converted from BGR to RGB for correct Matplotlib visualization.

2. Create a Temperature-Like Representation

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 - gray

This creates a simple approximation where darker regions produce higher temperature-like values.

3. Detect Warm Colors

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.

4. Apply Gaussian Blur

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.

5. Generate a Thermal-Like Visualization

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.

6. Convert to an 8×8 Array

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.

7. Add Sensor Noise

Random Gaussian noise is added:

noise = np.random.normal(0, 0.015, (8, 8))

This makes the simulated sensor output less perfectly uniform.

8. Create the Heater Array

The final 8×8 values are amplified using:

heater = thermal_8x8 ** 1.6

The resulting array represents the simulated sensor/heater values.

Output

The program displays three visualizations:

Original Image

The input RGB image.

Thermal-Like Image

A blurred, color-mapped representation based on the original image.

8×8 Simulated Output

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:

[[... ... ...]
 [... ... ...]
 ...
 [... ... ...]]

Important Note

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.

Project Structure

A simple project structure can be:

project/
│
├── simulation.py
├── images.jpg
└── README.md

Possible Improvements

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.

Disclaimer

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.

About

A thermal simulation python code where a heat image is generated based on a real image and then simplified to an 8x8 heatmap

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages