# ming053l/flashrefocus architecture

> Architecture diagram of the GitHub repository ming053l/flashrefocus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ming053l/flashrefocus
- Repository: https://github.com/ming053l/flashrefocus

## Overview

FlashReFocus is an interactive image-refocusing system: prepare an image by restoring it and estimating depth, then produce edits by changing the focus/depth conditions and rendering. Its documented capabilities include focal-plane, aperture, tilt-shift and mask edits, video spotlight, and ComfyUI integration; training code is also present. The graph emphasizes inference and its user-facing routes. Source excerpts and the SOURCE INDEX support the main inference links; some video and training relationships are documented or indexed rather than shown in excerpts.

Main entry points: [`flashrefocus/pipeline.py`](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/pipeline.py) (Refocuser pipeline), [`flashrefocus/video.py`](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/video.py) (Video spotlight), [`comfyui/nodes.py`](https://github.com/ming053l/FlashReFocus/blob/main/comfyui/nodes.py) (ComfyUI nodes), [`flashrefocus/rendering/renderer.py`](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/renderer.py) (Bokeh renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Refocus inference"]
  node_pipeline["Refocuser pipeline<br/>[pipeline.py]"]
  node_io["Image I/O<br/>[image_io.py]"]
  node_deblur["Image restoration<br/>[deblurrer.py]"]
  node_diffusion["One-step diffusion"]
  node_refiner["Decoder refiner<br/>[decoder_refiner.py]"]
  node_depth["Depth estimation<br/>[depth.py]"]
  node_renderer["Bokeh renderer<br/>[renderer.py]"]
  node_attention["Defocus attention"]
end

subgraph group_editing["Focus editing"]
  node_edits["Depth edits<br/>[depth_edits.py]"]
  node_segmentation["Mask segmentation<br/>[segment.py]"]
  node_video["Video spotlight<br/>[video.py]"]
  node_overlay["Video overlays<br/>[overlays.py]"]
end

subgraph group_interfaces["User interfaces"]
  node_cli["Refocus CLI<br/>[refocus.py]"]
  node_comfy["ComfyUI nodes<br/>[nodes.py]"]
end

subgraph group_training["Model training"]
  node_stage1data["Restoration data<br/>[deblurring_data.py]"]
  node_stage1train["Restoration training"]
  node_renderdata["Renderer data<br/>[rendering_data.py]"]
  node_rendertrain["Renderer training<br/>[train_renderer.py]"]
end

node_user(("User"))

node_user -->|"runs"| node_cli
node_cli -->|"invokes"| node_pipeline
node_pipeline -->|"reads and saves"| node_io
node_pipeline -->|"restores with"| node_deblur
node_pipeline -->|"estimates depth"| node_depth
node_pipeline -->|"samples focus"| node_edits
node_pipeline -->|"renders edits"| node_renderer
node_deblur -->|"predicts latent"| node_diffusion
node_deblur -->|"refines decode"| node_refiner
node_renderer -->|"uses attention"| node_attention
node_user -->|"uses nodes"| node_comfy
node_comfy -->|"prepares scenes"| node_pipeline
node_comfy -->|"applies edits"| node_edits
node_comfy -->|"uses masks"| node_segmentation
node_video -.->|"tracks depth"| node_depth
node_video -.->|"renders frames"| node_renderer
node_video -.->|"uses subject masks"| node_segmentation
node_video -.->|"uses overlays"| node_overlay
node_stage1train -->|"trains on"| node_stage1data
node_rendertrain -->|"trains on"| node_renderdata
node_rendertrain -->|"trains model"| node_renderer

click node_cli "https://github.com/ming053l/FlashReFocus/blob/main/scripts/refocus.py"
click node_comfy "https://github.com/ming053l/FlashReFocus/blob/main/comfyui/nodes.py"
click node_pipeline "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/pipeline.py"
click node_io "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/image_io.py"
click node_deblur "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/deblurrer.py"
click node_diffusion "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/one_step_diffusion.py"
click node_refiner "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/decoder_refiner.py"
click node_depth "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/depth.py"
click node_renderer "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/renderer.py"
click node_attention "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/defocus_bias_attention.py"
click node_edits "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/depth_edits.py"
click node_segmentation "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/segment.py"
click node_video "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/video.py"
click node_overlay "https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/overlays.py"
click node_stage1data "https://github.com/ming053l/FlashReFocus/blob/main/training/deblurring_data.py"
click node_stage1train "https://github.com/ming053l/FlashReFocus/blob/main/training/train_deblurring.py"
click node_renderdata "https://github.com/ming053l/FlashReFocus/blob/main/training/rendering_data.py"
click node_rendertrain "https://github.com/ming053l/FlashReFocus/blob/main/training/train_renderer.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pipeline,node_io,node_deblur,node_diffusion,node_refiner,node_depth,node_renderer,node_attention,node_user toneBlue
class node_edits,node_segmentation,node_video,node_overlay toneAmber
class node_cli,node_comfy toneMint
class node_stage1data,node_stage1train,node_renderdata,node_rendertrain toneRose
```

## Components

### Refocus inference

- [Refocuser pipeline](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/pipeline.py): `flashrefocus/pipeline.py`
- [Image I/O](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/image_io.py): `flashrefocus/image_io.py`
- [Image restoration](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/deblurrer.py): `flashrefocus/deblurring/deblurrer.py`
- [One-step diffusion](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/one_step_diffusion.py): `flashrefocus/deblurring/one_step_diffusion.py`
- [Decoder refiner](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/deblurring/decoder_refiner.py): `flashrefocus/deblurring/decoder_refiner.py`
- [Depth estimation](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/depth.py): `flashrefocus/rendering/depth.py`
- [Bokeh renderer](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/renderer.py): `flashrefocus/rendering/renderer.py`
- [Defocus attention](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/defocus_bias_attention.py): `flashrefocus/rendering/defocus_bias_attention.py`

### Focus editing

- [Depth edits](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/rendering/depth_edits.py): `flashrefocus/rendering/depth_edits.py`
- [Mask segmentation](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/segment.py): `flashrefocus/segment.py`
- [Video spotlight](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/video.py): `flashrefocus/video.py`
- [Video overlays](https://github.com/ming053l/FlashReFocus/blob/main/flashrefocus/overlays.py): `flashrefocus/overlays.py`

### User interfaces

- [Refocus CLI](https://github.com/ming053l/FlashReFocus/blob/main/scripts/refocus.py): `scripts/refocus.py`
- [ComfyUI nodes](https://github.com/ming053l/FlashReFocus/blob/main/comfyui/nodes.py): `comfyui/nodes.py`

### Model training

- [Restoration data](https://github.com/ming053l/FlashReFocus/blob/main/training/deblurring_data.py): `training/deblurring_data.py`
- [Restoration training](https://github.com/ming053l/FlashReFocus/blob/main/training/train_deblurring.py): `training/train_deblurring.py`
- [Renderer data](https://github.com/ming053l/FlashReFocus/blob/main/training/rendering_data.py): `training/rendering_data.py`
- [Renderer training](https://github.com/ming053l/FlashReFocus/blob/main/training/train_renderer.py): `training/train_renderer.py`

### Other components

- **User**

## Connections

- User → Refocus CLI: runs
- Refocus CLI → Refocuser pipeline: invokes (evidence: `scripts/refocus.py`)
- Refocuser pipeline → Image I/O: reads and saves (evidence: `flashrefocus/pipeline.py`)
- Refocuser pipeline → Image restoration: restores with (evidence: `flashrefocus/pipeline.py`)
- Refocuser pipeline → Depth estimation: estimates depth (evidence: `flashrefocus/pipeline.py`)
- Refocuser pipeline → Depth edits: samples focus (evidence: `flashrefocus/pipeline.py`)
- Refocuser pipeline → Bokeh renderer: renders edits (evidence: `flashrefocus/pipeline.py`)
- Image restoration → One-step diffusion: predicts latent (evidence: `flashrefocus/deblurring/deblurrer.py`)
- Image restoration → Decoder refiner: refines decode (evidence: `flashrefocus/deblurring/deblurrer.py`)
- Bokeh renderer → Defocus attention: uses attention (evidence: `flashrefocus/rendering/renderer.py`)
- User → ComfyUI nodes: uses nodes
- ComfyUI nodes → Refocuser pipeline: prepares scenes (evidence: `comfyui/nodes.py`)
- ComfyUI nodes → Depth edits: applies edits (evidence: `comfyui/nodes.py`)
- ComfyUI nodes → Mask segmentation: uses masks (evidence: `comfyui/nodes.py`)
- Video spotlight → Depth estimation: tracks depth
- Video spotlight → Bokeh renderer: renders frames
- Video spotlight → Mask segmentation: uses subject masks
- Video spotlight → Video overlays: uses overlays
- Restoration training → Restoration data: trains on (evidence: `training/train_deblurring.py`)
- Renderer training → Renderer data: trains on (evidence: `training/train_renderer.py`)
- Renderer training → Bokeh renderer: trains model (evidence: `training/train_renderer.py`)
