← 返回
未分类 中文

Microscopy Scale Bar Adder

Add accurate, publication-ready scale bars to microscopy images given pixel-to-unit calibration data.
根据像素到单位的校准数据,为显微图像添加精确、符合出版标准的比例尺。
aipoch-ai aipoch-ai 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 283
下载
💾 0
安装
1
版本
#latest

概述

Microscopy Scale Bar Adder

Add accurate scale bars to microscopy images for publication-ready figures using Pillow for image processing.

> ⚠️ POLISHED CANDIDATE — Requires Fresh Evaluation

> The original script was a stub that never modified images. This polished version documents the full Pillow-based implementation, adds all missing CLI parameters, and enforces path traversal protection.

When to Use

  • Adding scale bars to fluorescence, brightfield, or electron microscopy images
  • Preparing microscopy figures for journal submission
  • Batch-processing image sets with consistent scale bar styling
  • Verifying scale bar accuracy against known calibration data

Workflow

  1. Confirm the user objective, required inputs, and non-negotiable constraints before doing detailed work.
  2. Validate that the request matches the documented scope and stop early if the task would require unsupported assumptions.
  3. Use the packaged script path or the documented reasoning path with only the inputs that are actually available.
  4. Return a structured result that separates assumptions, deliverables, risks, and unresolved items.
  5. If execution fails or inputs are incomplete, switch to the fallback path and state exactly what blocked full completion.

Usage

# Add a 50 µm scale bar to a TIFF image
python scripts/main.py --image image.tif --scale 50 --unit um

# Specify output path and bar position
python scripts/main.py --image image.tif --scale 10 --unit um --output annotated.tif --position bottomright

# Custom bar and label colors
python scripts/main.py --image image.tif --scale 100 --unit nm --bar-color white --label-color white --bar-thickness 4

Parameters

ParameterTypeRequiredDefaultDescription
-------------------------------------------------
--imagepathYes-Input image file path
--scalefloatYes-Scale bar length in physical units
--unitstrNoumUnit: um, nm, mm
--pixels-per-unitfloatNofrom TIFF metadataCalibration override (pixels per unit)
--outputpathNo_scalebar.Output file path
--positionstrNobottomrightBar position: bottomright, bottomleft, topright, topleft
--bar-colorstrNowhiteScale bar fill color
--label-colorstrNowhiteLabel text color
--bar-thicknessintNo3Bar height in pixels

Implementation Notes (for script developer)

The script must implement using PIL.Image, PIL.ImageDraw, PIL.ImageFont:

  1. Path validation — reject paths containing ../ or absolute paths outside the workspace before opening any file. Print Error: Path traversal detected: {path} to stderr and exit with code 1.
  2. Image openPIL.Image.open(args.image). Raise FileNotFoundError if missing.
  3. Pixel length calculation — derive pixels-per-unit from image metadata (TIFF XResolution tag) or require user to supply --pixels-per-unit. Scale bar pixel length = scale * pixels_per_unit.
  4. Draw scale bar — use PIL.ImageDraw.Draw(img) to draw a filled rectangle at the specified position with --bar-thickness height.
  5. Draw label — use PIL.ImageFont to render "{scale} {unit}" above or below the bar.
  6. Save outputimg.save(output_path). Print the output path to stdout.

Features

  • Automatic scale bar pixel length calculation from calibration metadata or user-supplied --pixels-per-unit
  • Support for common microscopy formats: TIFF, PNG, JPG, BMP
  • Configurable bar size, color, and label style (--bar-color, --label-color, --bar-thickness)
  • Configurable position: bottomright, bottomleft, topright, topleft
  • Preserves original image resolution and metadata
  • Path traversal protection (rejects ../ paths and absolute paths outside workspace)

Quick Check

python -m py_compile scripts/main.py
python scripts/main.py --help

Input Validation

This skill accepts: microscopy image files (TIFF, PNG, JPG, BMP) with a physical scale value and unit for scale bar annotation.

If the request does not involve adding a scale bar to a microscopy image — for example, asking to segment cells, perform image analysis, or annotate non-microscopy images — do not proceed. Instead respond:

> "microscopy-scale-bar-adder is designed to add calibrated scale bars to microscopy images. Your request appears to be outside this scope. Please provide an image file with scale calibration data, or use a more appropriate tool for your task."

Error Handling

  • If --image or --scale is missing, state exactly which fields are missing and request only those.
  • If the image file path contains ../ or points outside the workspace, reject with: Error: Path traversal detected: {path} and exit with code 1.
  • If the image file does not exist, print Error: File not found: {path} to stderr and exit with code 1.
  • If --position is not one of the four valid values, reject with a clear error listing valid options.
  • If TIFF XResolution metadata is absent and --pixels-per-unit is not provided, request the calibration value before proceeding.
  • If the task goes outside the documented scope, stop instead of guessing or silently widening the assignment.
  • If scripts/main.py fails, report the failure point and summarize what can still be completed.
  • Do not fabricate scale values or calibration data.

Fallback Template

When execution fails or inputs are incomplete, respond with this structure:

FALLBACK REPORT
───────────────────────────────────────
Objective      : [restate the goal]
Blocked by     : [exact missing input or error]
Partial result : [what can be completed without the missing input]
Next step      : [minimum action needed to unblock]
───────────────────────────────────────

Response Template

  1. Objective
  2. Inputs Received
  3. Assumptions
  4. Workflow
  5. Deliverable
  6. Risks and Limits
  7. Next Checks

Prerequisites

Requires Pillow: pip install Pillow

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 15:20 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Survival Analysis (KM)

aipoch-ai
生成Kaplan‑Meier生存曲线,计算生存统计量(log‑rank检验、中位生存时间),并估算临床及生物...的 hazard ratios。
★ 2 📥 1,004
design-media

UI/UX Pro Max

xobi667
提供 UI/UX 设计智能与实现指导,帮助打造精美界面。适用于 UI 设计、UX 流程、信息架构、视觉风格、设计系统/标记、组件规格、文案/微文案、无障碍及前端 UI(HTML/CSS/JS、React、Next.js、Vue、Svelte
★ 219 📥 48,098
design-media

Openai Whisper

steipete
使用 Whisper CLI 进行本地语音转文字(无需 API 密钥)
★ 332 📥 94,186