# Breast Mri Annotation

> Generate breast-region and nipple-location masks for sagittal breast MRI NIfTI files, including folder batches, inspect every slice in 3D Slicer, and export timestamped Astra labelmaps. Compare user-reviewed annotation folders with original exports and update learned preferences. Use for this user's breast MRI annotation and correction workflow.

- Skill: `maystroh/breast-mri-annotation` (Agent Skill, multi-file: 8 files)
- Install (CLI): `npx skillmds@latest add maystroh/breast-mri-annotation`
- Raw SKILL.md: https://api.skillmd.com/api/skills/maystroh/breast-mri-annotation/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Productivity
- Author: maystroh (https://skillmd.com/u/maystroh)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/maystroh/breast-mri-annotation

---


# Breast MRI annotation

Create reviewed, editable masks from a user-supplied folder or explicit list of `.nii`/`.nii.gz` volumes. This is an agent-guided annotation workflow, not a trained segmentation model. A single corrected case does not establish accuracy across a dataset. Do the requested generation and visual review; do not present a propagation script or generated arrays as completed annotation.

Read [references/annotation-rules.md](references/annotation-rules.md) and [the latest 30-case Mama-Mia review](references/mama-mia-review1-learned-preferences.md) before annotating. Read [the earlier 25-case QIN review](references/review1-learned-preferences.md) as complementary, case-specific evidence. The newer review corrects any blanket posterior-trimming interpretation: assess both missing attachment and excess depth. Apply outer-contour, coverage and nipple position/extent checks independently. Use the installed `slicer` skill for current Slicer APIs and connection mechanics. Read [references/slicer-workflow.md](references/slicer-workflow.md) for session setup and known editor pitfalls.

## Batch workflow

1. Inventory the specified folder/list. Default to the named folder only, not recursive traversal. Exclude existing masks, segmentations and prior outputs; ambiguous names need inspection. `scripts/batch_io.py inventory FOLDER` provides a candidate inventory, not proof that each file is suitable MRI. Honor an explicit list over discovery. Track each source, geometry, output path, corrected reference slices, generation method, reviewed slice indices, remaining uncertainties and status in a batch manifest. Resume based on verified manifest/file state, not filename existence alone.
2. Inspect each source's dimensions, affine/direction, spacing, orientation and intensity range. Do not assume K is sagittal, use fixed slice counts, reuse another patient's pixel coordinates, or silently select a timepoint from a 4D volume. Establish the intended scalar MRI first. If reslicing for annotation, map labels back to the original geometry with nearest-neighbor resampling.
3. Snapshot existing annotations before edits. Preserve user-corrected reference slices exactly unless the user asks to revise them. Generate breast contours from this case's anatomy. Corrected anchors and contour propagation can accelerate annotation, but independently inspect interpolated and end slices. Thresholding is an aid for finding tissue boundaries, not a universal breast segmentation method. Avoid hard-coded polygon templates, fixed anatomical cutoffs and intensity thresholds copied from the demonstration case.
4. Create a distinctly named draft in Slicer with `breast_region` and `nipple` in that order. Apply the preflight below before each case/editing session. Keep the original separate and make the active draft visibly identifiable. Use programmatic labelmap updates for reliable voxel placement, then inspect the results visually.
5. Review **every sagittal slice**, including slices appropriately left empty outside the target anatomy. Inspect upper/lower limits, outer skin boundary, posterior boundary, folds, background leakage and inter-slice consistency. Check orthogonal views or 3D where useful for discontinuities. Use native-resolution closeups for ambiguous areas. Capture actual Slicer views with the source and overlay toggled or shown transparently. A local montage can aid review but does not replace the user-requested review in Slicer. Make necessary corrections and repeat affected checks. Do not label unseen slices as reviewed or force nonempty masks on slices with no target tissue.
6. Keep nipple localization separate from detailed breast contours. Cover the supported nipple feature with a generous local neighborhood, not a tiny seed. Inspect position and physical extent across neighboring slices; avoid fixed voxel radii or a universal superior shift. Do not clip a supported nipple marker to the breast mask. Exact borders are not critical. If position itself remains ambiguous, flag the case and seek a location hint while progressing on breast masks/other cases.
7. Check labels, geometry, nonempty expected regions, disconnected islands/holes and abrupt contour changes. Flag rather than blindly remove anatomy merely to enforce one component. Verify preserved user masks and nipple labels after breast-only changes. Visual review by the agent is not user approval or clinical validation; record these separately.
8. Export a Slicer `.seg.nrrd` working copy and a NIfTI labelmap. Label **0=background, 1=breast_region, 2=nipple**, with nipple winning overlaps. Use `<source_stem>_mask_astra_<YYYYMMDD>_<HHMMSS>.nii.gz`, timestamped in the user's local timezone at export unless an exact timestamp/name is supplied. Example only: `QIN-BREAST-01-0031_mask_astra_20260909_152850.nii.gz`. Do not reuse this timestamp for new cases. Default output folder is the supplied source folder unless specified otherwise. Never overwrite original masks or silently replace an existing export.
9. Reload each export and verify exact labels plus original physical geometry. `scripts/batch_io.py` provides an export helper using SimpleITK with these invariants. Mark a case complete only after generation, requested visual review and verified export. Report counts of completed/flagged/remaining cases and link results/manifest. State any incomplete Slicer review plainly.

## Slicer preflight: every session/case

Before accepting a draft, apply the [Mama-Mia corrective quality gate](references/mama-mia-review1-learned-preferences.md#quality-gate-that-changes-generation-behavior): inspect source-only and outline closeups of the full superior/inferior attachment and skin envelope; correct clipping notches, detached strips, abrupt steps and unsupported caps. Recheck affected neighbors. Neither an all-slice viewing log nor an uncertainty flag substitutes for fixing a visible defect. Preserve intentionally empty reviewed slices.

- Discover the actual visible `qMRMLSegmentEditorWidget`; SegmentationReview has its own editor and is not the standard Segment Editor.
- Verify source volume and target node IDs/names. Set the intended draft, reference geometry and source volume. Ensure both named segments exist in the correct order.
- Enable overall and 2D visibility, per-segment visibility, and useful fill/outline opacity. A visible draft over a hidden original can make edits to the original seem invisible.
- Select the intended segment and effect. Avoid two editors having competing active effects. Verify the selected draft and painted data correspond to the visible overlay.
- Before creating or editing the `nipple` segment, set **Modify other segments → Allow overlap** in the active Segment Editor. Verify this setting after switching editors, target segmentations or sessions so nipple edits preserve overlapping `breast_region` voxels. Retain overlap in the working segmentation; nipple priority applies only when deriving the scalar NIfTI labelmap.
- Apply the user's existing setup script when needed **after** selecting the target. It binds geometry and keyboard shortcuts but does not enable overall visibility. Do not assume running it fixes every issue. Do not change mask voxels merely to test brush operation.

## Learning from corrections

Keep immutable before snapshots. For saved review folders, use their explicit source-to-reviewed-export mapping and verify the staged baseline against the original export before computing changes. Check scalar versus multicomponent segment encoding and physical geometry first. For live corrections, compare the user's corrected mask to the matching before version, checking both original and draft if edits may have landed in either. Report added/removed voxels by slice and show before/after/difference overlays. Extract anatomical preferences, distinguishing observed changes from inferred rules. Preserve these in a per-project reference; never merge edits from two masks silently. Learning here means updating workflow/reference rules, not model retraining.

Preserve raw segment overlap and distinguish union changes from breast-to-nipple relabeling. Display-normalized staged MRI may differ in intensity while masks and physical geometry still match; use the original MRI for intensity analysis. Reconcile contradictory examples explicitly instead of turning the latest edit into a universal erosion, dilation, slice-exclusion or nipple-shift rule. State which slices were visually inspected and which were compared numerically only.

## Invocation

`Use $breast-mri-annotation on <MRI_DATA>\annotation\qin_round1. Annotate the source NIfTI volumes, review every slice in Slicer, and save timestamped Astra masks.`

Do not require Slicer for initial file inspection or generation. It must be running for the requested live visual review; it need not be the user's current session. Prefer a separate review instance for batches so unsaved user work stays intact. If no usable Slicer connection exists, prepare files and the connection step, and explicitly mark visual review pending rather than claiming the batch is finished.

