# Image Stacking Guide

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

Currently, the Image Stacking tool works with RAW data in either SER or uncompressed RAW AVI format. Most astrophotography cameras and software support these formats. 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.

## 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.
