# mahaqj/scene-manipulation architecture

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

- Interactive diagram: https://gitdiagram.com/mahaqj/scene-manipulation
- Repository: https://github.com/mahaqj/scene-manipulation

## Overview

This repository is a command-line scene-manipulation prototype: a user supplies an image and natural-language relocation instruction, and the pipeline parses the instruction, detects and segments the target, removes and relocates it, then displays the result. README documents DETR detection and Stable Diffusion inpainting; relighting is explicitly not implemented. The graph includes SAM’s principal inference layers and automatic-mask path. Scene-pipeline links rely on README documentation; internal links are limited to shown calls or SOURCE INDEX references.

Main entry points: [`segment-anything/scene_manip.py`](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py) (Scene CLI), [`segment-anything/segment_anything/build_sam.py`](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/build_sam.py) (SAM builder), [`segment-anything/segment_anything/modeling/sam.py`](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/sam.py) (SAM model core), [`segment-anything/segment_anything/predictor.py`](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/predictor.py) (SAM predictor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Scene workflow"]
  node_scene_cli["Scene CLI<br/>[scene_manip.py]"]
  node_instruction_parser["Instruction parsing<br/>[scene_manip.py]"]
  node_object_detection["Object detection<br/>[scene_manip.py]"]
  node_sam_segmentation["SAM segmentation<br/>[predictor.py]"]
  node_object_cutout["Object cutout<br/>[scene_manip.py]"]
  node_scene_inpainting["Scene inpainting<br/>[scene_manip.py]"]
  node_object_relocation["Object relocation<br/>[scene_manip.py]"]
  node_relighting["Relighting &#40;planned&#41;<br/>[scene_manip.py]"]
  node_result_display["Result display<br/>[scene_manip.py]"]
end

subgraph group_sam_runtime["SAM runtime"]
  node_sam_builder["SAM builder<br/>[build_sam.py]"]
  node_sam_predictor["SAM predictor<br/>[predictor.py]"]
  node_automatic_masks["Automatic masks"]
end

subgraph group_sam_model["SAM model"]
  node_sam_model_core["SAM model core<br/>[sam.py]"]
  node_image_encoder["Image encoder<br/>[image_encoder.py]"]
  node_prompt_encoder["Prompt encoder<br/>[prompt_encoder.py]"]
  node_mask_decoder["Mask decoder<br/>[mask_decoder.py]"]
  node_two_way_transformer["Two-way transformer<br/>[transformer.py]"]
end

subgraph group_sam_support["SAM support"]
  node_mask_utilities["Mask utilities<br/>[amg.py]"]
  node_image_transforms["Image transforms<br/>[transforms.py]"]
  node_model_common["Model layers<br/>[common.py]"]
end

node_user(("User"))
node_detr["DETR"]
node_stable_diffusion["Stable Diffusion"]

node_user -->|"provides inputs"| node_scene_cli
node_scene_cli -->|"parses instruction"| node_instruction_parser
node_scene_cli -->|"requests detection"| node_object_detection
node_object_detection -->|"detects object"| node_detr
node_scene_cli -->|"requests mask"| node_sam_segmentation
node_sam_segmentation -->|"uses predictor"| node_sam_predictor
node_sam_predictor -->|"runs inference"| node_sam_model_core
node_scene_cli -->|"cuts out object"| node_object_cutout
node_scene_cli -->|"inpaints region"| node_scene_inpainting
node_scene_inpainting -->|"uses inpainting"| node_stable_diffusion
node_scene_cli -->|"repositions object"| node_object_relocation
node_scene_cli -->|"displays results"| node_result_display
node_scene_cli -.->|"leaves unimplemented"| node_relighting
node_sam_builder -->|"constructs"| node_image_encoder
node_sam_builder -->|"constructs"| node_prompt_encoder
node_sam_builder -->|"constructs"| node_mask_decoder
node_sam_builder -->|"constructs"| node_two_way_transformer
node_sam_model_core -->|"encodes image"| node_image_encoder
node_sam_model_core -->|"encodes prompts"| node_prompt_encoder
node_sam_model_core -->|"predicts masks"| node_mask_decoder
node_mask_decoder -->|"uses transformer"| node_two_way_transformer
node_image_encoder -->|"uses layers"| node_model_common
node_prompt_encoder -->|"uses layers"| node_model_common
node_mask_decoder -->|"uses layers"| node_model_common
node_two_way_transformer -->|"uses layers"| node_model_common
node_automatic_masks -->|"uses predictor"| node_sam_predictor
node_automatic_masks -->|"uses utilities"| node_mask_utilities
node_sam_predictor -->|"uses transforms"| node_image_transforms

click node_scene_cli "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_instruction_parser "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_object_detection "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_sam_segmentation "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/predictor.py"
click node_object_cutout "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_scene_inpainting "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_object_relocation "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_relighting "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_result_display "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py"
click node_sam_builder "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/build_sam.py"
click node_sam_predictor "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/predictor.py"
click node_automatic_masks "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/automatic_mask_generator.py"
click node_mask_utilities "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/utils/amg.py"
click node_image_transforms "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/utils/transforms.py"
click node_sam_model_core "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/sam.py"
click node_image_encoder "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/image_encoder.py"
click node_prompt_encoder "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/prompt_encoder.py"
click node_mask_decoder "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/mask_decoder.py"
click node_two_way_transformer "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/transformer.py"
click node_model_common "https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/common.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_scene_cli,node_instruction_parser,node_object_detection,node_sam_segmentation,node_object_cutout,node_scene_inpainting,node_object_relocation,node_relighting,node_result_display,node_user toneBlue
class node_sam_builder,node_sam_predictor,node_automatic_masks toneAmber
class node_sam_model_core,node_image_encoder,node_prompt_encoder,node_mask_decoder,node_two_way_transformer toneMint
class node_mask_utilities,node_image_transforms,node_model_common toneRose
class node_detr,node_stable_diffusion toneIndigo
```

## Components

### Scene workflow

- [Scene CLI](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Instruction parsing](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Object detection](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [SAM segmentation](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/predictor.py): `segment-anything/segment_anything/predictor.py`
- [Object cutout](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Scene inpainting](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Object relocation](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Relighting (planned)](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`
- [Result display](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/scene_manip.py): `segment-anything/scene_manip.py`

### SAM runtime

- [SAM builder](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/build_sam.py): `segment-anything/segment_anything/build_sam.py`
- [SAM predictor](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/predictor.py): `segment-anything/segment_anything/predictor.py`
- [Automatic masks](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/automatic_mask_generator.py): `segment-anything/segment_anything/automatic_mask_generator.py`

### SAM model

- [SAM model core](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/sam.py): `segment-anything/segment_anything/modeling/sam.py`
- [Image encoder](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/image_encoder.py): `segment-anything/segment_anything/modeling/image_encoder.py`
- [Prompt encoder](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/prompt_encoder.py): `segment-anything/segment_anything/modeling/prompt_encoder.py`
- [Mask decoder](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/mask_decoder.py): `segment-anything/segment_anything/modeling/mask_decoder.py`
- [Two-way transformer](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/transformer.py): `segment-anything/segment_anything/modeling/transformer.py`

### SAM support

- [Mask utilities](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/utils/amg.py): `segment-anything/segment_anything/utils/amg.py`
- [Image transforms](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/utils/transforms.py): `segment-anything/segment_anything/utils/transforms.py`
- [Model layers](https://github.com/mahaqj/scene-manipulation/blob/master/segment-anything/segment_anything/modeling/common.py): `segment-anything/segment_anything/modeling/common.py`

### Other components

- **User**
- **DETR**
- **Stable Diffusion**

## Connections

- User → Scene CLI: provides inputs (evidence: `README.md`)
- Scene CLI → Instruction parsing: parses instruction (evidence: `README.md`)
- Scene CLI → Object detection: requests detection (evidence: `README.md`)
- Object detection → DETR: detects object (evidence: `README.md`)
- Scene CLI → SAM segmentation: requests mask (evidence: `README.md`)
- SAM segmentation → SAM predictor: uses predictor (evidence: `segment-anything/segment_anything/__init__.py`)
- SAM predictor → SAM model core: runs inference
- Scene CLI → Object cutout: cuts out object (evidence: `README.md`)
- Scene CLI → Scene inpainting: inpaints region (evidence: `README.md`)
- Scene inpainting → Stable Diffusion: uses inpainting (evidence: `README.md`)
- Scene CLI → Object relocation: repositions object (evidence: `README.md`)
- Scene CLI → Result display: displays results (evidence: `README.md`)
- Scene CLI → Relighting (planned): leaves unimplemented (evidence: `README.md`)
- SAM builder → Image encoder: constructs (evidence: `segment-anything/segment_anything/build_sam.py`)
- SAM builder → Prompt encoder: constructs (evidence: `segment-anything/segment_anything/build_sam.py`)
- SAM builder → Mask decoder: constructs (evidence: `segment-anything/segment_anything/build_sam.py`)
- SAM builder → Two-way transformer: constructs (evidence: `segment-anything/segment_anything/build_sam.py`)
- SAM model core → Image encoder: encodes image (evidence: `segment-anything/segment_anything/modeling/sam.py`)
- SAM model core → Prompt encoder: encodes prompts (evidence: `segment-anything/segment_anything/modeling/sam.py`)
- SAM model core → Mask decoder: predicts masks (evidence: `segment-anything/segment_anything/modeling/sam.py`)
- Mask decoder → Two-way transformer: uses transformer
- Image encoder → Model layers: uses layers (evidence: `segment-anything/segment_anything/modeling/image_encoder.py`)
- Prompt encoder → Model layers: uses layers (evidence: `segment-anything/segment_anything/modeling/prompt_encoder.py`)
- Mask decoder → Model layers: uses layers (evidence: `segment-anything/segment_anything/modeling/mask_decoder.py`)
- Two-way transformer → Model layers: uses layers (evidence: `segment-anything/segment_anything/modeling/transformer.py`)
- Automatic masks → SAM predictor: uses predictor (evidence: `segment-anything/segment_anything/automatic_mask_generator.py`)
- Automatic masks → Mask utilities: uses utilities (evidence: `segment-anything/segment_anything/automatic_mask_generator.py`)
- SAM predictor → Image transforms: uses transforms (evidence: `segment-anything/segment_anything/predictor.py`)
