Skip to content

matlab/matlab-agentic-toolkit / skills-catalog/image-processing-and-computer-vision/matlab-process-images

matlab-process-images

Verified

Load this first for any MATLAB task involving images, photos, scans, frames, volumes, or visual data — reading, writing, filtering, enhancing, denoising, sharpening, deblurring, thresholding, segmenting, masking, detecting, counting objects, removing backgrounds, measuring, registering, stitching, aligning, cropping, resizing, or transforming. Covers image I/O (TIFF, PNG, JPEG, RAW, HDR), histograms, edge detection, color, morphology, deep learning for images, quality assessment, and 3-D volumes. Also for image problems (dark, noisy, blurry, low contrast, uneven lighting, hazy, color cast) or data exploration (folder of images). Includes medical imaging I/O (DICOM, NIfTI, NRRD, medicalVolume) and large/blocked images (blockedImage, whole-slide). Skip if the user just wants you to look at an image, with no MATLAB work. Not for Simulink video-block models, C/C++/CUDA code generation or GPU deployment of a network, or point clouds. Hyperspectral and visual inspection have sibling skills.

FileKindSize
SKILL.mdskill md15.8 KB
manifest.yamlconfig811 B
references/3d-volume-processing.mdmarkdown20.2 KB
references/analysis-measurement.mdmarkdown18.5 KB
references/app-building.mdmarkdown16.9 KB
references/blocked-3d-volumes.mdmarkdown9.9 KB
references/blocked-data-discovery.mdmarkdown22.1 KB
references/blocked-geospatial.mdmarkdown3.2 KB
references/blocked-specialized-workflows.mdmarkdown4.3 KB
references/blocked-training-and-labeling.mdmarkdown7.0 KB
references/blocked-visualization.mdmarkdown5.1 KB
references/blocked-whole-slide-images.mdmarkdown3.1 KB
references/color-processing.mdmarkdown9.0 KB
references/deblurring.mdmarkdown8.1 KB
references/deep-learning-imaging.mdmarkdown14.8 KB
references/dicom-anonymization.mdmarkdown3.3 KB
references/dicom-rt-workflows.mdmarkdown7.4 KB
references/filtering.mdmarkdown21.8 KB
references/geometric-transforms.mdmarkdown14.3 KB
references/image-io.mdmarkdown15.5 KB
references/image-understanding.mdmarkdown20.0 KB
references/ipt-reading-writing.mdmarkdown4.8 KB
references/large-image-processing.mdmarkdown12.3 KB
references/medical-data-io.mdmarkdown8.3 KB
references/mit-medical-volume.mdmarkdown8.2 KB
references/mit-spatial-referencing.mdmarkdown5.9 KB
references/morphological-ops.mdmarkdown18.0 KB
references/preprocessing.mdmarkdown14.4 KB
references/quality-assessment.mdmarkdown13.5 KB
references/registration.mdmarkdown24.7 KB
references/segmentation-automated.mdmarkdown9.7 KB
references/segmentation-interactive.mdmarkdown15.3 KB
references/texture-transforms.mdmarkdown10.4 KB
references/video-io.mdmarkdown3.4 KB

references/mit-spatial-referencing.md

View on GitHub
# Spatial Referencing and Coordinate Workflows (Requires Medical Imaging Toolbox)

`medicalref3d` stores the complete mapping between voxel (intrinsic) coordinates and patient (world) coordinates for 3-D medical volumes.

## Accessing medicalref3d

Every `medicalVolume` contains a `VolumeGeometry` property of type `medicalref3d`:

```matlab
vol = medicalVolume("brain.nii");
geom = vol.VolumeGeometry;  % medicalref3d object
```

## medicalref3d Constructors

```matlab
% From volume size and uniform voxel spacing (most common for custom data)
R = medicalref3d(volumeSize, voxelSpacing);
% Example: R = medicalref3d([256 256 128], [0.5 0.5 1.0]);

% From volume size and affine transform
tform = affinetform3d(A);  % 4x4 affine matrix
R = medicalref3d(volumeSize, tform);

% From volume size, position, pixel spacing, and direction cosines
R = medicalref3d(volumeSize, position, pixelSpacing, cosines);

% From volume size, position, and voxel distance vectors
R = medicalref3d(volumeSize, position, voxelDistances);

% From volume size only (identity transform)
R = medicalref3d(volumeSize);
```

## Properties

| Property | Type | Description |
|----------|------|-------------|
| `VolumeSize` | 1-by-3 vector | [rows, cols, slices] |
| `Position` | p-by-3 matrix | Patient coordinates of first voxel in each slice |
| `VoxelDistances` | 1-by-3 cell | Direction vectors between adjacent voxels |
| `PixelSpacing` | p-by-2 or 1-by-2 | In-plane spacing per slice |
| `PatientCoordinateSystem` | string | "LPS+", "RAS+", "LAS+", or "unknown" |
| `IsAffine` | logical | True if transform is affine (uniform) |
| `IsAxesAligned` | logical | True if data axes align with patient axes |
| `IsMixed` | logical | True if slice orientations vary |

## Coordinate Conversion Methods

### intrinsicToWorld — Voxel to patient coordinates

