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/blocked-specialized-workflows.md

View on GitHub
# Specialized blockedImage Workflows

## Writing Data (block-by-block)
Create a writable blockedImage and populate it block by block with `setBlock`:
```matlab
bim = blockedImage(dest, imageSize, blockSize, initVal, Mode="w");
setBlock(bim, [r c], blockdata);        % write one block
setBlock(bim, [r c], blockdata, Level=L); % write at specific level
```
Use this when building an image incrementally outside of `apply()` (e.g., assembling tiles from an external source).

## Coordinate Systems and Spatial Referencing
- **Subscripts** — standard MATLAB indexing into the virtual full image.
- **BlockSub** — index into `SizeInBlocks` (which block). Convert with `sub2blocksub` / `blocksub2sub`.
- **World** — real-world coordinates. Convert with `sub2world` / `world2sub`. Set via `WorldStart` and `WorldEnd` properties.

For geospatial coordinate conversions (projected/geographic to pixel), see `blocked-geospatial.md`.

### Multiresolution spatial referencing
blockedImage assumes all resolution levels span the **same world extents**. By default, `WorldStart` and `WorldEnd` are set from the finest level's pixel coordinates (center of first pixel at 0.5, last edge at `Size + 0.5`).

**Verify the assumption:** check that the aspect ratio (`Size(:,1)./Size(:,2)`) is consistent across levels. If it varies, the default referencing is incorrect and levels will not align when displayed side-by-side.

**Fix misaligned levels:** extract pixel spacing from the source metadata. Two common patterns:

1. **TIFF XResolution/YResolution** (pixels per unit, most common for WSI):
   ```matlab
   fileInfo = imfinfo(bim.Source);
   pixelExtent = 1 / fileInfo(1).XResolution;  % world units per pixel at finest level
   imageSizeInWorld = bim.Size(1,1:2) * pixelExtent;
   bim.WorldStart = [pixelExtent/2, pixelExtent/2, 0.5];
   bim.WorldEnd = bim.WorldStart + [imageSizeInWorld, 3];
   ```

2. **DICOM_PIXEL_SPACING in ImageDescription** (embedded XML, e.g., Camelyon data):
   ```matlab
   binfo = imfinfo(bim.Source);
   desc = binfo(1).ImageDescription;
   % Parse pixel spacing per level from XML, then:
   pixelDims = pixelSpacing_coarse / pixelSpacing_fine;
   bim.WorldEnd(coarseLevel, 1:2) = bim.Size(coarseLevel, 1:2) * pixelDims;
   ```

**Verify alignment** after setting world coordinates by displaying two levels side-by-side with `linkviewers` and zooming to a common feature.

## Mask-based Block Selection with `selectBlockLocations`
Build a mask from a coarse level (fits in memory), wrap it as a blockedImage with matching spatial referencing, then use `selectBlockLocations` to select only blocks overlapping the ROI:
```matlab
imCoarse = gather(bim, Level=bim.NumLevels);
BW = ~imbinarize(im2gray(imCoarse));
bmask = blockedImage(BW, WorldEnd=bim.WorldEnd(bim.NumLevels, 1:2));
bls = selectBlockLocations(bim, Mask=bmask, InclusionThreshold=0);
bResult = apply(bim, @fcn, BlockLocationSet=bls);
```
- `InclusionThreshold` (0-1) controls what fraction of mask pixels must be true for a block to be processed. Use `0` to include any block with at least one true pixel.
- **Smaller blocks follow contours better.** Decreasing `BlockSize` in `selectBlockLocations` creates a tighter wrap around the ROI and processes fewer pixels outside it. But if blocks are too small, per-block overhead dominates. Tune by benchmarking.

## ExtraImages for Pixel-level Masking
Pass a second blockedImage (e.g., a mask) via `ExtraImages` to access it in the block function alongside the primary image:
```matlab
bResult = apply(bim, @(bsImg, bsMask) maskAndProcess(bsImg, bsMask), ...
    ExtraImages=bmask, BlockLocationSet=bls);
```
If the extra image has a different resolution than the primary, `apply` delivers blocks covering the same world region — resize inside the function if pixel sizes differ:
```matlab
function bout = maskAndProcess(bsImg, bsMask)
    if ~isequal(size(bsMask), size(bsImg.Data, [1 2]))
        bsMask = imresize(bsMask, size(bsImg.Data, [1 2]), 'nearest');
    end
    bout = bsImg.Data .* cast(bsMask, class(bsImg.Data));
end
```

## In-place Apply with Resume
Write results back to the source location for incremental updates. Use H5Blocks with `ResumeWillOverwrite=true`:
```matlab
h5a = images.blocked.H5Blocks; h5a.ResumeWillOverwrite = true;
bim = apply(bim, @fcn, OutputLocation=bim.Source, Adapter=h5a, Resume=true);
```

----

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: 198kUpdated 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