Run a single OSInsert inference. Parameters ---------- background_path: Path to the background image. foreground_path: Path to the foreground image used as the InsertAnything reference image. foreground_mask_path:
(
self,
background_path: str | Path,
foreground_path: str | Path,
foreground_mask_path: str | Path,
bbox_txt_path: str | Path,
result_dir: str | Path,
mode: Literal["aggressive", "conservative"] = "conservative",
cleanup_intermediate: bool = True,
verbose: bool = False,
seed: int = 123,
strength: float = 1.0,
split_ratio: float = 0.5,
)
| 135 | return self._sam_predictor |
| 136 | |
| 137 | def __call__( |
| 138 | self, |
| 139 | background_path: str | Path, |
| 140 | foreground_path: str | Path, |
| 141 | foreground_mask_path: str | Path, |
| 142 | bbox_txt_path: str | Path, |
| 143 | result_dir: str | Path, |
| 144 | mode: Literal["aggressive", "conservative"] = "conservative", |
| 145 | cleanup_intermediate: bool = True, |
| 146 | verbose: bool = False, |
| 147 | seed: int = 123, |
| 148 | strength: float = 1.0, |
| 149 | split_ratio: float = 0.5, |
| 150 | ) -> np.ndarray | None: |
| 151 | """Run a single OSInsert inference. |
| 152 | |
| 153 | Parameters |
| 154 | ---------- |
| 155 | background_path: |
| 156 | Path to the background image. |
| 157 | foreground_path: |
| 158 | Path to the foreground image used as the InsertAnything reference |
| 159 | image. |
| 160 | foreground_mask_path: |
| 161 | Binary mask for the foreground image. |
| 162 | bbox_txt_path: |
| 163 | Text file containing ``x1 y1 x2 y2`` on a single line, specifying the |
| 164 | insertion region on the background image. |
| 165 | result_dir: |
| 166 | Directory where the final composed image will be written. |
| 167 | mode: |
| 168 | - ``"conservative"``: background + bbox -> mask -> InsertAnything. |
| 169 | - ``"aggressive"``: ObjectStitch + SAM -> combined source/mask -> |
| 170 | InsertAnything. |
| 171 | cleanup_intermediate: |
| 172 | Deprecated. Present for backward compatibility. |
| 173 | verbose: |
| 174 | If True, save intermediate artifacts into ``result_dir/intermediates``. |
| 175 | Default False (do not save intermediates). |
| 176 | seed: |
| 177 | Random seed for InsertAnything. |
| 178 | strength: |
| 179 | InsertAnything strength parameter. |
| 180 | """ |
| 181 | |
| 182 | if mode not in {"aggressive", "conservative"}: |
| 183 | raise ValueError(f"Unsupported mode: {mode}") |
| 184 | |
| 185 | # ------------------------------------------------------------------ |
| 186 | # Path normalization and output directory. |
| 187 | # ------------------------------------------------------------------ |
| 188 | background_path = Path(background_path) |
| 189 | foreground_path = Path(foreground_path) |
| 190 | foreground_mask_path = Path(foreground_mask_path) |
| 191 | bbox_txt_path = Path(bbox_txt_path) |
| 192 | result_dir = Path(result_dir) |
| 193 | |
| 194 | os.makedirs(result_dir, exist_ok=True) |
nothing calls this directly
no test coverage detected