$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-display-volumeDisplay 3-D image volumes, medical image volumes, surface meshes, and annotations for 3-D image processing. Use when displaying 3-D images or isosurfaces with volshow, creating volume viewers with viewer3d, adding Regions of Interest (ROI) or annotations, overlaying masks or segm
| 1 | # Volume Display |
| 2 | |
| 3 | Display volumes with `volshow` for performant, high quality volume display. Display isosurface meshes, triangulations, and surfaces using `images.ui.graphics.Surface` rather than `isosurface` for more performant, higher quality mesh display with more responsive interactions for meshes of all sizes. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - User asks to create a GUI, app, dashboard, or interactive tool for volume, isosurface, or surface mesh display |
| 8 | - User wants ROIs, annotations, or other lines and shapes plotted on top of the volume or surface mesh |
| 9 | - User wants to display labeled data or other overlay volumes on top of a volume |
| 10 | |
| 11 | ## When NOT to Use |
| 12 | |
| 13 | - User does not have the Image Processing Toolbox — fall back to `isosurface` + `patch`, but recommend `volshow` for better performance. |
| 14 | |
| 15 | ## Medical Image Volumes |
| 16 | |
| 17 | When the user has the Medical Imaging Toolbox, use `medicalVolume` to load DICOM/NIfTI/NRRD files, then call the `volshow` method on that object. This automatically sets the spatial `Transformation` and `SpatialUnits` from the file metadata. All other patterns in this skill (Viewer, overlays, annotations, streaming, app building) still apply — only the entry point differs. |
| 18 | |
| 19 | ```matlab |
| 20 | medVol = medicalVolume("brain.nii"); |
| 21 | obj = volshow(medVol); |
| 22 | ``` |
| 23 | |
| 24 | ## Key Objects |
| 25 | |
| 26 | | Object | Constructor | Key callback | |
| 27 | |--------|------------|-------------| |
| 28 | | `Viewer` | `viewer3d(parent)` | `CameraMovedFcn`, `ObjectClickedFcn` | |
| 29 | | `Volume` | `volshow(data, Parent=viewer)` | | |
| 30 | | `Surface` | `images.ui.graphics.Surface(viewer, Data=tri)` | | |
| 31 | | Interactive Annotations | `uidraw(parent, "shape")` | `AnnotationMovedFcn` (on Viewer) | |
| 32 | |
| 33 | **Utilities:** `linkviewers(viewers)` synchronizes camera motion across multiple Viewers. `title(viewer, "text")` sets the Viewer title. |
| 34 | |
| 35 | ## Workflow |
| 36 | |
| 37 | 1. **Create Viewer** — call `viewer3d()` or `viewer3d(parent)` for app contexts |
| 38 | 2. **Add Volume** — call `volshow(V, Parent=viewer)` to display volumetric data |
| 39 | 3. *(Optional)* **Add surfaces** — call `images.ui.graphics.Surface(viewer, Data=tri)` for mesh display |
| 40 | 4. *(Optional)* **Add annotations** — call `uidraw(volObj, "line")` for interactive ROIs |
| 41 | 5. *(Optional)* **Configure callbacks** — set `CameraMovedFcn`, `AnnotationMovedFcn`, or `ObjectClickedFcn` on the Viewer |
| 42 | 6. **Update data** — set `obj.Data = newV` to stream; use `waitfor(viewer,"Busy",false)` for synchronization |
| 43 | |
| 44 | ## Legacy Patterns to Avoid |
| 45 | |
| 46 | | Do NOT use | Use instead | Why | |
| 47 | |------------|-------------|-----| |
| 48 | | `isosurface` + `patch` | `images.ui.graphics.Surface(viewer, Data=tri)` | Better rendering, interactive performance, depth peeling | |
| 49 | | `clear(viewer)` then re-add objects | Reuse objects, update `Data` property | Avoids reconstruction overhead | |
| 50 | | `drawnow` for volume streaming sync | `waitfor(viewer,"Busy",false)` | Volume data loads asynchronously; `drawnow` is still appropriate for Surface animation | |
| 51 | | Creating new `volshow` each frame | Keep reference, set `obj.Data = V` | Reuse avoids GPU reallocation | |
| 52 | |
| 53 | ## Patterns |
| 54 | |
| 55 | ### Standard Volume Display |
| 56 | |
| 57 | Simple cases of volume display can call `volshow` without specifying a parent. All name-value arguments can be set as properties on the Volume object, and the volume data can be updated by setting the `Data` property. |
| 58 | |
| 59 | ```matlab |
| 60 | obj = volshow(V); |
| 61 | ``` |
| 62 | |
| 63 | Choose `DisplayRangeMode` based on the data type and value range: |
| 64 | |
| 65 | | Data characteristics | Recommended mode | |
| 66 | |---------------------|-----------------| |
| 67 | | Normalized `single`/`double` in [0, 1] | `"data-range"` (default) | |
| 68 | | `uint8` or `int8` | `"data-range"` (default) | |
| 69 | | `uint16` with values up to 1023 (e.g., 10-bit CT) | `"10-bit"` | |
| 70 | | `uint16` with values up to 4095 (e.g., 12-bit CT/MR) | `"12-bit"` | |
| 71 | | `uint16` full range or `int16` | `"16-bit"` | |
| 72 | | Custom window/level needed | `"manual"` with `DisplayRange=[low high]` | |
| 73 | |
| 74 | ```matlab |
| 75 | % 12-bit medical volume |
| 76 | obj = volshow(V, DisplayRangeMode="12-bit"); |
| 77 | |
| 78 | % Manual window/level |
| 79 | obj = volshow(V, DisplayRangeMode="manual", DisplayRange=[200 1200]); |
| 80 | ``` |
| 81 | |
| 82 | Set `RenderingStyle` to control how voxel data is visualized. See the dedicated **Rendering Styles** section below for detailed guidance. |
| 83 | |
| 84 | **Choosing a Colormap** — Select based on data content: |
| 85 | |
| 86 | | Data content | Recommended colormap | Rationale | |
| 87 | |-------------|---------------------|-----------| |
| 88 | | CT / MR (anatomical) | `gray(256)` | Clinical convention; preserves radiologist familiarity | |
| 89 | | CT with window/level | `gray(256)` + `DisplayRange` | Narrow range highlights target tissue | |
| 90 | | Fluorescence / emission | |