JPEG 2000 (JP2, J2K, JPX)
| Full name | JPEG 2000 |
|---|---|
| Extensions | .jp2 (JP2 file), .j2k and .j2c (raw codestream), .jpx and .jpf (extended JPX file), .jpm (compound document), .jph (HTJ2K in a JP2-style file) |
| MIME type | image/jp2, image/jpx, image/jpm, image/j2c, image/jph |
| Type | raster image, lossy and lossless compression (discrete wavelet transform) |
| Starts with | JP2/JPX/JPM: 00 00 00 0C 6A 50 20 20 0D 0A 87 0A (signature box jP); raw codestream: FF 4F FF 51 (SOC + SIZ markers) |
| Specification | ITU-T T.800 (JPEG 2000 Part 1), free download |
| Also standardized as | ISO/IEC 15444-1 (core), 15444-2 (JPX extensions), 15444-6 (JPM), 15444-15 (HTJ2K) |
| Maintained by | ISO/IEC JTC 1/SC 29 (JPEG committee) and ITU-T |
| License | open; Part 1 is meant to be implementable royalty-free |
JPEG 2000 compresses images with a discrete wavelet transform instead of the 8x8 DCT blocks of JPEG. It supports lossless and lossy compression in the same format, 1 to 38 bits per sample, up to 16384 components, very large images with tiling, and progressive decoding by quality, resolution or position. A decoder can extract a lower-resolution version or a region of an image without decoding the whole file.
Web browsers don’t support it, but JPEG 2000 is widely used in specialized fields:
- PDF: images compressed with the
JPXDecodefilter are JPEG 2000 codestreams or JP2 files. Scanned books and maps often use it. See PDF. - Digital cinema: every frame of a DCP (Digital Cinema Package) is a JPEG 2000 codestream, wrapped in MXF, at 2K or 4K resolution.
- Medical imaging: DICOM defines JPEG 2000 transfer syntaxes (lossless and lossy) and, since 2023, HTJ2K transfer syntaxes.
- Geospatial and archives: satellite imagery (Sentinel-2, Pleiades) and digitized collections in libraries and archives, often with GeoJP2 or GMLJP2 metadata.
When to use JPEG 2000#
- Use when you need lossless and lossy compression of high bit depth images (12-bit or 16-bit medical, scientific and satellite images).
- Use for very large images where viewers need fast zoom and pan: tiles and resolution levels let a server or viewer decode only what’s shown.
- Use when a standard requires it: DCI digital cinema, DICOM, PDF/A with JPX images, archival profiles.
- Use HTJ2K (Part 15) when encoding and decoding speed matters: it’s about 10 times faster than classic JPEG 2000 block coding.
- Avoid for images on the web: no browser displays it. Use WebP, AVIF or JPEG.
- Avoid when you need fast, simple software support everywhere: decoding is slow compared to JPEG, and fewer programs read it.
File structure#
JPEG 2000 data comes in 2 layers:
- the codestream: the compressed image itself, a sequence of markers and packets. A raw codestream is a
.j2kor.j2cfile. - the file format (JP2, JPX, JPM): a box structure around the codestream that adds color space, resolution and metadata. JP2 is the basic file format of Part 1; JPX (Part 2) adds more color spaces, multiple codestreams and compositing; JPM (Part 6) stores compound documents like scanned pages with separate text and background layers.
Boxes (JP2, JPX, JPM)#
A JP2 file is a sequence of boxes, the same idea as ISO base media (MP4) boxes. Each box starts with a 4-byte big-endian length (including the 8-byte header) and a 4-byte type. A length of 1 means a 64-bit length follows; 0 means the box runs to the end of the file.
00 00 00 0C 6A 50 20 20 length 12, type 'jP ' (signature box)
0D 0A 87 0A signature contents
00 00 00 14 66 74 79 70 length 20, type 'ftyp' (file type box)
6A 70 32 20 brand 'jp2 '
00 00 00 00 minor version
6A 70 32 20 compatibility list: 'jp2 '
00 00 00 2D 6A 70 32 68 length 45, type 'jp2h' (header superbox)
00 00 00 16 69 68 64 72 length 22, type 'ihdr'
00 00 01 E0 00 00 02 80 height 480, width 640
00 03 07 07 00 00 3 components, 8 bits (7+1), compression 7, ...
00 00 00 0F 63 6F 6C 72 length 15, type 'colr'
01 00 00 00 00 00 10 method 1 (enumerated), color space 16 (sRGB)
xx xx xx xx 6A 70 32 63 type 'jp2c' (contiguous codestream box)
FF 4F FF 51 ... codestream
| Box | Purpose |
|---|---|
jP |
signature, always first, always the same 12 bytes |
ftyp |
file type: brand jp2, jpx or jpm, plus compatible brands |
jp2h |
header superbox containing the boxes below |
ihdr |
image header: height, width, number of components, bit depth |
colr |
color space: enumerated (16 = sRGB, 17 = greyscale, 18 = sYCC) or an embedded ICC profile |
res |
capture and display resolution |
pclr, cmap |
palette and component mapping |
cdef |
channel definitions, e.g. which component is alpha |
jp2c |
the codestream |
xml, uuid |
metadata: XMP is stored in a uuid box, GMLJP2 in xml or asoc boxes |
Codestream markers#
The codestream starts with a main header of 2-byte markers (FF xx), followed by one or more tiles. Each tile starts with an SOT marker and contains packets of compressed data.
| Marker | Code | Purpose |
|---|---|---|
| SOC | FF 4F |
start of codestream |
| SIZ | FF 51 |
image and tile size, number of components, bit depth and subsampling per component |
| CAP | FF 50 |
capabilities (Part 15 HTJ2K and later parts) |
| COD, COC | FF 52, FF 53 |
coding style: progression order, quality layers, decomposition levels, code-block size, wavelet (5/3 reversible or 9/7 irreversible), color transform |
| QCD, QCC | FF 5C, FF 5D |
quantization |
| TLM, PLT | FF 55, FF 58 |
tile and packet lengths, for fast random access |
| COM | FF 64 |
comment |
| SOT | FF 90 |
start of tile-part |
| SOD | FF 93 |
start of data (compressed packets follow) |
| EOC | FF D9 |
end of codestream |
How compression works#
- Optional color transform: RGB to YCbCr. The reversible transform (RCT) is used for lossless files, the irreversible transform (ICT) for lossy ones.
- The image can be split into tiles, each compressed independently.
- A discrete wavelet transform splits each tile into subbands over several resolution levels. The 5/3 integer wavelet is lossless, the 9/7 floating-point wavelet is lossy.
- Subbands are divided into code-blocks (usually 64x64), which are coded bit plane by bit plane with an arithmetic coder (EBCOT). HTJ2K replaces this step with a much faster block coder.
- Coded data is grouped into packets and quality layers. The progression order (LRCP, RLCP, RPCL, PCRL, CPRL) decides whether a truncated file gives a lower quality, a lower resolution or a smaller region.
Lossy compression is set by a target compression ratio or bit rate per layer, not by a 1-100 quality scale.
Variants#
| Variant | Spec | What it adds |
|---|---|---|
| JP2 | Part 1 (ITU-T T.800) | baseline file format and codestream |
| JPX | Part 2 (ITU-T T.801) | more color spaces, multiple codestreams, compositing, extended wavelet options |
Motion JPEG 2000 (.mj2) |
Part 3 (ITU-T T.802) | video as a sequence of JPEG 2000 frames in an ISO base media file |
| JPM | Part 6 | compound documents with mask, foreground and background layers |
| JPIP | Part 9 | network protocol to stream regions and resolutions from a server |
HTJ2K (.jph, .jhc) |
Part 15 (ITU-T T.814) | high-throughput block coder, about 10 times faster, lossless transcoding to and from Part 1 |
| DCI profiles | Part 1 profiles | fixed 2K/4K parameters and maximum bit rate for digital cinema |
Converting JPEG 2000#
- With OpenJPEG’s command-line tools:
opj_decompress -i in.jp2 -o out.pngandopj_compress -i in.png -o out.jp2 -r 20(20:1 lossy) or without-rfor lossless. - With ImageMagick:
magick in.jp2 out.pngandmagick in.png -quality 40 out.jp2. - With GDAL for geospatial files:
gdal_translate in.jp2 out.tif. opj_dump -i in.jp2prints the boxes and codestream parameters, useful to debug a file.
Specifications and documentation#
- ITU-T T.800: JPEG 2000 core coding system (identical to ISO/IEC 15444-1), free PDF from ITU
- ITU-T T.801: JPEG 2000 extensions (JPX) (ISO/IEC 15444-2)
- ITU-T T.814: High-throughput JPEG 2000 (HTJ2K) (ISO/IEC 15444-15)
- JPEG 2000 at jpeg.org: overview of all parts
- RFC 3745: MIME types for JPEG 2000
- JP2 format description, Library of Congress
- OpenJPEG test data: conformance and regression test files
- JPEG 2000 on Wikipedia
Software that opens JPEG 2000 files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; also shows JPEG 2000 images inside PDF files | |||
| macOS Preview | ✓ | view, convert | built into macOS | |||
| GIMP | ✓ | ✓ | ✓ | view, edit, convert | free, open source, uses OpenJPEG | |
| IrfanView | ✓ | view, convert | free for non-commercial use, needs the plugins package | |||
| XnView MP | ✓ | ✓ | ✓ | view, convert | free for private use | |
| Adobe Photoshop | ✓ | ✓ | view, edit, convert | commercial, JPEG 2000 is an optional plugin | ||
| ImageMagick | ✓ | ✓ | ✓ | convert, create | command line, open source, uses OpenJPEG | |
| OpenJPEG tools | ✓ | ✓ | ✓ | convert, create | opj_compress, opj_decompress, opj_dump | |
| GDAL | ✓ | ✓ | ✓ | convert | geospatial JPEG 2000 (OpenJPEG, Grok, Kakadu drivers) | |
| QGIS | ✓ | ✓ | ✓ | view | free, open source GIS, shows georeferenced JP2 | |
| DCP-o-matic | ✓ | ✓ | ✓ | create, convert | free, open source; makes digital cinema packages | |
| Weasis | ✓ | ✓ | ✓ | view | free, open source DICOM viewer, JPEG 2000 transfer syntaxes | |
| Kakadu | ✓ | ✓ | ✓ | view, convert, create | commercial SDK; free demo apps kdu_expand, kdu_compress |
Libraries#
Open-source libraries that read and write JPEG 2000. See all JPEG 2000 libraries for a comparison.
| C/C++ | Grok, OpenJPEG |
|---|---|
| C# | CoreJ2K, Magick.NET |
| Java | jai-imageio-jpeg2000 |
| Go | govips |
| Python | glymur, imagecodecs, Pillow |
| Ruby | ruby-vips |
| Rust | hayro-jpeg2000, jpeg2k |
| PHP | Imagick |
Related formats#
- JPEG: the common DCT-based format, much better supported, smaller decoders
- JPEG XL: newer royalty-free format with lossless JPEG recompression, also good for high bit depth
- JPEG XR: Microsoft’s HDR-capable format, another unsuccessful JPEG successor
- TIFF: common container for large, high bit depth and geospatial images
- PDF: stores JPEG 2000 images with the JPXDecode filter