Codec support#

Isocenter reads compressed pixel data at ingest and writes one of two transfer syntaxes on export. This page lists which decoder reads each syntax, what the export writes, and the limits a decode cannot catch.

What reads what#

Every read of a compressed frame goes through one decode: ingest(), Instance.get_pixel_data(), an icon, and the export’s readback. A file gets the same answer everywhere.

Transfer syntax

UID

Decoded by

JPEG Baseline, JPEG Extended

1.2.840.10008.1.2.4.50, .51

Pillow. Monochrome, unsigned files Pillow cannot read (12-bit JPEG Extended, for example) go through imagecodecs.

JPEG Lossless

1.2.840.10008.1.2.4.57, .70

pydicom’s plugins where one is installed, otherwise imagecodecs

JPEG-LS

1.2.840.10008.1.2.4.80, .81

pydicom’s plugins where one is installed, otherwise imagecodecs

JPEG 2000

1.2.840.10008.1.2.4.90, .91

pydicom’s plugins where one is installed, otherwise imagecodecs

High-Throughput JPEG 2000

1.2.840.10008.1.2.4.201, .202, .203

imagecodecs (openjpeg)

RLE Lossless

1.2.840.10008.1.2.5

pydicom’s own decoder

imagecodecs and Pillow are required dependencies and install with Isocenter. imagecodecs is also the JPEG 2000 encoder the default compressed export uses.

A file under any other compressed syntax (a video syntax such as MPEG2, or a private one) is refused at ingest when it holds pixels, with a row naming the syntax. A file with no pixel element (a report, a waveform, an encapsulated document) has nothing to decode. It is ingested and exported whatever transfer syntax its file meta names, and Instance.get_pixel_data() returns None for it. That answer comes from the file’s elements alone: Pixel Data, Float Pixel Data and Double Float Pixel Data. A file that holds one of them and does not decode raises.

A JPIP Referenced image (1.2.840.10008.1.2.4.94, .95, and the HTJ2K pair .204, .205) is not such a file. It has no pixel element because its pixels are on a server, named by Pixel Data Provider URL (0028,7FE0), and Isocenter does not fetch them. It is ingested. Then Instance.get_pixel_data() raises for it. export() writes nothing for it and leaves one ERROR row that names the transfer syntax. redact() under a rule whose zone matches it raises RedactionError. The same holds for any file with no pixel element that carries the URL at the top level of its data set under a syntax no decoder here reads. A URL inside a sequence item is not looked for. Such a file under MPEG2, say, has no pixels of its own and is exported, the item and its URL with it.

Where import imagecodecs itself fails, so does import isocenter, with that ImportError. The library imports imagecodecs when the library is imported, so no file is read and no row is written. Where imagecodecs imports and one of its codecs does not load (a wheel with a missing shared library, for example), a file that needs that codec is refused. Its ingest row and the error from Instance.get_pixel_data() end with imagecodecs could not decode it either: DelayedImportError: could not import name 'ljpeg_decode' from 'imagecodecs'. That text names the function of the codec that did not load, and no advice follows. Importing that codec’s own module shows the import’s error (python -c "import imagecodecs._ljpeg" for this one).

The library also has words for the case where imagecodecs did not import at all. They are imagecodecs is not available: its import raised ImportError, with the module it was importing where the failure names one, and a last line that begins Missing image codecs: imagecodecs did not import. Neither quotes the import failure’s own message, which can hold an install path. No installation of this release reaches them, for the reason above. They are there for a process in which the module was removed after import. Advice beginning Missing image codecs: is given only when a decoder is missing from the installation, never for a file refused on what it holds.

What the export writes#

