agentsclimarketplace

Matlab read medical data

Skill matlab/matlab-agentic-toolkit/skills-catalog/image-processing-and-computer-vision/matlab-read-medical-data

Read, write, and manipulate medical imaging data (DICOM, NIfTI, NRRD) in MATLAB. Covers Image Processing Toolbox functions (dicomreadVolume, niftiread, dicomContours, dicomanon) and Medical Imaging Toolbox enhanced APIs (medicalVolume, medicalImage, medicalref3d, extractSlice, updateOrientation). Use when reading medical files, listing DICOM series, extracting spatial referencing, changing orientation, working with RT structures, or anonymizing DICOM data. Some features require Medical Imaging Toolbox — see skill body and references for details.From its SKILL.md

Install
npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-read-medical-data

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

What its file declares

Copied from the file, not written here

The file declares its own license as MathWorks BSD-3-Clause. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.7 KB, ~2.1k tokens by cl100k_base, as published. Nobody here has run it

Read and Write Medical Data

Read, write, and manipulate medical imaging data in MATLAB. This skill covers both Image Processing Toolbox (IPT) functions and Medical Imaging Toolbox (MIT) enhanced APIs.

When to Use

  • Reading or writing DICOM, NIfTI, or NRRD files
  • Listing DICOM series with dicomCollection
  • Extracting spatial referencing or coordinate transforms
  • Changing volume orientation or extracting oriented slices
  • Working with DICOM RT structures (contours, masks, modify/write)
  • Anonymizing DICOM data

When NOT to Use

  • Displaying or visualizing volumes (use matlab-display-volume skill)
  • Displaying 2-D medical images with annotations (use matlab-display-image skill)
  • Reading non-medical image formats (PNG, TIFF, JPEG) — use imread

Toolbox Detection — CRITICAL FIRST STEP

Always check which toolboxes are available before choosing an approach. If Medical Imaging Toolbox is installed, prefer its APIs. If only Image Processing Toolbox is available, use IPT patterns.

Task → Function Quick Reference

TaskIPT onlyWith Medical Imaging Toolbox (preferred)
Read single DICOM filedicomread + dicominfomedicalImage
Read DICOM folderdicomreadVolumemedicalVolume
Read NIfTIniftiread + niftiinfomedicalVolume
Read NRRD— (requires MIT)medicalVolume or nrrdread + nrrdinfo
List DICOM seriesdicomCollectiondicomCollection
Spatial referencingimref3dmedicalref3d
Extract oriented sliceManual indexingextractSlice
Change orientationManual permuteupdateOrientation
Read DICOM RT structuredicomContours(dicominfo(file))Same
Anonymize DICOMdicomanon + dicomuidSame
Visualize volumevolumeViewermedicalVolumeViewer or volshow(medVol)

Top 4 Patterns

1. Read DICOM folder

Call medicalVolume or dicomreadVolume directly on the DICOM folder path. Do NOT call dicomCollection first — it is unnecessary when reading a single-series folder.

% WITH Medical Imaging Toolbox (preferred):
medVol = medicalVolume("path/to/dicom/folder");
V = medVol.Voxels;               % Auto-rescaled (e.g., HU for CT)
spacing = medVol.VoxelSpacing;   % [dx dy dz] in mm
orientation = medVol.Orientation; % "transverse", "coronal", "sagittal"
modality = medVol.Modality;       % "CT", "MR"

% Access spatial referencing via VolumeGeometry (medicalref3d object)
geom = medVol.VolumeGeometry;
geom.VolumeSize;                  % [rows cols slices]
geom.PatientCoordinateSystem;     % "LPS+" or "RAS+"
geom.Position;                    % [slices×3] slice positions in patient coords
geom.VoxelDistances;              % {[slices×3] [slices×3] [slices×3]} per-axis distances
geom.PixelSpacing;                % [slices×2] in-plane pixel spacing per slice
geom.IsAffine;                    % true if uniform spacing (affine transform)
geom.IsAxesAligned;               % true if volume axes align with patient axes
geom.IsMixed;                     % true if slices have varying pixel spacing

% IPT only:
[V, spatial, dim] = dicomreadVolume("path/to/dicom/folder");
V = squeeze(V);  % Remove singleton 4th dimension

2. Read NIfTI file

% WITH Medical Imaging Toolbox (preferred):
medVol = medicalVolume("path/to/file.nii.gz");

% IPT only:
V = niftiread("path/to/file.nii.gz");
info = niftiinfo("path/to/file.nii.gz");
voxelSize = info.PixelDimensions(1:3);

3. List DICOM series and read one

Use dicomCollection only when:

  • The user says the folder contains multiple series or volumes
  • medicalVolume or dicomreadVolume fails with an error (e.g., "not a DICOM file" or "multiple volumes detected")
  • You need to identify what series exist before deciding which one to read

dicomCollection scans the directory, excludes non-DICOM files, and returns a table where each row is one series. It does not read pixel data.

collection = dicomCollection("path/to/directory");
disp(collection);  % Table with Modality, SeriesDescription, Rows, Columns, Frames

% WITH Medical Imaging Toolbox:
medVol = medicalVolume(collection, "s1");

