refine workspace previews and library thumbnails

This commit is contained in:
2026-05-03 15:00:26 +08:00
parent 149cbc95d3
commit 0d0a881555
2 changed files with 243 additions and 61 deletions

View File

@@ -18,7 +18,7 @@ os.environ.setdefault("MPLCONFIGDIR", "/tmp/head_ct_morph_matplotlib")
import pydicom
from pydicom.multival import MultiValue
from PIL import Image
from PIL import Image, ImageDraw
from generate_head_extension_video import generate_video
from head_extension_app import (
@@ -662,11 +662,56 @@ def make_preview(
canvas_image.paste(fit_image(before_display, 700, 520), (0, 0))
canvas_image.paste(fit_image(after, 700, 520), (740, 0))
panels = [
("Original", before_display),
(
"Hard boundary",
preview_deform_2d(before_display, float(angle_degrees), "hard_boundary"),
),
(
"Gaussian smooth",
preview_deform_2d(
before_display,
float(angle_degrees),
"gaussian_smooth",
gaussian_sigma=float(gaussian_sigma),
),
),
(
"Soft transition",
preview_deform_2d(
before_display,
float(angle_degrees),
"soft_transition",
transition_width=float(transition_width),
),
),
]
process_image = Image.new("RGB", (1440, 430), (0, 0, 0))
process_draw = ImageDraw.Draw(process_image)
panel_width = 330
panel_height = 300
margin = 35
gap = 20
for index, (label, panel) in enumerate(panels):
x = margin + index * (panel_width + gap)
process_draw.text((x, 28), label, fill=(230, 230, 230))
process_image.paste(fit_image(panel, panel_width, panel_height), (x, 70))
process_draw.text(
(margin, 390),
f"Angle {float(angle_degrees):.1f} deg",
fill=(170, 170, 170),
)
canvas = BytesIO()
canvas_image.save(canvas, format="PNG")
encoded = base64.b64encode(canvas.getvalue()).decode("ascii")
process_canvas = BytesIO()
process_image.save(process_canvas, format="PNG")
process_encoded = base64.b64encode(process_canvas.getvalue()).decode("ascii")
return {
"image": f"data:image/png;base64,{encoded}",
"processImage": f"data:image/png;base64,{process_encoded}",
"source": str(Path(input_dir).resolve()),
"angleDegrees": float(angle_degrees),
}