The export writes two transfer syntaxes and no others:

  • Explicit VR Little Endian (1.2.840.10008.1.2.1), with use_compression=False. It is also written for every file with no pixel data, floating-point pixels, or 32- or 64-bit integer samples, which JPEG 2000 Lossless here cannot carry exactly (#771). It was Implicit VR Little Endian before #1107.

  • JPEG 2000 Lossless (1.2.840.10008.1.2.4.90), with use_compression=True, the default.

A source in any other syntax is decoded at ingest and re-encoded into one of those two. Nothing writes High-Throughput JPEG 2000. An HTJ2K source exports uncompressed or as JPEG 2000. What the export writes covers what compression does to colour images and lossy sources.

Decode limits#

  • A stream corrupted mid-stream can decode to plausible wrong values with no error. openjpeg (JPEG 2000, through Pillow and through imagecodecs) and lj92 (JPEG Lossless) report nothing for a stream with bytes damaged in the middle, and a second decoder returns the same wrong array. libjpeg-turbo (JPEG Baseline and Extended) reads a stream that lost data from its middle and still ends in its EOI marker, and fills the missing rows with mid-grey. A truncated stream is refused: a JPEG one because it does not end in EOI. JPEG-LS (CharLS) refuses mid-stream damage too.

  • 16-bit YBR_FULL JPEG-LS and JPEG 2000 files are refused. The conversion to RGB takes 8-bit samples only.

  • A 16-bit colour image exported with use_compression=True is JPEG 2000 that pydicom cannot read with Pillow alone. The file is conformant and lossless, and Isocenter reads it back exactly. pydicom’s Pillow plugin refuses every JPEG 2000 image with more than 8 bits and more than one sample per pixel. pydicom with pylibjpeg and pylibjpeg-openjpeg reads it exactly. pylibjpeg-openjpeg has no wheel for the free-threaded 3.14t build. For a recipient whose reader has only Pillow, export with use_compression=False. The export names each such instance at INFO. pydicom on its own installs no JPEG 2000 decoder, so any compressed export assumes the recipient has one.

  • High-Throughput JPEG 2000 is decoded under JPEG 2000’s rules for colour, signedness and sample width.

  • JPEG Baseline and Extended files Pillow cannot decode are read only when monochrome and unsigned. A colour one is refused, because the fallback decoder’s colour output differs from pydicom’s. A signed one is refused, because nothing here re-signs a lossy JPEG decode.

  • A JPEG 2000 codestream that is signed where PixelRepresentation 0 declares unsigned samples is refused. No decoder here returns those samples unsigned.

  • Frames beyond NumberOfFrames are dropped with a DATA_LOSS row, whether an offset table names them, pydicom’s walk of the fragments finds them, or a native element’s length holds them. Instance.get_pixel_data() on such a file refuses and names both counts. A multi-fragment file that declares one frame (or none) and has no offset table is read as one frame, unless it is RLE Lossless. RLE fragments are counted one per frame when there are more of them than declared frames and each begins an RLE frame header. Where pydicom finds no frame boundary in the fragments, the file is refused and both counts are named.

  • An Extended Offset Table is read as pydicom reads it. pydicom ignores the table when its Lengths element is a different length, and reads the frames from the fragments. Such a table that names more frames than NumberOfFrames still gets the DATA_LOSS row above. Such a table that names fewer, or the same number, is not counted. The file is then read exactly as the same file without the table is read: by its Basic Offset Table where that is populated, by its fragments where it is RLE Lossless, and by pydicom’s walk otherwise. When pydicom does read by the table and the table’s length is not a multiple of 8 bytes, the table names no whole number of frames. The file is then refused in a sentence that names the table’s length. Where pydicom refuses the file’s header (a missing or invalid Bits Stored, Pixel Representation or Photometric Interpretation, for example), the refusal is pydicom’s, which names that element.

  • A native 1-bit image whose frame is not a whole number of bytes is refused when its Pixel Data holds more frames than NumberOfFrames declares. A bit-packed frame of 3 by 3 pixels is nine bits, so the bytes beyond the declared frames cannot be cut into frames. The refusal names the bytes held and the bytes the declared frames need. A few bytes of padding that hold no further frame are read as padding. A file labelled YBR_FULL_422 is not refused this way. pydicom refuses or pads it by its own rule for that label. A file whose header pydicom refuses is not refused this way either. pydicom’s refusal names the missing or invalid element, and is the one given.

  • A stream whose precision exceeds BitsStored is read by the stream’s precision. JPEG, JPEG-LS and JPEG 2000 streams carry their own sample precision. Some encoders write BitsAllocated there (precision 16 under BitsStored 12). Where every decoded sample still fits BitsStored, nothing else happens. Where one does not, ingest writes one WARNING row per instance, which grades the run REVIEW_REQUIRED, and an export writes BitsStored from the samples.

  • A JPEG Lossless stream whose decoded samples exceed its own declared precision is reported when imagecodecs read it. For JPEG Lossless (.57/.70), imagecodecs returns the samples the stream encodes (up to 4970 for a precision-12 stream), and pydicom with pylibjpeg-libjpeg saturates them to 4095. Ingest writes one WARNING row per instance where a decoded sample lies outside the stream’s own precision. It does so for unsigned samples, and for signed samples where BitsStored is wider than the stream’s precision. The check reads the decoded samples, for every codec whose precision is read, so it can report only what a decoder returned. Four limits come with it:

    • The row cannot fire when pydicom’s plugin read the file, because a clamped array always fits its precision. What is reported depends on which decoder read the file.

    • A JPEG 2000 codestream holding such a sample is clamped at decode, and no row is written. A codestream can declare precision 12 and hold 4970. The two JPEG 2000 decoders that install with Isocenter, Pillow and imagecodecs, both decode with openjpeg. openjpeg returns that sample as 4095, the most that the declared precision holds. The clamped samples fit the precision, so ingest writes no row, and they are what is stored and exported. Nothing in Isocenter detects this, and nothing it writes says that it happened. Measured for a JPEG 2000 Lossless (.90) file with unsigned samples, through Pillow and through imagecodecs. pydicom decodes first, and uses another plugin where one is installed. pylibjpeg-openjpeg (measured at 2.6.0) is openjpeg too, and returns the same clamped samples. GDCM was not tried, and neither was any other JPEG 2000 decoder that is not openjpeg (#1057).

    • No JPEG-LS stream was found that decodes to such a sample, so no row has been seen for JPEG-LS. Two encoders were asked and neither writes one. imagecodecs.jpegls_encode declares precision 16 for 16-bit samples. Where it takes a precision (2026.10.10), it masks each sample into that precision as it encodes: 4970 at precision 12 is written, and read, as 874. DCMTK’s dcmcjpls does the same two things, with +pr and with +pc. A stream rewritten by hand to declare less than it holds does not decode beyond its precision either. imagecodecs decodes JPEG-LS with CharLS, and CharLS refuses a stream whose preset parameters state a largest sample above what the declared precision holds. A 16-bit stream from either encoder carries that statement, so its rewrite is refused as it stands. Where nothing states more than the precision holds, the outcome depends on the samples that were encoded. (An 8-bit stream carries no statement, and a 16-bit one can have its own taken out.) Some rewritten streams are refused. Some decode, at both widths, to samples that are not the ones encoded, every one of them inside the rewritten precision. Ingest reads those, the check finds nothing beyond the precision, and no row is written. Nothing reports that the samples are wrong. Measured with imagecodecs 2026.8.16 and 2026.10.10 (CharLS 2.4.4 in both) and DCMTK 3.7.0. pydicom decodes first and uses a plugin where one is installed. pylibjpeg-libjpeg (2.4.0, measured on Python 3.12 only), which is not CharLS, decodes every rewritten stream that was tried on it, those CharLS refuses included, each to samples inside the rewritten precision. Ingest of four such files stored those samples and wrote no row. pyjpegls (1.5.1), which is CharLS, was asked directly and answers as imagecodecs does, apart from a one-pixel stream it refuses. GDCM was not tried, and neither was any other JPEG-LS decoder (#684).

    • A signed JPEG Lossless stream beyond its own precision, under a BitsStored no wider than that precision, may read differently on the two routes. The fallback reads such a sample from its low bits (4970 at precision 12 reads 874). Its decode says so in a WARNING row, read from the codec’s array before the sign extension (#682). A pydicom plugin decodes first when one is installed, and on that route no row is written. JPEG-LS and JPEG 2000 have nothing to report here. Their sign extension keeps every sample inside the stream’s precision.

  • A colour image with no Planar Configuration is read color-by-pixel. Planar Configuration (0028,0006) is required when an image has more than one sample per pixel. Where it is absent or holds no value, ingest reads the samples color-by-pixel (0) and records 0 on the instance. The export writes 0 with an INFO note in the log. Section 5 of the compliance report counts such images and icons. No audit row is written, and the grade does not move (#1134). Nothing checks the layout against the pixels. A native file that is really stored color-by-plane reads with its colours wrong.

    For JPEG-LS, JPEG 2000 and HTJ2K, the codestream fixes the layout, and PS3.5 says the value “shall be set to 0”. For JPEG, PS3.5 says the stream is “always color-by-pixel and should be specified as such”. With pydicom’s Pillow plugin (JPEG Baseline and Extended, JPEG 2000), the element is what tells pydicom how to arrange Pillow’s output, so 0 is the right value there. An RLE Lossless image with no Planar Configuration is still refused in pydicom’s words. (RLE’s decoder fixes its own layout, and the exclusion is a ruling.) A value other than 0 or 1 under a native syntax or RLE is refused in the same way. A declared value under a compressed syntax is the subject of the next bullet.

  • Under a compressed syntax, a declared Planar Configuration is read as 0. Under JPEG (.50, .51, .57, .70), JPEG-LS (.80, .81), JPEG 2000 (.90, .91) and HTJ2K (.201, .202, .203), any declared value but 0 is read as 0. That covers 1, 2 or more, or several values. The instance or icon holds 0, and the export writes 0 with an INFO note in the log. Section 5 of the compliance report counts such images and icons on a line of its own. No audit row is written, and the grade does not move (#1137).

    PS3.5 says the stream decides:

    • JPEG-LS: “The Value of Planar Configuration (0028,0006) is irrelevant since the manner of encoding components is specified in the JPEG-LS bit stream as component, line or sample interleaved, hence it shall be set to 0.”

    • JPEG 2000 and HTJ2K: “The Value of Planar Configuration (0028,0006) is irrelevant since the manner of encoding components is specified in the JPEG 2000 standard, hence it shall be set to 0.”

    • JPEG: “JPEG compressed data streams are always color-by-pixel and should be specified as such (a decoder can essentially ignore this Data Element however as the value for JPEG compressed data is already known).”

    Before #1137, pydicom’s Pillow plugin (JPEG Baseline and Extended, 8-bit JPEG 2000) read a declared 1 with its colours scrambled, and a 2 was refused. Under a native syntax, a declared 1 still means the bytes are color-by-plane and is read so, and RLE Lossless is unchanged.

  • HighBit other than BitsStored − 1 is read, and says so. Samples are read right-aligned, by BitsStored or by the stream’s own precision. Ingest writes one WARNING row per such instance, which grades the run REVIEW_REQUIRED, and an export writes HighBit as BitsStored − 1.

Free-threaded Python and pylibjpeg-libjpeg#

pylibjpeg-libjpeg has no free-threaded wheel. On CPython 3.14t, pip install builds it from source and either fails or installs a package whose extension does not import. Built by hand, it imports and turns the GIL back on unless PYTHON_GIL=0 is set. Isocenter does not need it. Without it, JPEG Lossless and JPEG-LS decode through imagecodecs, which ships free-threaded wheels. Which decoder reads a file is what the precision limits above depend on.