# Edge-Aware Poisson Image Editing

This repository implements Poisson image editing with an edge-aware diffusion operator that inhibits blending across strong edges in either source or target. `main.py` contains implementations of two methods:
- `pie`: Poisson Image Editing.
- `ours`: edge-aware Perona–Malik diffusion with sensitivity parameter `kappa`, with standard Poisson Image Editing recovered as `kappa` goes to infinity (practically, `kappa=1.0` is visually indistinguishable from PIE).

## Prerequisites
- Python 3.9+ 
- Install dependencies:
  ```bash
  pip install -r requirements.txt
  ```

## Data Layout
Place your images in a data subfolder, e.g. `data/cloud/`, with filenames:
- `source.png`
- `target.png`
- `mask.png` (binary/soft mask; values > 0.5 are treated as inside the region)
The mask is easily constructed using the program GIMP by creating a black layer, hiding, lasso selecting the source, pressing 'Enter', and using the bucket tool to fill in the mask region. 

## Running
From the repo root:

Edge-aware (ours):
```bash
python main.py --data_dir data/cloud --method ours --kappa 0.02
```

Classical Poisson (pie):
```bash
python main.py --data_dir data/cloud --method pie
```

Outputs are written to the same `data_dir` unless `--output` is provided:
- `result_ours_kappa_<kappa>.png` for `ours`
- `result_pie.png` for `pie`

## CLI Options (main.py)
- `--data_dir`: Path to folder containing `source.png`, `target.png`, `mask.png` (required).
- `--method`: `pie` or `ours` (required).
- `--kappa`: Perona–Malik contrast parameter (only for `ours`, default `0.02`).
- `--gradient-mode`: `max`, `alpha`, or `source` (default `alpha`). All reported results use `--gradient-mode alpha`; `max` or varying `alpha` implement mixed gradients that can make the source object appear more transparent.
- `--gradient-alpha`: Alpha for gradient mixing when `gradient-mode=alpha` (default `1.0`).
- `--output`: Optional output filename.