link to jupyter notebook:
https://github.com/mayukh4/JWST_image_processing
Have you ever wondered how those breathtaking James Webb Space Telescope images are created? The stunning cosmic landscapes we see in the news don’t come directly from the telescope—they require careful processing to transform raw data into visual masterpieces. In this guide, I’ll show you how astronomers turn invisible infrared light into the colorful vistas that captivate our imagination.
What JWST Actually “Sees”
The James Webb Space Telescope, orbiting 1.5 million kilometers from Earth, captures light primarily in the infrared spectrum—completely invisible to human eyes. This means every JWST image you’ve seen is a “false color” representation, carefully constructed to reveal cosmic structures while remaining scientifically meaningful.
Each JWST observation is captured through multiple filters, with each filter sensitive to specific wavelengths of infrared light. For the famous Cosmic Cliffs in the Carina Nebula, five key filters were used:
- F090W (0.9 microns): Captures the hottest stars and reflected starlight
- F200W (2.0 microns): Shows stars hidden behind dust
- F335M (3.35 microns): Reveals complex organic molecules
- F444W (4.44 microns): Detects warm dust (~400°C)
- F470N (4.7 microns): Highlights carbon monoxide and ionized hydrogen
The Image Processing Pipeline
Creating a JWST image involves several key steps:
1. Loading the Raw Data
JWST data comes in FITS (Flexible Image Transport System) files—a specialized format containing both image data and detailed metadata. Python’s Astropy library makes handling these files straightforward:
# Load FITS file
from astropy.io import fits
hdul = fits.open('jwst_image.fits')
data = hdul[1].data # The image data is in the first extension
2. Contrast Enhancement
The raw data has an enormous dynamic range that exceeds what displays can show. We need to rescale the data to bring out details:
# Adjust contrast with percentile-based clipping
lo, hi = np.percentile(data, (15, 99.85)) # Clip darkest and brightest regions
adjusted_data = exposure.rescale_intensity(data, in_range=(lo, hi))
# Apply adaptive histogram equalization for better detail visibility
from skimage import exposure
final_data = exposure.equalize_adapthist(adjusted_data, clip_limit=0.02)
This crucial step ensures we can see both bright stars and dim nebula features simultaneously.
3. Image Alignment
Since different filters are captured separately, we need to align the images precisely:
# Reproject image to match reference image coordinates
from reproject import reproject_interp
aligned_data = reproject_interp((data, header), reference_wcs, shape_out=reference_shape)[0]
4. Color Assignment
Here’s where science meets art. We assign colors to each filter based on wavelength:
def assign_color(filter_wavelength, min_wl, max_wl):
# Map wavelength to color (longer wavelengths → redder colors)
proportion = (filter_wavelength - min_wl) / (max_wl - min_wl)
# Apply S-curve adjustment to avoid too much green
adjusted = 1 / (1 + (proportion / (1 - proportion)) ** -2)
# Map to hue (240° = blue, 0° = red)
hue = (1 - adjusted) * 240 / 360
return hue
For the Cosmic Cliffs, we used this mapping:
- F090W → Blue (240° hue)
- F200W → Cyan (200° hue)
- F335M → Green/Yellow (150° hue)
- F444W → Orange (65° hue)
- F470N → Red (0° hue)
5. Combining the Layers
Finally, we blend all the colorized layers using a screen blending technique:
def screen_blend(image1, image2):
# Screen blending mimics light projection
return 255 - (((255 - image1) * (255 - image2)) // 255)
# Blend all layers
final_image = image1
for image in images[1:]:
final_image = screen_blend(final_image, image)
Understanding What You’re Seeing
The Cosmic Cliffs image reveals an active stellar nursery 7,600 light-years away. What looks like a static landscape is actually a dynamic region where:
- The massive amber cliff is being eroded by stellar radiation at over 1.5 million km/h
- Newly formed stars (blue regions) emit intense ultraviolet radiation that sculpts surrounding gas
- Hidden within the dust wall are hundreds of young protostars still gathering material
- The green/yellow areas highlight complex organic molecules similar to those found on Earth
Try It Yourself!
All JWST data becomes publicly available after a 12-month proprietary period. You can download raw data from the MAST Portal and process it using the techniques described here.
The complete code for this pipeline is available on GitHub, including tools to:
- Process FITS files automatically
- Extract layer images
- Customize the colors for each layer
- Blend layers with screen blending
Beyond the Cosmic Cliffs
The techniques described here can be applied to any JWST dataset. Whether you’re interested in distant galaxies, nebulae, or planetary systems, the process remains similar—loading, enhancing, aligning, colorizing, and blending.
The next time you see a stunning JWST image, you’ll appreciate that it’s not just a pretty picture—it’s a carefully crafted scientific visualization that reveals the hidden structures and processes of our universe. Now you have the knowledge to create your own cosmic masterpieces!