2026-05-18-17-40-02 构建导丝分割Web系统

This commit is contained in:
2026-05-18 17:49:30 +08:00
commit debd0bfd50
22 changed files with 1349 additions and 0 deletions

107
frontend/app.js Normal file
View File

@@ -0,0 +1,107 @@
const form = document.querySelector("#segmentForm");
const methodSelect = document.querySelector("#method");
const sensitivity = document.querySelector("#sensitivity");
const sensitivityValue = document.querySelector("#sensitivityValue");
const fileInput = document.querySelector("#file");
const fileName = document.querySelector("#fileName");
const resultGrid = document.querySelector("#resultGrid");
const emptyState = document.querySelector("#emptyState");
const videoLink = document.querySelector("#videoLink");
const health = document.querySelector("#health");
const template = document.querySelector("#resultCardTemplate");
const methodLabels = new Map();
function setBusy(isBusy) {
const button = form.querySelector("button");
button.disabled = isBusy;
button.querySelector("span").textContent = isBusy ? "分割中" : "开始分割";
}
async function loadHealth() {
try {
const response = await fetch("/api/health");
if (!response.ok) throw new Error("bad health");
const data = await response.json();
health.textContent = `${data.service} ${data.version}`;
health.classList.add("ok");
} catch {
health.textContent = "服务不可用";
health.classList.add("bad");
}
}
async function loadMethods() {
const response = await fetch("/api/methods");
const data = await response.json();
methodSelect.innerHTML = "";
Object.entries(data.methods).forEach(([key, value]) => {
methodLabels.set(key, value.label);
const option = document.createElement("option");
option.value = key;
option.textContent = value.label;
if (key === "fusion") option.selected = true;
methodSelect.appendChild(option);
});
}
function renderResults(data) {
resultGrid.innerHTML = "";
emptyState.hidden = true;
videoLink.hidden = !data.video_url;
if (data.video_url) {
videoLink.href = data.video_url;
videoLink.setAttribute("download", "");
}
data.frames.forEach((frame) => {
const node = template.content.firstElementChild.cloneNode(true);
node.querySelector(".method").textContent = methodLabels.get(frame.method) || frame.method;
node.querySelector(".frame-index").textContent = `${frame.frame_index}`;
node.querySelector(".overlay").src = frame.overlay_url;
node.querySelector(".mask").src = frame.mask_url;
node.querySelector(".coverage").textContent = `${(frame.metrics.coverage * 100).toFixed(3)}%`;
node.querySelector(".skeleton").textContent = frame.metrics.skeleton_length;
node.querySelector(".components").textContent = frame.metrics.components;
resultGrid.appendChild(node);
});
}
sensitivity.addEventListener("input", () => {
sensitivityValue.textContent = Number(sensitivity.value).toFixed(2);
});
fileInput.addEventListener("change", () => {
const file = fileInput.files[0];
fileName.textContent = file ? file.name : "支持 mp4、avi、png、jpg、tiff";
});
form.addEventListener("submit", async (event) => {
event.preventDefault();
setBusy(true);
emptyState.hidden = false;
emptyState.textContent = "正在抽帧和分割,请稍候。";
resultGrid.innerHTML = "";
videoLink.hidden = true;
try {
const payload = new FormData(form);
const response = await fetch("/api/segment", {
method: "POST",
body: payload,
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.detail || "分割失败");
}
renderResults(data);
} catch (error) {
emptyState.hidden = false;
emptyState.textContent = error.message;
} finally {
setBusy(false);
}
});
loadHealth();
loadMethods();

96
frontend/index.html Normal file
View File

@@ -0,0 +1,96 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>ISISeg 导丝分割工作台</title>
<link rel="stylesheet" href="/styles.css" />
</head>
<body>
<main class="shell">
<section class="mast">
<div>
<p class="eyebrow">ISISeg</p>
<h1>介入导丝视频分割工作台</h1>
</div>
<div class="status" id="health">服务检查中</div>
</section>
<section class="workspace">
<form class="control-panel" id="segmentForm">
<label class="drop-zone" for="file">
<input id="file" name="file" type="file" accept="image/*,video/*" required />
<span class="drop-title">选择介入视频或图像</span>
<span class="drop-subtitle" id="fileName">支持 mp4、avi、png、jpg、tiff</span>
</label>
<div class="field">
<label for="method">分割方式</label>
<select id="method" name="method"></select>
</div>
<div class="field">
<div class="field-head">
<label for="sensitivity">灵敏度</label>
<output id="sensitivityValue">0.56</output>
</div>
<input id="sensitivity" name="sensitivity" type="range" min="0.05" max="0.95" value="0.56" step="0.01" />
</div>
<div class="compact-grid">
<div class="field">
<label for="frameStride">帧步长</label>
<input id="frameStride" name="frame_stride" type="number" min="1" max="90" value="5" />
</div>
<div class="field">
<label for="maxFrames">最大帧数</label>
<input id="maxFrames" name="max_frames" type="number" min="1" max="80" value="12" />
</div>
</div>
<button class="primary" type="submit">
<span>开始分割</span>
</button>
</form>
<section class="results">
<div class="results-head">
<div>
<p class="eyebrow">Result</p>
<h2>分割结果</h2>
</div>
<a class="download" id="videoLink" hidden>下载叠加视频</a>
</div>
<div class="empty" id="emptyState">上传文件后,这里会显示原帧、叠加图和导丝掩膜。</div>
<div class="grid" id="resultGrid"></div>
</section>
</section>
</main>
<template id="resultCardTemplate">
<article class="result-card">
<div class="card-top">
<span class="method"></span>
<span class="frame-index"></span>
</div>
<div class="image-pair">
<figure>
<img class="overlay" alt="导丝叠加结果" />
<figcaption>叠加</figcaption>
</figure>
<figure>
<img class="mask" alt="导丝掩膜" />
<figcaption>掩膜</figcaption>
</figure>
</div>
<dl class="metrics">
<div><dt>覆盖率</dt><dd class="coverage"></dd></div>
<div><dt>骨架长度</dt><dd class="skeleton"></dd></div>
<div><dt>连通域</dt><dd class="components"></dd></div>
</dl>
</article>
</template>
<script src="/app.js"></script>
</body>
</html>