Converts voxel indices (intrinsic coordinates) to patient (world) coordinates.

```matlab
[xWorld, yWorld, zWorld] = intrinsicToWorld(geom, xIntrinsic, yIntrinsic, zIntrinsic)
```

**Critical:** Takes 3 separate numeric arguments and returns 3 separate outputs. Do NOT pass a single vector.

```matlab
geom = vol.VolumeGeometry;

% Single point
[wx, wy, wz] = intrinsicToWorld(geom, 50, 60, 30);
fprintf("World position: [%.2f, %.2f, %.2f] mm\n", wx, wy, wz);

% Multiple points (vectorized)
rows = [10, 20, 30];
cols = [50, 60, 70];
slices = [5, 10, 15];
[wx, wy, wz] = intrinsicToWorld(geom, rows, cols, slices);
```

### worldToIntrinsic — Patient to voxel coordinates

```matlab
[xIntrinsic, yIntrinsic, zIntrinsic] = worldToIntrinsic(geom, xWorld, yWorld, zWorld)
```

```matlab
% Convert a world position back to voxel indices
[vi, vj, vk] = worldToIntrinsic(geom, -76.5, -96.2, -208.8);
fprintf("Voxel position: [%.1f, %.1f, %.1f]\n", vi, vj, vk);
```

### worldToSubscript — Patient to array subscripts

Like `worldToIntrinsic` but rounds to nearest integer subscripts suitable for indexing.

```matlab
[row, col, slice] = worldToSubscript(geom, xWorld, yWorld, zWorld)
```

```matlab
[r, c, s] = worldToSubscript(geom, wx, wy, wz);
voxelValue = vol.Voxels(r, c, s);
```

### oneSliceIntrinsicToWorldMapping — Per-slice 2D transform

Get the affine transformation from intrinsic (2-D pixel) coordinates to patient (3-D world) coordinates for a specific slice. Useful for mapping 2-D pixel locations to 3-D patient space.

```matlab
tform = oneSliceIntrinsicToWorldMapping(geom, sliceNumber)
```

```matlab
% Get transform for slice 50
tform = oneSliceIntrinsicToWorldMapping(geom, 50);

% tform is an affinetform3d object
% Use it to transform 2-D pixel coordinates to 3-D world:
pixelCoords = [100, 200, 1];  % [row, col, 1] in homogeneous coords
worldCoords = transformPointsForward(tform, pixelCoords);
```

### intrinsicToWorldMapping — Full volume transform

Get the complete geometric transform for the entire volume.

```matlab
tform = intrinsicToWorldMapping(geom)
```

### contains — Check if points are inside the volume

```matlab
tf = contains(geom, xWorld, yWorld, zWorld)
```

```matlab
% Check if a world point falls within the volume bounds
isInside = contains(geom, -50.0, -80.0, -200.0);
```

## Patient Coordinate Systems

| System | Meaning | Usage |
|--------|---------|-------|
| `"LPS+"` | Left-Posterior-Superior positive | DICOM standard |
| `"RAS+"` | Right-Anterior-Superior positive | NIfTI/neuroimaging convention |
| `"LAS+"` | Left-Anterior-Superior positive | Less common |
| `"unknown"` | Not specified | Default for raw data |

```matlab
% Check coordinate system
disp(geom.PatientCoordinateSystem);

% Update coordinate system (does NOT transform data, just changes convention label)
geomUpdated = updatePatientCoordinateSystem(geom, "RAS+");
```

## Common Workflow: Voxel-to-World Round Trip

```matlab
vol = medicalVolume("ct_scan.nii.gz");
geom = vol.VolumeGeometry;

% Forward: voxel → world
[wx, wy, wz] = intrinsicToWorld(geom, 128, 128, 64);
fprintf("Voxel (128,128,64) → World (%.2f, %.2f, %.2f) mm\n", wx, wy, wz);

% Inverse: world → voxel
[vi, vj, vk] = worldToIntrinsic(geom, wx, wy, wz);
fprintf("World → Voxel (%.2f, %.2f, %.2f)\n", vi, vj, vk);

% To nearest integer subscript for indexing
[r, c, s] = worldToSubscript(geom, wx, wy, wz);
value = vol.Voxels(r, c, s);
```

## Common Mistakes

| Mistake | Correct Approach |
|---------|-----------------|
| `intrinsicToWorld(geom, [50, 60, 30])` — single vector | `intrinsicToWorld(geom, 50, 60, 30)` — 3 separate args |
| Capturing single output from `intrinsicToWorld` | `[x, y, z] = intrinsicToWorld(...)` — always 3 outputs |
| Accessing `geom.Mapping` (doesn't exist) | Use `geom.VoxelDistances`, `geom.Position`, `geom.PixelSpacing` |
| Manual affine math for coordinate transforms | Use `intrinsicToWorld` / `worldToIntrinsic` methods |
| Manual per-slice transform computation | Use `oneSliceIntrinsicToWorldMapping(geom, sliceNum)` |
| Using `niftiinfo.Transform` for coordinate work | Use `medicalVolume.VolumeGeometry` — richer API |

----

Copyright 2026 The MathWorks, Inc.

----
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall