All formats

JPEG 2000 (JP2, J2K, JPX)

Full nameJPEG 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 typeimage/jp2, image/jpx, image/jpm, image/j2c, image/jph
Typeraster image, lossy and lossless compression (discrete wavelet transform)
Starts withJP2/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)
SpecificationITU-T T.800 (JPEG 2000 Part 1), free download
Also standardized asISO/IEC 15444-1 (core), 15444-2 (JPX extensions), 15444-6 (JPM), 15444-15 (HTJ2K)
Maintained byISO/IEC JTC 1/SC 29 (JPEG committee) and ITU-T
Licenseopen; 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:

When to use JPEG 2000#

File structure#

JPEG 2000 data comes in 2 layers:

  1. the codestream: the compressed image itself, a sequence of markers and packets. A raw codestream is a .j2k or .j2c file.
  2. 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#

  1. Optional color transform: RGB to YCbCr. The reversible transform (RCT) is used for lossless files, the irreversible transform (ICT) for lossy ones.
  2. The image can be split into tiles, each compressed independently.
  3. 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.
  4. 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.
  5. 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#

Specifications and documentation#

Software that opens JPEG 2000 files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; also shows JPEG 2000 images inside PDF files
macOS Preview✓view, convertbuilt into macOS
GIMP✓✓✓view, edit, convertfree, open source, uses OpenJPEG
IrfanView✓view, convertfree for non-commercial use, needs the plugins package
XnView MP✓✓✓view, convertfree for private use
Adobe Photoshop✓✓view, edit, convertcommercial, JPEG 2000 is an optional plugin
ImageMagick✓✓✓convert, createcommand line, open source, uses OpenJPEG
OpenJPEG tools✓✓✓convert, createopj_compress, opj_decompress, opj_dump
GDAL✓✓✓convertgeospatial JPEG 2000 (OpenJPEG, Grok, Kakadu drivers)
QGIS✓✓✓viewfree, open source GIS, shows georeferenced JP2
DCP-o-matic✓✓✓create, convertfree, open source; makes digital cinema packages
Weasis✓✓✓viewfree, open source DICOM viewer, JPEG 2000 transfer syntaxes
Kakadu✓✓✓view, convert, createcommercial 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
Javajai-imageio-jpeg2000
Gogovips
Pythonglymur, imagecodecs, Pillow
Rubyruby-vips
Rusthayro-jpeg2000, jpeg2k
PHPImagick