$npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-process-large-imagesPatterns for using blockedImage to process large images, harness parallel compute for image processing, and write custom adapters. Use when writing code that creates, processes, or visualizes blockedImage objects, when implementing images.blocked.Adapter subclasses, or when a use
| 1 | ## When to Use |
| 2 | - Writing code that creates, processes, or visualizes `blockedImage` objects |
| 3 | - Implementing `images.blocked.Adapter` subclasses for custom file formats |
| 4 | - User needs help with large image data that doesn't fit in memory |
| 5 | - User wants to leverage parallel computing for image processing tasks |
| 6 | - Working with whole-slide images, geospatial rasters, 3D microscopy volumes, or tiled mosaics |
| 7 | - **Any time a user is working with a TIFF file** — load this skill and check the file first with `imfinfo`. Use `blockedImage` if the file is large (dimensions > 10,000 pixels in any axis), has multiple channels beyond RGB, or contains multiple IFDs (could be pyramid levels, time series, or Z-stack slices) |
| 8 | |
| 9 | ## When NOT to Use |
| 10 | - Image fits comfortably in memory and no parallel processing is needed — use standard `imread`/`imwrite` workflows |
| 11 | - General image display without `blockedImage` — use the `matlab-display-image` skill instead |
| 12 | - Deep learning model architecture or training loop design — this skill covers data preparation with `blockedImageDatastore`, not network design |
| 13 | |
| 14 | # Large Image Processing with blockedImage |
| 15 | |
| 16 | **Reference files** (read on demand when the topic comes up): |
| 17 | - `references/visualization.md` — imageshow, overlays, synced views, overview+detail, annotations |
| 18 | - `references/training-and-labeling.md` — Image Labeler, labeled blockedImages, training datastores, DL inference |
| 19 | - `references/3d-volumes.md` — 3D blocked images, 3D inference, 3D training data |
| 20 | - `references/geospatial.md` — GeoTIFF, shapefiles, coordinate systems, spatial referencing |
| 21 | - `references/data-discovery.md` — 7-step data discovery workflow, custom adapters, format conversion adapter selection, virtual composite adapters, adapter performance tips |
| 22 | - `references/specialized-workflows.md` — writing block-by-block, coordinate systems, mask-based block selection, ExtraImages for pixel-level masking, in-place resume |
| 23 | - `references/whole-slide-images.md` — importing WSI files via OpenSlide/Bio-Formats, choosing between libraries, display, downstream processing (segmentation, classification) |
| 24 | |
| 25 | ## When to use blockedImage |
| 26 | blockedImage is not only for data that exceeds RAM. Even when the data fits in memory, wrapping it as a blockedImage lets you harness a parallel cluster: each worker can independently read and write different blocks, enabling parallel partial reads and parallel writes into separate file blocks. |
| 27 | |
| 28 | **Always ask the user what their intent with the data is.** Ask about visualization, processing, DL training, archival, and whether they want to leverage parallel compute — even if the data fits in RAM. |
| 29 | |
| 30 | ## When the user points you at a directory or multi-file dataset |
| 31 | **ALWAYS read `references/data-discovery.md` and follow its 7-step workflow** before writing any code. The workflow covers: inspecting file layout, parsing naming conventions, understanding user intent, choosing between single blockedImage vs. collection, assessing random access capabilities, checking for gaps/overlaps, and recommending an approach (built-in adapter, format conversion, or custom adapter). |
| 32 | |
| 33 | ## Construction |
| 34 | ```matlab |
| 35 | % Read-only (auto-selects adapter; reads only metadata, fast) |
| 36 | bim = blockedImage("large_image.tif"); |
| 37 | |
| 38 | % Multiple images at once |
| 39 | [bim1, bim2] = blockedImage(["img1.tif", "img2.tif"]); |
| 40 | |
| 41 | % Writable |
| 42 | bim = blockedImage(dest, imageSize, blockSize, initVal, Mode="w"); |
| 43 | |
| 44 | % Override adapter |
| 45 | bim = blockedImage(source, Adapter=myAdapter); |
| 46 | ``` |
| 47 | |
| 48 | ## BlockSize |
| 49 | - Defaults to a factor of `IOBlockSize` (adapter's native read unit), targeting ~1024 or the minimum dimension size. |
| 50 | - The object's `BlockSize` is the default for all downstream processing and visualization. |
| 51 | - Override per-operation via the `BlockSize` name-value argument (e.g., when a DL network requires a fixed input size). |
| 52 | - For best performance, keep `BlockSize` as a multiple of `IOBlockSize` and as large as practical. |
| 53 | |
| 54 | ## Reading Data |
| 55 | - `getBlock(bim, blocksub)` — read one block by block subscript. Returns `[data, blockinfo]`. |
| 56 | - `getRegion(bim, pixelStart, pixelEnd)` — read an arbitrary pixel region. |
| 57 | - `gather(bim)` — load entire image into memory (only if it fits in RAM). Use `Level` to select resolution. |
| 58 | |
| 59 | ## Processing with `apply()` |
| 60 | `apply(bim, @fcn)` calls `fcn` on each block one at a time. Scales to arbitrarily large data. Supports `UseParallel=true` for cluster execution. |
| 61 | |
| 62 | Key name-value arguments: `BlockSize`, |