FUNCTION REFERENCE
dicomread
Read grayscale or three-component DICOM pixels (native, deflated, RLE, JPEG Baseline/Lossless), including multiple frames.
Read grayscale or three-component DICOM pixels (native, deflated, RLE, JPEG Baseline/Lossless), including multiple frames.
Syntax
X = dicomread(filename); X = dicomread(info); X = dicomread(___,'Dictionary',dictionaryFile)Returns raw stored samples as uint8/uint16 (grayscale or RGB) or int8/int16 (grayscale). Single-frame shapes are Rows-by-Columns for grayscale and Rows-by-Columns-by-3 for RGB; multiple frames return Rows-by-Columns-by-SamplesPerPixel-by-NumberOfFrames, retaining the singleton sample axis for grayscale. Only trailing singleton dimensions are trimmed. MONOCHROME1 and MONOCHROME2 values are unchanged: no rescaling, windowing, normalization or inversion. The scalar dicominfo struct form uses only its text Filename and reopens/revalidates the file. Relative filenames use Current Folder.
Differences from MATLAB: this bounded reader supports Part 10 implicit VR little endian, explicit VR little endian, explicit VR big endian and Deflated Explicit VR Little Endian (.99), using the same native pixel layouts after dataset inflation, plus RLE Lossless (1.2.840.10008.1.2.5) for the same grayscale/unsigned RGB types, single or multiple frames, plus 8-bit JPEG Baseline Process 1 (1.2.840.10008.1.2.4.50) in desktop builds. MONOCHROME1/2 requires SamplesPerPixel=1; RGB requires SamplesPerPixel=3 and PlanarConfiguration=0 (interleaved) or 1 (planar within each frame). Absent NumberOfFrames means 1; otherwise it must be a positive integer count. All frames are read. BitsAllocated must be 8 unsigned or 16 unsigned/signed; BitsStored must be 1 through BitsAllocated and HighBit=BitsStored-1. Unused bits are masked and signed stored samples are sign-extended. Only exact bytes for all samples and frames plus a single even-length padding byte when needed are accepted; individual native frames are not padded. Signed RGB, YBR, palette/indexed images, signed 8-bit, float, shifted-bit layouts, raw datasets, other compression/encapsulation (JPEG Extended 12-bit .51, JPEG-LS, HTJ2K .201-.203, video; RLE/JPEG writing; Extended Offset Tables), frame-selection and options other than Dictionary, and auxiliary outputs are not supported yet. A custom dictionary (dicomdict set or the Dictionary option) supplies the VRs of implicit files, so for those files it must list the pixel attributes dicomread needs (such as Rows, Columns and BitsAllocated). File admission is 256 MiB; engine dimension, evaluation and available workspace/scratch/output memory limits apply before pixel allocation. Deflated input requires a completed single raw RFC1951 stream (no zlib/gzip wrapper); exactly one trailing NUL is required when the compressed stream byte count is odd, and no trailing bytes are accepted when even. Missing/extra padding, concatenated streams and junk error. Decoded datasets are capped at 256 MiB and available engine memory before each capacity growth. Retained backing capacity, inflater/chunks, metadata, pixel scratch and typed output/transient copy all count against memory; engine work limits also bound inflation. RLE requires undefined-length OB PixelData with exactly one fragment per frame; an empty Basic Offset Table uses fragment order, a nonempty one must list every frame's fragment item offset. Each frame header must declare SamplesPerPixel*BitsAllocated/8 segments (MSB byte segment first per sample), first offset 64, strictly increasing offsets and zero unused entries. PlanarConfiguration must still be 0 or 1 for RGB but RLE segments are always by plane. PackBits runs may not cross a row or overfill/underfill a plane; -128 is a no-op; each segment must be even-length, with exactly one zero pad byte after an odd byte count and nothing else. Malformed tables, fragments, delimiters, segments or runs error. Offset table, one compressed frame, decoded planes and typed output/copy count against memory, and compressed bytes count as work, before decoding. JPEG Baseline is lossy: values are the decoder's reconstruction and can differ by a few levels from other decoders (checked against libjpeg-turbo within 1 level for grayscale and 3 for colour; in the last column or row of 4:2:2/4:2:0 colour frames whose size is even but not a multiple of 16, this decoder blends in padding samples and differences up to 8 levels were measured). It requires BitsAllocated=BitsStored=8 and PixelRepresentation=0. MONOCHROME1/2 return uint8 Rows-by-Columns unchanged; YBR_FULL_422 and YBR_FULL (SamplesPerPixel=3) are converted and returned as RGB uint8 Rows-by-Columns-by-3, while dicominfo still reports the stored PhotometricInterpretation; PlanarConfiguration must be present (0 or 1) but never reorders decoder output. PhotometricInterpretation RGB is accepted only when the stream itself signals untransformed RGB components (Adobe APP14 transform 0, or R,G,B component ids); an RGB header over an unmarked stream, a YBR header over an RGB-signalled stream, and other photometric values error. A frame may span several fragments: one frame with an empty Basic Offset Table concatenates all fragments; several frames need either a nonempty Basic Offset Table whose entries name each frame's first fragment item, or exactly one fragment per frame; frame boundaries are never guessed from JPEG markers. Every frame stream is validated before decoding: SOI first, one baseline SOF0 frame header with 8-bit precision and exactly Rows, Columns and SamplesPerPixel (extended, progressive, lossless and arithmetic frames are rejected), 1x1 grayscale or 4:4:4/4:2:2/4:2:0 colour sampling, one interleaved scan whose every Huffman-coded block and restart marker is complete, then EOI and at most one zero pad byte. Truncated or corrupt streams, extra data and multi-scan streams error; no partial image is returned. One concatenated frame stream, decoder buffers, all decoded frames and typed output/copy count against memory, and compressed bytes count as work, before decoding; the decoder call for one admitted frame is not interruptible. Builds without the desktop/plot-export image decoder report the transfer syntax and the missing JPEG decoder; dicominfo still works there. Reads/inflation/parsing/decoding/conversion are cancellable; no writes are performed. The browser has no file access. Writing and the remaining DICOM batch are subsequent slices.
Example
exist('dicomread','builtin') % 5JPEG Lossless (.57 and .70) is available in every engine build, independently of the desktop decoder. It accepts SOF3 precision 2..16 equal to BitsStored, BitsAllocated 8 or 16, and one or three components with dimensions matching Rows/Columns. MONOCHROME1/2 return raw samples without inversion; RGB returns stored RGB; YBR_FULL returns stored Y/Cb/Cr without colour conversion (dicominfo keeps the stored PhotometricInterpretation). PixelRepresentation selects uint8/int8 or uint16/int16; signed samples use two's complement over BitsStored. Three-component data must be unsigned. Layout is R-by-C-by-S-by-F with trailing singleton dimensions removed, as for native reads. Both syntaxes share the baseline fragment/BOT rules and reject Extended Offset Tables. Process 14 accepts predictors 1..7; .70 requires predictor 1. Point transforms are restored once after decoding reduced samples. Only one interleaved scan with 1x1 component sampling is supported; nonzero restart intervals error explicitly because of the decoder's predictor-reset limitation. Complete entropy data, EOI and at most one zero pad byte are required; no partial image is returned. Compressed buffers, decoder workspace and output count against a 256 MiB peak cap and the remaining workspace budget. Cancellation is polled during validation, concatenation, decoder reads and conversion and between frames; reconstruction within one admitted frame is not interruptible. JPEG Extended .51, JPEG-LS and HTJ2K .201-.203 remain explicitly unsupported.
JPEG 2000 Part 1 (.90 lossless only and .91 reversible or irreversible) is available in every engine build. It accepts raw J2K codestreams with precision 1..16, BitsAllocated 8 or 16, one or three full-resolution components, signed or unsigned, and single or multiple frames. Output classes are uint8/int8/uint16/int16; dimensions are R-by-C-by-S-by-F with trailing singleton dimensions removed. MONOCHROME1/2 return raw samples without inversion; RGB with MCT disabled returns stored RGB. YBR_RCT with reversible MCT and YBR_ICT with irreversible MCT return decoder RGB. dicominfo reports PhotometricInterpretation unchanged from the file, including YBR_RCT/YBR_ICT. Metadata/MCT, size, component, precision, sign and sampling mismatches error. .90 requires reversible 5/3 with no quantization; JP2 box wrappers and partial images error. Fragment/BOT rules are shared with baseline/lossless JPEG; Extended Offset Tables remain unsupported. Packed packet headers (PPM/PPT) are explicitly unsupported. SIZ tile count is capped at 4096, decomposition levels at 16, quality layers at 1024 and total packets at 1048576; image, nominal tile, coding/precinct workspace, compressed buffers and typed output/copies must fit the remaining engine budget and a hard 256 MiB peak cap. Full resolution and all quality layers are decoded. Cancellation is checked during concatenation, validation, conversion and between frames; the decoder call for one admitted frame is not interruptible. Strict pure-Rust decoding is bounded before that call and decoder failures/panics become malformed-codestream errors. No JPEG 2000 writing is provided.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.