% IPT only:
[V, spatial] = dicomreadVolume(collection, "s1");

4. Extract slice / change orientation (Requires Medical Imaging Toolbox)

medVol = medicalVolume("path/to/file.nii");

% Extract slices — works for any orientation
[axialSlice, position, spacings] = extractSlice(medVol, 50, "transverse");
[coronalSlice, ~, ~] = extractSlice(medVol, 30, "coronal");
[sagittalSlice, ~, ~] = extractSlice(medVol, 45, "sagittal");

% If medVol.Orientation is not empty, use it as the third input
[sliceData, position, spacings] = extractSlice(medVol, 50, medVol.Orientation);

% Change orientation — do NOT use permute
medVolCoronal = updateOrientation(medVol, "coronal");  % Returns NEW object

updateOrientation was introduced in R2025a.

Detailed Reference Files

IMPORTANT: Before generating code for any task below, read the matching reference file first.

Task triggerReferenceRead BEFORE
Reading/writing DICOM or NIfTI with IPTreferences/ipt-reading-writing.mdWriting dicomreadVolume, niftiread, imref3d, or rescale logic
Using medicalVolume, medicalImage, slices, or orientationreferences/mit-medical-volume.mdWriting medicalImage, medicalVolume, extractSlice, or updateOrientation calls
Spatial referencing or coordinate transformsreferences/mit-spatial-referencing.mdWriting medicalref3d, intrinsicToWorld, or worldToIntrinsic calls
RT structures (contours, labelmaps, RTSTRUCT)references/dicom-rt-workflows.mdReading, editing, displaying, or plotting contours/RTSTRUCT files, or writing any dicomContours, plotContour, createMask, addContour, deleteContour call
Anonymizing DICOM filesreferences/dicom-anonymization.mdWriting any dicomanon or dicomuid call

Legacy Patterns to Avoid

Do NOT useUse insteadWhy
dicomread + dicominfo for single filemedicalImage (MIT)Unified access, auto-rescale
dicomreadVolume for DICOM foldermedicalVolume (MIT)Preserves spatial referencing
niftiread + niftiinfomedicalVolume (MIT)Unified container
V.Voxels(:,:,n) or V(:,:,n) for slice extractionextractSlice(medVol, n, medVol.Orientation) (MIT)Handles orientation, spatial metadata, works regardless of storage order
Manual permute for orientationupdateOrientation(medVol, orient) (MIT)Updates spatial metadata
Manual struct parsing for RTdicomContours(info)Clean tabular output
volumeViewermedicalVolumeViewer (MIT, R2026a)Medical-specific features
imshow for medical imagesimageshowBetter defaults for medical data

Conventions

  • Always detect available toolboxes before choosing functions
  • Prefer Medical Imaging Toolbox APIs (medicalVolume, medicalImage) when available
  • Always capture output from immutable methods (deleteContour, updateOrientation)
  • Always use CreateMode="Copy" when writing RT Structure DICOM files
  • Do NOT call dicomCollection before medicalVolume/dicomreadVolume by default — call the reader directly on the folder path
  • Use dicomCollection only when: the folder contains multiple series, medicalVolume fails with an error, or you need to identify what series exist without reading pixel data
  • Always squeeze the output of dicomreadVolume for grayscale data
  • Always use extractSlice to get slices from a medicalVolume — never use V.Voxels(:,:,n) manual indexing. extractSlice handles orientation, spatial metadata, and works correctly regardless of how the volume is stored on disk
  • Never manually parse nested DICOM structs — use dicomContours
  • extractSlice argument order: (vol, sliceIndex, direction) — numeric before string
  • intrinsicToWorld returns 3 separate outputs: [x, y, z] — not a single vector

Copyright 2026 The MathWorks, Inc.


What ships with it: 6 files

29.8 KB alongside SKILL.md

Gives 0 of the 12 instructions most healthcare skills give in ~2.1k tokens

Counted across 147 of the 152 authors here whose files we hold, read 2026-08-07

  • Export trial data to CSV formatin 11 of 147, across 2 files
  • Retrieve trial details using an NCT IDin 11 of 147, across 2 files
  • Split clinical datasets strictly by patientin 11 of 147, across 3 files
  • Use the ClinicalTrials.gov API v2in 10 of 147, across 1 file
  • Search trials by condition, drug, location, status or phasein 10 of 147, across 1 file
  • Use maximum page size for bulk data retrievalin 10 of 147, across 1 file
  • Extract and summarize key study informationin 10 of 147, across 1 file
  • Combine multiple filters for targeted searchesin 10 of 147, across 1 file
  • Print and review dataset statistics before modelingin 8 of 147, across 1 file
  • Start model development with simple baselinesin 8 of 147, across 1 file
  • Match preprocessing processors directly to data typesin 8 of 147, across 1 file
  • Monitor validation metrics for task type and class imbalancein 8 of 147, across 1 file

Said here and by no other author read

  • Check available toolboxes before choosing functions
  • Prefer Medical Imaging Toolbox APIs when available
  • Read matching reference file before generating code
  • Read DICOM folder path directly without dicomCollection
  • Use dicomCollection only for multiple series or debugging
  • Capture output from immutable methods

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.