microscopy-scale-bar-adder
Add accurate, publication-ready scale bars to microscopy images given pixel-to-unit calibration data.
Best use case
microscopy-scale-bar-adder is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Add accurate, publication-ready scale bars to microscopy images given pixel-to-unit calibration data.
Teams using microscopy-scale-bar-adder should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/microscopy-scale-bar-adder/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How microscopy-scale-bar-adder Compares
| Feature / Agent | microscopy-scale-bar-adder | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Add accurate, publication-ready scale bars to microscopy images given pixel-to-unit calibration data.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
# 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
```text
# 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
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `--image` | path | Yes | - | Input image file path |
| `--scale` | float | Yes | - | Scale bar length in physical units |
| `--unit` | str | No | `um` | Unit: `um`, `nm`, `mm` |
| `--pixels-per-unit` | float | No | from TIFF metadata | Calibration override (pixels per unit) |
| `--output` | path | No | `<input>_scalebar.<ext>` | Output file path |
| `--position` | str | No | `bottomright` | Bar position: `bottomright`, `bottomleft`, `topright`, `topleft` |
| `--bar-color` | str | No | `white` | Scale bar fill color |
| `--label-color` | str | No | `white` | Label text color |
| `--bar-thickness` | int | No | `3` | Bar 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 open** — `PIL.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 output** — `img.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
```bash
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`Related Skills
dpi-upscaler-checker
Check if images meet 300 DPI printing standards, and intelligently restore blurry low-resolution images using AI super-resolution technology.
study-design-scale-selector
Determines the appropriate Risk of Bias assessment scale for a medical study based on its design (RCT, Cohort, etc.), using PubMed metadata lookup or text analysis. Use when the user wants to know which quality assessment tool to use for a specific paper (given PMID or abstract).
skill-auditor
A comprehensive auditor for any agent skill — including Manus, OpenClaw/ClawHub, Claude, LobeHub, or custom SKILL.md-based skills. Use this skill whenever a user wants to evaluate, audit, review, score, or quality-check an agent skill before publishing, updating, or deploying. Covers two hard veto gates (structural redlines + research integrity redlines), static quality scoring across 25 criteria (ISO 25010 + OpenSSF + Agent), dynamic test input generation, multi-mode execution testing, multi-layer output evaluation with five specialized category rubrics (Evidence Insight / Protocol Design / Data Analysis / Academic Writing / Other), a Research Veto that applies to all four research categories, human eval viewer generation, actionable P0/P1/P2 optimization recommendations, and automatic skill improvement that outputs a polished, production-ready SKILL.md. Also use whenever a user says "audit my skill", "evaluate my skill", "improve my skill", or wants a corrected version after evaluation.
two-sample-mr-research-planner
Generates complete two-sample Mendelian randomization (MR) research designs from a user-provided research direction. Use when users want to design, plan, or build a study using two-sample MR to test causal relationships. Triggers:"design a two-sample MR study", "build a publishable MR paper", "test whether this biomarker causally affects this disease", "generate Lite/Standard/Advanced MR plans", "screen multiple exposures with MR", "bidirectional MR design", "causal inference using GWAS summary statistics", or "I want to study X and Y using MR". Always outputs four workload configurations (Lite / Standard / Advanced / Publication+) with a recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, and publication upgrade path.
research-proposal-generator
Generates a comprehensive research proposal design based on input literature, including hypothesis, mechanism verification, and budget. Use when the user wants to design a research project from a paper.
research-grants
Write competitive research proposals for NSF, NIH, DOE, DARPA, and Taiwan's NSTC when you need agency-compliant narratives, budgets, and review-criteria alignment for a specific solicitation/FOA/BAA.
protocol-standardization
Standardize fragmented experimental steps into reproducible protocol documents when you need method organization, lab SOP drafting, or cross-operator reproducibility; missing parameters must be explicitly marked as "To be supplemented/Not provided".
prospero-registration-helper
Assists researchers in generating PROSPERO registration content for meta-analyses from a title and optional protocol. Use when the user wants to draft a PROSPERO registration form.
non-tumor-ml-research-planner
Generates complete non-tumor biomedical machine learning research designs from a user-provided research direction. Always use this skill when users want to plan bioinformatics + ML papers for non-cancer diseases (metabolic, cardiovascular, kidney, inflammatory, autoimmune, infectious, neurological, endocrine, wound healing, chronic multifactor), design diagnostic biomarker studies, combine GEO datasets with feature selection and ML modeling, or generate Lite/Standard/Advanced/Publication+ workload plans. Trigger for:"non-tumor ML study", "bioinformatics paper outside oncology", "key genes and diagnostic model for a disease", "pyroptosis/ferroptosis/senescence/autophagy + disease", "GEO datasets + machine learning", "RF + LASSO diagnostic model", "DEG + feature selection + validation", "immune infiltration + biomarker", "non-cancer biomarker paper". Trigger even for casual phrasings like "I want to study X using machine learning", "help me design a non-tumor bioinformatics paper", or "how do I build a diagnostic model for disease Y".
network-tox-docking-research-planner
Generates complete network toxicology + molecular docking research designs from a user-provided toxicant and disease/phenotype. Always use this skill when users want to investigate how an environmental toxicant, endocrine disruptor, heavy metal, food contaminant, pharmaceutical residue, or consumer product chemical may contribute to a disease through shared molecular targets, hub genes, pathways, and docking evidence. Trigger for:"network toxicology study", "toxicology mechanism paper", "target prediction + PPI + docking", "environmental pollutant and disease mechanism", "hub genes and docking for toxicant", "Lite/Standard/Advanced toxicology plan", "CTD + SwissTargetPrediction + GeneCards + STRING", "CB-Dock2 docking study", "triclosan/BPA/cadmium/PFAS + disease". Also triggers for Chinese phrasings:"网络毒理学研究设计"、"毒物机制论文"、"靶点预测+PPI+对接"、"环境污染物与疾病机制". Trigger even for casual phrasings like "I want to study how chemical X affects disease Y" or "help me design a toxicology paper". Always output four workload configurations (Lite / Standard / Advanced / Publication+) with a recommended primary plan, step-by-step workflow, figure plan, validation strategy, minimal executable version, and publication upgrade path.
meta-protocol-writer
Generates a PROSPERO-compliant Meta-analysis protocol based on Title and PICOS. Use when the user wants to write a protocol for a systematic review or meta-analysis.
hypothesis-generation
Structured scientific hypothesis formulation from observations; use when you have experimental observations or preliminary data and need testable hypotheses with predictions, mechanisms, and validation experiments.