Ubuntu – How to enable JPEG2000 (jp2) in ImageMagick

configurationimagemagicksoftware installation

I want to use ImageMagick to convert some files from jp2 (JPEG-2000) to jpg. The command to do that is fine, but I don't know how to enable the jp2 delegate in ImageMagick.

I installed ImageMagick via package manager: sudo apt-get install ImageMagick.
I'm using ImageMagick 6.8.9-9, this is the most up to date version of ImageMagick available from apt-get.

Currently, a lot of the main file types are automatically included. The following libraries have built-in support and are listed as delegates:

bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

Edit: I should have mentioned, I did try file conversions before starting to wrangle with openjpeg-2. A command like convert input.jp2 output.jpg gives me the error message:

convert: no decode delegate for this image format `JP2' @ error/constitute.c/ReadImage/501.

So, I need to get jp2 working. The relevant library is openjpeg-2, and ImageMagick's delegates page gives the tarball, openjpeg-2.0.0.tar.gz.

Okay, so I downloaded it and followed the instructions to install given in the install file. Normal stuff: cmake ., sudo make install.

But now, how do I configure ImageMagick so that it 'picks up' open-jpeg-2.0.0? Do I have to rebuild ImageMagick from source to do so? Or is there a command I can enter to get ImageMagick to enable it? Or a file I should change, etc?

I have spent ages and ages looking into this, read many Q&As online, but I still did not crack it. It is an issue of my Linux knowledge rather than something to do with ImageMagick per se, so I would really appreciate it if someone can help me figure out what the missing step is here. Thank you.

Best Answer

Install libopenjp2-tools and use opj_decompress to convert jp2 to something else:

sudo apt install libopenjp2-tools
opj_decompress -i m_3712213_sw_10_h_20160625_20161004.jp2 -OutFor TIF -o my.tif

This package provides with command-line tools allowing for conversions between several formats and also provides tools for encoding and decoding motion-jpeg2000 video formats:

  • opj_decompress: decodes j2k, jp2, and jpt files to pgm, ppm, pnm, pgx, and bmp.
  • opj_compress: encodes pnm, pgm, pgx, bmp, and ppm files to j2k, and jp2.
  • opj_dump: dump information contains in j2k and jp2.
  • index_create: create jp2 with JPIP index file from a j2k file.
  • frames_to_mj2: convert YUV video streams to mj2 format.
  • mj2_to_frames: convert mj2 video streams to YUV format.
  • wrap_j2k_in_mj2: wrap j2k codestreams into mj2 format.
  • extract-j2k-from_mj2: extract j2k codestreams from the mj2 format.