Spaces:
Running
Running
File size: 13,200 Bytes
dcca177 5d2240d 0697273 5d2240d 0697273 5d2240d 15daaf3 5d2240d 15daaf3 5d2240d dcca177 | 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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="Image segmentation mini-lab: compare classic thresholding, semantic, instance, and promptable segmentation on one image"
/>
<title>AI-Powered Image Segmentation</title>
<link
rel="icon"
href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>✂️</text></svg>"
/>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<main class="page-shell">
<!-- =========================================================
HERO
========================================================== -->
<header class="hero">
<p class="eyebrow">
Creative Technology · Computer Vision
</p>
<h1>
AI-Powered<br />
Image Segmentation
</h1>
<p class="lede">
Four ways to answer the same question:
<strong>which pixels belong to what?</strong>
Start with a hand-written threshold rule,
then hand the job to three pretrained models.
</p>
<div class="lesson-strip" aria-label="Mini-lab overview">
<span>
<b>Task</b>
Image segmentation
</span>
<span>
<b>Data</b>
COCO validation examples
</span>
<span>
<b>Methods</b>
Threshold · SegFormer · MaskFormer · SlimSAM
</span>
</div>
</header>
<!-- =========================================================
MAIN WORKSPACE
========================================================== -->
<section class="workspace" aria-label="Image segmentation mini-lab">
<!-- =======================================================
LEFT: CONTROLS
======================================================== -->
<div class="controls card">
<!-- STEP 1 -->
<div class="step">
<span class="step-number">1</span>
<div>
<p class="control-label sample-title">
Choose an image
</p>
<p class="helper">
Start with a tested example, or try a photo of your own.
</p>
</div>
</div>
<div class="sample-head coco-head">
<div>
<p class="input-kicker">
Start here · COCO examples
</p>
<p class="helper">
Four images are drawn at random from 24 bundled
COCO validation examples.
</p>
</div>
<button id="shuffle-examples" class="shuffle-button" type="button">
Shuffle
</button>
</div>
<div
id="sample-grid"
class="sample-grid"
aria-label="COCO example images"
></div>
<div class="or-row">
<span>or try your own</span>
</div>
<label class="control-label" for="image-input">
Upload an image
</label>
<p class="helper">
Useful for seeing where a model trained on one dataset
stops making sense.
</p>
<input
id="image-input"
class="file-input"
type="file"
accept="image/*"
/>
<div class="divider"></div>
<!-- STEP 2 -->
<div class="step">
<span class="step-number">2</span>
<div class="grow">
<p class="control-label sample-title">
Choose a method
</p>
<p class="helper">
Same image, four different ideas about what a segment is.
</p>
</div>
</div>
<div
id="experiment-grid"
class="experiment-grid"
role="radiogroup"
aria-label="Segmentation method"
></div>
<div class="experiment-note">
<p id="experiment-blurb" class="helper"></p>
<p id="experiment-note" class="helper note-sub" hidden></p>
</div>
<!-- DYNAMIC CONTROLS -->
<div class="divider"></div>
<div id="panel-threshold" class="panel" hidden>
<label class="control-label" for="threshold-method">
Threshold rule
</label>
<select id="threshold-method" class="model-select">
<option value="otsu">Otsu — automatic cutoff</option>
<option value="binary">Binary — manual cutoff</option>
<option value="adaptive">Adaptive — local mean</option>
</select>
<div id="threshold-manual" hidden>
<div class="slider-row">
<label for="cutoff">Grey level</label>
<output id="cutoff-value" for="cutoff">128</output>
</div>
<input id="cutoff" type="range" min="1" max="254" value="128" />
</div>
<div id="threshold-adaptive" hidden>
<div class="slider-row">
<label for="block-size">Window size</label>
<output id="block-size-value" for="block-size">35</output>
</div>
<input id="block-size" type="range" min="5" max="101" step="2" value="35" />
<div class="slider-row">
<label for="adaptive-c">Sensitivity</label>
<output id="adaptive-c-value" for="adaptive-c">10</output>
</div>
<input id="adaptive-c" type="range" min="0" max="30" value="10" />
</div>
<label class="check">
<input id="invert" type="checkbox" />
Invert — make dark pixels the object
</label>
<label class="check">
<input id="denoise" type="checkbox" checked />
Clean up noise (open, then close)
</label>
<div class="histogram-wrap">
<canvas id="histogram" aria-label="Greyscale histogram"></canvas>
<p class="helper">
Pixel brightness distribution. The marker shows where the
threshold falls.
</p>
</div>
</div>
<div id="panel-segformer" class="panel" hidden>
<p class="helper">
There is nothing to tune. SegFormer runs at a fixed input size and
returns its best guess per pixel.
</p>
</div>
<div id="panel-maskformer" class="panel" hidden>
<div class="slider-row">
<label for="confidence">Confidence threshold</label>
<output id="confidence-value" for="confidence">0.50</output>
</div>
<input
id="confidence"
type="range"
min="0.10"
max="0.95"
step="0.05"
value="0.50"
/>
<p class="helper">
Lower values keep more objects, including ones the model is
guessing at.
</p>
</div>
<div id="panel-sam" class="panel" hidden>
<p class="helper">
Run once to compute the image embedding, then
<strong>click anywhere on the picture</strong> to segment the object
under your cursor. Each click is independent — try a few.
</p>
</div>
<!-- RUN BUTTON -->
<button id="run-button" class="run-button" type="button" disabled>
Run Segmentation
</button>
<!-- STATUS -->
<p id="status" class="status" aria-live="polite">
Choose a COCO example or upload your own image.
</p>
<!-- PROGRESS -->
<div id="progress-wrap" class="progress-wrap" hidden>
<div id="progress-bar" class="progress-bar"></div>
</div>
</div>
<!-- =======================================================
RIGHT: RESULT
======================================================== -->
<div class="result card">
<div class="result-head">
<div>
<p class="section-kicker" id="result-kicker">
Result
</p>
<h2 id="result-title">
Run a method to see its segments
</h2>
</div>
<span id="runtime-badge" class="badge">
Waiting
</span>
</div>
<div
id="view-switch"
class="view-switch"
role="radiogroup"
aria-label="What the canvas shows"
hidden
>
<button
type="button"
class="view-option selected"
data-view="overlay"
role="radio"
aria-checked="true"
>
Photo + mask
</button>
<button
type="button"
class="view-option"
data-view="mask"
role="radio"
aria-checked="false"
>
Mask only
</button>
<button
type="button"
class="view-option"
data-view="original"
role="radio"
aria-checked="false"
>
Photo only
</button>
</div>
<div id="canvas-wrap" class="canvas-wrap empty">
<canvas id="result-canvas" aria-label="Segmentation result"></canvas>
<p id="canvas-placeholder">
Choose an image first.
The original image appears here before you run anything.
</p>
</div>
<p id="sam-hint" class="sam-hint" hidden>
Click the image to segment the object under your cursor.
</p>
<div id="summary" class="summary">
No result yet.
</div>
<div class="table-wrap">
<table>
<thead>
<tr id="table-head">
<th>Segment</th>
<th>Detail</th>
</tr>
</thead>
<tbody id="detections-body">
<tr class="empty-row">
<td colspan="2">
Run a method to see its segments.
</td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<!-- =========================================================
COMPARISON
========================================================== -->
<section class="compare card">
<div class="compare-head">
<div>
<p class="section-kicker">
Compare
</p>
<h2>
The same image, four ways
</h2>
</div>
<button id="clear-compare" class="shuffle-button" type="button">
Clear
</button>
</div>
<p class="helper compare-lede">
Every run is kept here, so you can put the four methods side by side
without re-running them.
</p>
<div id="compare-grid" class="compare-grid">
<p class="compare-empty">
Run a method and its result will appear here.
</p>
</div>
</section>
<!-- =========================================================
EXPLANATION
========================================================== -->
<section class="explain card">
<p class="section-kicker">
What you are doing
</p>
<h2 class="explain-title">
Segmentation asks a harder question than detection.
Not "is there a cat?" but "exactly which pixels are the cat?"
</h2>
<p class="explain-copy">
A detector draws a box around an object. A segmenter has to decide,
pixel by pixel, where that object ends — which is why the four methods
here disagree so much. Thresholding uses one hand-chosen rule about
brightness. SegFormer labels every pixel with a scene class but cannot
tell two people apart. MaskFormer predicts one mask per object.
SlimSAM takes a click as its question and returns whatever object sits
under that point, without any fixed class list.
</p>
<div class="flow" aria-label="Segmentation progression">
<span>1 hand-written rule</span>
<span class="arrow">→</span>
<span>2 classes per pixel</span>
<span class="arrow">→</span>
<span>3 one mask per object</span>
<span class="arrow">→</span>
<span>4 mask on request</span>
</div>
<p class="extension-note">
<strong>Try this:</strong>
run Threshold on an image with uneven lighting, then run it again on a
clean studio-like scene. The rule does not change — only the picture
does. That gap is the reason the other three methods exist.
</p>
</section>
<!-- =========================================================
FOOTER
========================================================== -->
<footer>
Hosted as a Hugging Face Static Space ·
Powered by Transformers.js
</footer>
</main>
<script type="module" src="./app.js"></script>
</body>
</html>
|