# Image Stacking Guide

The Image Stacking tool is designed to help you select and combine the highest quality frames from your video or image sequence for improved clarity and detail in planetary astrophotography.

The Image Stacking tool supports RAW video data in SER or uncompressed RAW AVI format, plus image sequences composed of PNG, FIT/FITS, TIFF, or RAW image files. If your files are in another format, you’ll need to convert them before importing.

## Process Overview

The basic steps in image stacking are:

1. Sharpness Detection: Each frame is analyzed for sharpness by identifying edges. Frames with more detected edges are sharper, indicating clearer "seeing" conditions.
2. Alignment: Frames are aligned to a user-selected reference frame, ensuring consistency across frames.
3. Stacking: The frames are combined by averaging, resulting in a single enhanced "stacked" image.


## Playback Options

### Bayer Pattern
The Bayer pattern specifies the color filter array for your sensor, which Planet Stacker X uses to debayer (convert to color) the image correctly. For SER files, Planet Stacker X infers this automatically, but for RAW AVI files, you must set it manually. Most color cameras use either RGGB or BGGR patterns.

### Align Playback
When enabled, this option applies Planet Stacker X’s alignment algorithm during playback. This prevents the target from "jumping around" when playback is not in chronological order.

### Frame Ordering
You can choose the playback order for your frames:

- Time: Plays frames in chronological order.
- Sharpness: Plays frames from sharpest to least sharp, as determined by Planet Stacker X's sharpness algorithm.
Note: Frame ordering only affects playback. For stacking, frames are always sorted by sharpness.

## Current Frame Options

### Alignment Frame
Sets the currently displayed frame as the reference frame for aligning all other frames during stacking.

### Include in Stack
Determines whether the currently displayed frame will be included in the final stack. Uncheck this to skip the frame.

### Delete Frame
Permanently deletes the currently displayed frame from the stack. This action cannot be undone without reloading the original file.

## Stacking Options

### Auto
Automatically selects the best frames for stacking based on median sharpness. Basically this algorithm will only stack the frames represented as "green" frames in the sharpness graph.

### Percentage
Allows you to specify a percentage (e.g., the top 20%) of the sharpest frames for stacking. Enter the percentage in the text box provided.

### Count
Allows you to manually select an exact number of the sharpest frames for stacking.

### Adaptive Weighting
When this option is selected, frames will be weighted based on their sharpness and overall quality—higher-quality frames will contribute more to the final stacked image. When the option is deselected, all frames will be given equal weight in the stack, regardless of quality.

### Stack
Begins the alignment and stacking process. When complete, you can choose to save the stacked image or open it in the Image Editor for further processing.

## Batch Stacking Tool

### Post Processing
The Batch Stacking tool can apply a saved processing preset (`.pssettings`) to each stacked result before writing output files.

- Enable **Apply Processing Settings**.
- Click **Load Settings...** and choose a preset file.
- Run **Stack** to write processed outputs.

Preset application affects processing controls only. Crop and rotation are not included in presets.

### Output Files
Batch stacking can save stacked results as FITS, TIFF, or `psImage`.

- Choose **psImage** when you want to keep the stacked source data editable in Planet Stacker X.
- If **Apply Processing Settings** is enabled, the selected settings are embedded in the saved `psImage` file instead of being flattened into the pixel data.

## Sharpness Graph

Below the playback window is a sharpness graph, showing frame quality throughout the video. Sharpness quality is relative to frames in the stack; a poor-quality video will still have sharp "green" frames and a high-quality video will still have some "red" frames. Avoid comparing sharpness quality across different videos based on this graph.
