12

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.

  • I solved this problem by using graphicsmagick instead, e.g. gm convert in.jp2 out.jpg – Sam Wilson May 11 '17 at 1:19
2

I resolve my problem of enabling the openjp2 delegation in Imagemagick.

Be sure you have install :

Now when you launch ./configure you can see openjp2 delegation

DELEGATES = mpeg jbig jng jpeg lcms lzma openjp2 png tiff zlib

2

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.
1

From my default installation of Image Magick 6.8.9.9 from the Ubuntu 16.04 repositories it appears that Jpeg200 (.jp2) is fully supported.

Conversions can be done with:

convert in.png out.jp2
convert in.jp2 out.jpg

For command line options esp. regarding encoding options or handling of tiled images see Image Magick online documentation.

It has to be said however that jp2 is not listed in the list of supported formats:

identify -list format

Nevertheless it apparently still works fine.

  • 1
    Thanks @Takkat, that's not the case for me though. When I try this (convert in.jp2 out.jpg), I get the error message that I don't have the jp2 delegate: convert: no decode delegate for this image format 'JP2' @ error/constitute.c/ReadImage/501. I'm at 6.8.9.9 (from convert --version: Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-03-14 imagemagick.org). Really odd that your version doesn't list jp2 as a format but still works! Are the jpg output files valid? – arokath Apr 2 '17 at 22:30
  • PS: there's a typo in your link: php not ph2 :) – arokath Apr 2 '17 at 22:37
  • @arokath: yeah files are valid - I tested conversion from and to. Reading JPG with ImageViewer or Gimp is OK, reading JP2 with Gimp or Darktable was fine. – Takkat Apr 3 '17 at 6:32
  • 1
    Hmm, I looked at that bug report. Even with installing libopenjp2-dev and then rebuilding from source, it still isn't working. I'm 100% stuck still unfortunately. Thank you for your replies, though! – arokath Apr 6 '17 at 1:27
  • 1
    This is not an answer to the question. You are just saying that it works for you! And giving a link to the documentation is not an answer! – Azim May 12 at 13:16
1

@arokath Like you, I was unable to find jp2 support in the version of ImageMagick that I installed through apt-get (Ubuntu 16.04.1 LTS).

Before building from source (following the ImageMagick docs), I installed first libopenjp2-tools and then libopenjp2-7-dev.

Note: I'm not sure which one did the trick: the alphabetical summary at the end of configure listed jp2 support as OpenJP2, rather than JP2 which I didn't notice until I had installed libopenjp2-7-dev and re-configured; it's quite possible it worked with only the first lib.

Besides ./configure, make and make install, I found that I needed (as suggested in the docs) to "configure the dynamic linker": sudo ldconfig /usr/local/lib.

Now, output of /usr/local/bin/identify -list format contains:

  J2C* rw-   JPEG-2000 Code Stream Syntax (2.1.0)
  J2K* rw-   JPEG-2000 Code Stream Syntax (2.1.0)
  JNX* r--   Garmin tile format
  JP2* rw-   JPEG-2000 File Format Syntax (2.1.0)
  JPC* rw-   JPEG-2000 Code Stream Syntax (2.1.0)
  JPM* rw-   JPEG-2000 File Format Syntax (2.1.0)
  JPT* rw-   JPEG-2000 File Format Syntax (2.1.0)
 JSON  -w+   The image format and characteristics
  • 1
    Thanks for this. I'm still having problems, unfortunately! I installed libopenjp2-tools and libopenjp2-7-dev using apt-get, then built from source, then ran sudo ldconfig /usr/local/lib. (In other words, followed the docs). STILL no JP2. Argh! It's doing my head in. I'll run through the process again just in case. – arokath Apr 3 '17 at 21:48
  • Still no luck. I noticed that when running ./configure, it checks for JP2 and doesn't find it: "checking for LIBOPENJP2... no". As a bonus, now it's not working for JPEG conversions in general. When I tried convert in.png out.jpg it creates a file, but it's invalid - it's a PNG file just with the jpg extension. I don't know why JPEG should suddenly be broken when I've compiled from source! – arokath Apr 3 '17 at 22:20
  • Try running "apt-get build-dep imagemagick" so it installs the libraries needed by imagemagick (these will be the ones it was built with in the release, so you'll still need openjp2) – cbz May 23 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.