A Python tool for processing and compiling SWAP solar observatory images into animated GIFs or WebP animations.
This tool processes raw SWAP (Sun Watcher using Active Pixel System detector and Image Processing) images from the PROBA2 satellite and combines them into smooth animations. The script performs several image correction operations:
- Automatic rotation correction to align images
- Image enhancement with various color profiles
- Blurry and corrupted frame detection and removal
- Compilation into animated GIF/WebP formats
Example animation of solar activity captured by PROBA2's SWAP instrument and processed with this tool.
- Python 3.6+ (tested on Python 3.12.9 but should be okay at lower versions too)
- Dependencies:
- numpy
- imageio
- opencv-python-headless (or opencv-python if you want realtime display of processed frames)
- os
- re
- Clone this repository or download the script
- Install the required dependencies:
pip install numpy imageio opencv-python-headlessNote: If you want realtime image display, you can use the normal version:
pip install numpy imageio opencv-python- Place your SWAP images (raw b&w images) in a folder (e.g., "SWAP/")
- Make sure you have the calibration image (
calibration.png) in the same directory as the script - Configure the settings at the top of the script
- Run the script:
python main.pyEdit these variables at the top of the script to customize processing:
INPUT_DIR- Directory containing SWAP imagesOUTPUT_FILE- Output filename (supports .gif or .webp)MS_PER_FRAME- Milliseconds per frame in the output animationEXTRA_PROCESSING- Enable additional alignment processing (rarely needed)ENHANCEMENT_NAME- Color profile to apply ("official", "blue", "orange", etc. or None)SHOW_IMG_REALTIME- Display frames during processing (requires opencv-python)
Several enhancement profiles are available:
official- Standard SWAP coloring (orange)official_blue- Blue variant of the official coloringorange- High contrast orangeblue- High contrast bluegreen- High contrast greenpink- High contrast pinkmagenta- High contrast magentapurple- High contrast purple
The script:
- Loads and sorts images based on their timestamp
- Calculates image quality using the Tenengrad measure
- Skips blurry or corrupted frames
- Performs multi-step image alignment:
- Rotation correction
- Coarse alignment
- Medium alignment
- Fine alignment
- Applies color enhancement
- Compiles frames into an animation
- First loaded image becomes the reference for alignment
- A circular mask is applied to focus on the sun disk and reduce computation
# Set to process images in the SWAP folder
INPUT_DIR = "SWAP/"
# Output as GIF with 100ms per frame
OUTPUT_FILE = "output.gif"
MS_PER_FRAME = 100
# Use the official SWAP coloring
ENHANCEMENT_NAME = "official"- Special thanks to @soplica.pl on Discord for providing the calibration image and test data.
- Special thanks to @seler1500 on Discord for providing test data.