328
frontend/styles.css Normal file
View File

@@ -0,0 +1,328 @@
:root {
--bg: #111412;
--panel: #181d1b;
--panel-2: #202622;
--line: #344038;
--text: #f0f5ef;
--muted: #9aa89c;
--accent: #ffd166;
--accent-2: #3dd6b5;
--danger: #ff6b6b;
--shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
background:
linear-gradient(135deg, rgba(61, 214, 181, 0.08), transparent 38%),
radial-gradient(circle at 85% 8%, rgba(255, 209, 102, 0.12), transparent 28%),
var(--bg);
color: var(--text);
font-family: "Aptos", "Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
.shell {
width: min(1440px, calc(100vw - 32px));
margin: 0 auto;
padding: 28px 0 42px;
}
.mast {
display: flex;
align-items: end;
justify-content: space-between;
gap: 24px;
padding: 16px 0 24px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--accent-2);
text-transform: uppercase;
letter-spacing: 0.12em;
font-size: 12px;
font-weight: 800;
}
h1,
h2 {
margin: 0;
letter-spacing: 0;
}
h1 {
font-size: clamp(34px, 5vw, 68px);
line-height: 0.92;
max-width: 820px;
}
h2 {
font-size: 28px;
}
.status,
.download {
border: 1px solid var(--line);
background: rgba(24, 29, 27, 0.75);
color: var(--muted);
padding: 10px 14px;
border-radius: 8px;
text-decoration: none;
white-space: nowrap;
}
.status.ok {
color: var(--accent-2);
border-color: rgba(61, 214, 181, 0.5);
}
.status.bad {
color: var(--danger);
border-color: rgba(255, 107, 107, 0.55);
}
.workspace {
display: grid;
grid-template-columns: 360px 1fr;
gap: 18px;
align-items: start;
}
.control-panel,
.results {
background: rgba(24, 29, 27, 0.92);
border: 1px solid var(--line);
box-shadow: var(--shadow);
border-radius: 8px;
}
.control-panel {
position: sticky;
top: 18px;
display: grid;
gap: 18px;
padding: 18px;
}
.drop-zone {
display: grid;
place-items: center;
gap: 8px;
min-height: 170px;
border: 1px dashed rgba(61, 214, 181, 0.55);
border-radius: 8px;
background: linear-gradient(145deg, rgba(61, 214, 181, 0.08), rgba(255, 209, 102, 0.06));
cursor: pointer;
text-align: center;
padding: 18px;
}
.drop-zone input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.drop-title {
font-size: 20px;
font-weight: 800;
}
.drop-subtitle {
color: var(--muted);
max-width: 280px;
overflow-wrap: anywhere;
}
.field {
display: grid;
gap: 8px;
}
.field-head,
.results-head,
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
label {
color: var(--muted);
font-size: 13px;
font-weight: 700;
}
select,
input[type="number"] {
width: 100%;
min-height: 42px;
color: var(--text);
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 8px;
padding: 0 12px;
}
input[type="range"] {
accent-color: var(--accent);
}
.compact-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.primary {
min-height: 48px;
border: 0;
border-radius: 8px;
background: linear-gradient(90deg, var(--accent), #ff9f5a);
color: #17140d;
font-weight: 900;
cursor: pointer;
}
.primary:disabled {
cursor: wait;
filter: grayscale(0.8);
opacity: 0.65;
}
.results {
min-height: 620px;
padding: 18px;
}
.results-head {
margin-bottom: 18px;
}
.empty {
min-height: 500px;
display: grid;
place-items: center;
color: var(--muted);
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(17, 20, 18, 0.55);
text-align: center;
padding: 24px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 14px;
}
.result-card {
border: 1px solid var(--line);
background: #121614;
border-radius: 8px;
overflow: hidden;
}
.card-top {
padding: 12px;
border-bottom: 1px solid var(--line);
}
.method {
font-weight: 900;
color: var(--accent);
}
.frame-index {
color: var(--muted);
font-size: 13px;
}
.image-pair {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1px;
background: var(--line);
}
figure {
margin: 0;
background: #050605;
}
img {
display: block;
width: 100%;
aspect-ratio: 4 / 3;
object-fit: contain;
}
figcaption {
padding: 7px 10px;
color: var(--muted);
font-size: 12px;
border-top: 1px solid var(--line);
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
margin: 0;
border-top: 1px solid var(--line);
}
.metrics div {
padding: 10px;
border-right: 1px solid var(--line);
}
.metrics div:last-child {
border-right: 0;
}
dt {
color: var(--muted);
font-size: 11px;
margin-bottom: 4px;
}
dd {
margin: 0;
font-weight: 850;
}
@media (max-width: 900px) {
.shell {
width: min(100vw - 20px, 720px);
}
.mast,
.workspace {
display: grid;
}
.workspace {
grid-template-columns: 1fr;
}
.control-panel {
position: static;
}
.status {
justify-self: start;
}
}