File size: 13,162 Bytes
a6c1a9f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | # Batch Generation of Orthographic Images from 3DGS Models
This guide describes how to generate top-down orthographic images from trained 3D Gaussian Splatting (3DGS) models. The batch commands invoke `render_ortho.py` for each scene and preserve the original scene directory names.
## Prerequisites
- Bash on Linux.
- The existing `3dgs` Conda environment with the dependencies required by `render_ortho.py`, including CUDA and gsplat.
- The rendering script located in the project directory.
- A trained 3DGS model and `cameras.json` for each scene.
## Input Directory Structure
```text
<dataset>/train/3DGS/
├── <scene_id>/
│ └── model/
│ ├── cameras.json
│ └── point_cloud/
│ └── iteration_7000/
│ └── point_cloud.ply
└── ...
```
## Rendering Configuration
| Parameter | Value |
| --- | --- |
| Image size | 2048 × 2048 pixels |
| Center crop ratio | 0.6 |
| Model iteration | 7000 |
| Rendering device | `cuda:0` |
| Processing mode | Sequential, one scene at a time |
## 1. Render the SUES 150 m Dataset
Run the following commands in a Bash terminal.
```bash
conda activate 3dgs
cd /media/liutao/A/demo/OCT
(
# ==================== Parameter configuration ====================
SRC="/media/liutao/A/demo/OCT/Datasets/150/train/3DGS"
DST="/media/liutao/A/demo/OCT/Datasets/U1652/train/SUES150_Ortho"
SCRIPT="/media/liutao/A/demo/OCT/3DGS重建/render_ortho.py"
SIZE=2048
CENTER_RATIO=0.6
ITERATION=7000
# ==================== Initialization ====================
if [[ ! -d "$SRC" || ! -f "$SCRIPT" ]]; then
echo "Input directory or rendering script not found"
exit 1
fi
mkdir -p "$DST"
shopt -s nullglob
scenes=("$SRC"/*/)
total=${#scenes[@]}
current=0
success=0
skipped=0
failed=0
FAILED_LOG="$DST/failed.txt"
> "$FAILED_LOG"
trap 'echo "Batch interrupted. Completed scenes will be skipped on restart."; exit 130' INT
echo "=================================================="
echo "3DGS Batch Orthographic Rendering"
echo "Input directory: $SRC"
echo "Output directory: $DST"
echo "Number of scenes: $total"
echo "Output resolution: ${SIZE} × ${SIZE}"
echo "Center crop ratio: $CENTER_RATIO"
echo "=================================================="
# ==================== Iterate over scenes ====================
for scene_dir in "${scenes[@]}"; do
scene=$(basename "$scene_dir")
current=$((current + 1))
ply="$scene_dir/model/point_cloud/iteration_${ITERATION}/point_cloud.ply"
cameras="$scene_dir/model/cameras.json"
out_dir="$DST/$scene"
output="$out_dir/ortho.png"
echo ""
echo "=================================================="
echo "[$current/$total] Current scene: $scene"
echo "=================================================="
# Check existing outputs to support resuming
if [[ -f "$out_dir/.complete" && \
-s "$output" && \
-s "$out_dir/ortho.alpha.png" && \
-s "$out_dir/ortho.json" ]]; then
echo "Already completed; skipping"
skipped=$((skipped + 1))
continue
fi
# Check input files
if [[ ! -f "$ply" || ! -f "$cameras" ]]; then
echo "Missing PLY or cameras.json; skipping"
echo "$scene: Missing input files" >> "$FAILED_LOG"
failed=$((failed + 1))
continue
fi
# Create the corresponding scene directory
mkdir -p "$out_dir"
rm -f "$out_dir/.complete"
# ==================== Orthographic rendering ====================
if python -u "$SCRIPT" \
--ply "$ply" \
--cameras "$cameras" \
--output "$output" \
--size "$SIZE" \
--center-ratio "$CENTER_RATIO" \
--device cuda:0 \
> "$out_dir/render.log" 2>&1 \
&& [[ -s "$output" && \
-s "$out_dir/ortho.alpha.png" && \
-s "$out_dir/ortho.json" ]]; then
touch "$out_dir/.complete"
echo "Scene $scene rendered successfully"
success=$((success + 1))
else
echo "Scene $scene rendering failed"
echo "$scene: Rendering failed" >> "$FAILED_LOG"
tail -n 15 "$out_dir/render.log"
failed=$((failed + 1))
fi
echo "Successful: $success"
echo "Skipped: $skipped"
echo "Failed: $failed"
done
# ==================== Final summary ====================
echo ""
echo "=================================================="
echo "All scenes processed"
echo "=================================================="
echo "Total scenes: $total"
echo "Newly completed: $success"
echo "Previously completed: $skipped"
echo "Failed: $failed"
echo "Output directory: $DST"
echo "Failure log: $FAILED_LOG"
echo "=================================================="
)
```
## 2. Render Multiple Dataset Groups
The following commands process the SUES 100 m, 200 m, 250 m, and 300 m datasets, followed by IRVL328.
```bash
conda activate 3dgs
cd /media/liutao/A/demo/OCT
(
# ==================== Global configuration ====================
BASE="/media/liutao/A/demo/OCT"
SCRIPT="$BASE/3DGS重建/render_ortho.py"
SIZE=2048
CENTER_RATIO=0.6
ITERATION=7000
shopt -s nullglob
trap 'echo "Batch interrupted. Completed scenes will be skipped on restart."; exit 130' INT
if [[ ! -f "$SCRIPT" ]]; then
echo "Rendering script not found: $SCRIPT"
exit 1
fi
all_total=0
all_success=0
all_skipped=0
all_failed=0
# ==================== Iterate over dataset groups ====================
for height in 100 200 250 300 IRVL328; do
SRC="$BASE/Datasets/${height}/train/3DGS"
DST="$BASE/Datasets/U1652/train/SUES${height}_Ortho"
echo ""
echo "=================================================="
echo "Processing dataset group: ${height}"
echo "=================================================="
if [[ ! -d "$SRC" ]]; then
echo "Input directory not found: $SRC"
echo "Skipping current dataset group"
continue
fi
mkdir -p "$DST"
scenes=("$SRC"/*/)
total=${#scenes[@]}
current=0
success=0
skipped=0
failed=0
FAILED_LOG="$DST/failed.txt"
> "$FAILED_LOG"
echo "Input directory: $SRC"
echo "Output directory: $DST"
echo "Number of scenes: $total"
echo "Output resolution: ${SIZE} × ${SIZE}"
echo "Center crop ratio: $CENTER_RATIO"
echo "=================================================="
# ==================== Iterate over scenes ====================
for scene_dir in "${scenes[@]}"; do
scene=$(basename "$scene_dir")
current=$((current + 1))
ply="$scene_dir/model/point_cloud/iteration_${ITERATION}/point_cloud.ply"
cameras="$scene_dir/model/cameras.json"
out_dir="$DST/$scene"
output="$out_dir/ortho.png"
echo ""
echo "=================================================="
echo "Dataset group: ${height}"
echo "[$current/$total] Current scene: $scene"
echo "=================================================="
# ==================== Resume completed scenes ====================
if [[ -f "$out_dir/.complete" && \
-s "$output" && \
-s "$out_dir/ortho.alpha.png" && \
-s "$out_dir/ortho.json" ]]; then
echo "Already completed; skipping"
skipped=$((skipped + 1))
continue
fi
# ==================== Check inputs ====================
if [[ ! -f "$ply" || ! -f "$cameras" ]]; then
echo "Missing PLY or cameras.json; skipping"
echo "$scene: Missing input files" >> "$FAILED_LOG"
failed=$((failed + 1))
continue
fi
mkdir -p "$out_dir"
rm -f "$out_dir/.complete"
# ==================== Orthographic rendering ====================
if python -u "$SCRIPT" \
--ply "$ply" \
--cameras "$cameras" \
--output "$output" \
--size "$SIZE" \
--center-ratio "$CENTER_RATIO" \
--device cuda:0 \
> "$out_dir/render.log" 2>&1 \
&& [[ -s "$output" && \
-s "$out_dir/ortho.alpha.png" && \
-s "$out_dir/ortho.json" ]]; then
touch "$out_dir/.complete"
echo "Scene $scene rendered successfully"
success=$((success + 1))
else
echo "Scene $scene rendering failed"
echo "$scene: Rendering failed" >> "$FAILED_LOG"
tail -n 15 "$out_dir/render.log"
failed=$((failed + 1))
fi
echo "Group successful: $success"
echo "Group skipped: $skipped"
echo "Group failed: $failed"
done
# ==================== Current group summary ====================
echo ""
echo "=================================================="
echo "Dataset group ${height} processed"
echo "=================================================="
echo "Total scenes: $total"
echo "Newly completed: $success"
echo "Previously completed: $skipped"
echo "Failed: $failed"
echo "Output directory: $DST"
echo "Failure log: $FAILED_LOG"
echo "=================================================="
all_total=$((all_total + total))
all_success=$((all_success + success))
all_skipped=$((all_skipped + skipped))
all_failed=$((all_failed + failed))
done
# ==================== Overall summary ====================
echo ""
echo "=================================================="
echo "All dataset groups processed"
echo "=================================================="
echo "Total scenes: $all_total"
echo "Newly completed: $all_success"
echo "Previously completed: $all_skipped"
echo "Failed: $all_failed"
echo "=================================================="
)
```
### Input and Output Paths
All paths below are relative to the project's `Datasets/` directory.
| Dataset group | Input directory | Output directory |
| --- | --- | --- |
| SUES 150 m | `150/train/3DGS` | `U1652/train/SUES150_Ortho` |
| SUES 100 m | `100/train/3DGS` | `U1652/train/SUES100_Ortho` |
| SUES 200 m | `200/train/3DGS` | `U1652/train/SUES200_Ortho` |
| SUES 250 m | `250/train/3DGS` | `U1652/train/SUES250_Ortho` |
| SUES 300 m | `300/train/3DGS` | `U1652/train/SUES300_Ortho` |
| IRVL328 | `IRVL328/train/3DGS` | `U1652/train/SUESIRVL328_Ortho` |
The directory paths and naming convention are retained from the supplied commands. In particular, the original output path for IRVL328 uses the `SUES` prefix. The original non-English directory name in the rendering script path is retained because changing it would change the actual filesystem path.
## 3. Output Directory Structure
```text
<output_directory>/
├── <scene_id>/
│ ├── ortho.png
│ ├── ortho.alpha.png
│ ├── ortho.json
│ ├── render.log
│ └── .complete
├── ...
└── failed.txt
```
| File | Description |
| --- | --- |
| `ortho.png` | Rendered RGB orthographic image |
| `ortho.alpha.png` | Alpha mask |
| `ortho.json` | Rendering and projection metadata |
| `render.log` | Per-scene rendering log |
| `.complete` | Completion marker |
| `failed.txt` | List of scenes that failed during the current run |
## 4. Resuming and Error Handling
Press `Ctrl+C` to interrupt the batch. Run the same commands again to resume. A scene is skipped if its completion marker and all three nonempty output files exist.
Scenes with missing input files or rendering failures are recorded in `failed.txt`, and processing continues with the next scene. The failure log is reset when the corresponding dataset group is processed again.
Do not remove the completion markers, alpha masks, or metadata files before batch rendering is finished; the original resume logic relies on them.
## Notes
- The commands do not retrain or modify the original 3DGS models.
- A center crop ratio of 0.6 is applied uniformly; this does not guarantee the same physical ground coverage across scenes.
- The output images are orthographic renderings, not georeferenced mapping products unless a separate georeferencing procedure is applied.
|