Converting image to Jpeg2000 does not work

7,550

Solution 1

What am I doing wrong?

Nothing. The command you typed in is correct. The problem is that *.jp2 (JPEG 2000) support isn't built into the repository version of Imagemagick. When converting to an unsupported format the resulting destination file will be the same format as the source file.

You can verify this by looking at the fourth lines of the convert -version output:

$ convert -version

Output:

Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-11-29 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

Notice that jp2 isn't included.

This is a reported bug (imagemagick: missing JPEG-2000 support):

The bug report describes the problem and indicates it has been fixed in the latest release (Version 6.9.1.2-1) which hasn't reached the repository yet.

Another test for jp2 support is:

$ identify -list format | egrep -i jp2

There is a use at your own risk PPA at:
https://launchpad.net/~isage-dna/+archive/ubuntu/imagick

Update:

As provided by SamWilson in the commands a supported PPA which I tested is located at: https://launchpad.net/~lyrasis/+archive/ubuntu/imagemagick-jp2

sudo add-apt-repository ppa:lyrasis/imagemagick-jp2
sudo apt-get update

Solution 2

This is still an issue as of February 2021. AFAIK JPEG 2000 support is disabled in Ubuntu due to a perceived risk of submarine patents.

However, there is a workaround that doesn't involve using third-party PPAs or compiling software yourself. The libopenjp2-tools package contains a decoding tool called opj_decompress that is able to convert .jp2 files into various lossless formats, including PNG, BMP, TIF, and RAW. It can even convert entire directories of files without the aid of external tools.

Convert a single file to TIF:

opj_decompress -i input.jp2 -o output.tif

Convert a directory of files to TIF:

opj_decompress -ImgDir my_jp2_images/ -OutFor TIF

Unfortunately, the native directory conversion isn't very fast due to it not being multithreaded. I've had to work on a large number of JPEG 2000 files over the years, and I've begun to use GNU Parallel to speed up the conversion process by using all the available CPU threads.

Converting all .jp2 files in a directory to .tif (need to be cd'd to the directory containing the files):

ls *.jp2 |parallel -j 10 --nice 19 --bar --will-cite "opj_decompress -i {} -o {}.tif"

Change the value of -j to however many threads want to use.

These files are very large since they don't use compression of any kind, so if you need to transfer them over a network or intend to store the them long-term, you might want to reduce their size by applying LZW compression:

ls *.tif |parallel -j 10 --nice 19 --bar --will-cite "mogrify -compress lzw {}"

In my experience, this can reduce file size by up to 50%.

Solution 3

Try this

convert example2.png -quality 0 example.jp2
Share:
7,550

Related videos on Youtube

guettli
Author by

guettli

http://thomas-guettler.de/ Working out loud: https://github.com/guettli/wol

Updated on September 18, 2022

Comments

  • guettli
    guettli over 1 year

    I try to convert an image to Jpeg2000:

    convert example2.png -quality 95 example.jp2
    

    But the output is still png:

    file example.jp2
    example.jp2: PNG image data, 2549 x 3507, 8-bit/color RGB, non-interlaced
    

    What am I doing wrong?

    convert -version
    Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-11-29 http://www.imagemagick.org
    
  • guettli
    guettli over 7 years
    "When converting to an unsupported format the resulting destination file will be the same format as the source file." I think sometimes it's better if software does not do guessing. In this case I would prefer an error :-) Thank you very much for your answer!
  • Apologician
    Apologician over 7 years
    I agree. That's a confusing behavior. It's most likely causing man images to float around everywhere with a wrong extension. People are sharing files that won't work for a lot of people. I'll put in a bug/feature request to the developers to fix this problem.
  • Sam Wilson
    Sam Wilson over 7 years
  • Apologician
    Apologician over 7 years
    @SamWilson I tested it and it works. Will add the information to the answer.
  • Sam Wilson
    Sam Wilson over 7 years
    @L.D.James thanks. Unfortunately, I've been trying it, and I don't get JP2 support :-( It appears to not replace the old imagemagick version (apt install says 8:6.9.6.6+dfsg-1ubuntu3~ubuntu16.04.1~ppa7 but identify -version says 6.8.9-9 ) Do you have any ideas?
  • Sam Wilson
    Sam Wilson over 7 years
    Ah, I had to explicitly install libmagickcore-6.q16-2 :-) Works now.
  • Apologician
    Apologician over 7 years
    Glad it's working!