learnANDlive's picture
Upload folder using huggingface_hub
15daaf3 verified
Raw History Blame Contribute Delete
13.2 kB
<!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>