Tuning options to convert images to JP2

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
frooms
Posts: 1
Joined: 2015-04-01T07:25:12-07:00
Authentication code: 6789

Tuning options to convert images to JP2

Post by frooms »

Dear users,

I would like to try the following:

We have a lot of TIFF 16bit grayscale images and we need to convert them to JP2 16bit grayscale images. I tried the following:

Code: Select all

convert fileIn.Tif -define jp2:quality=60 -set colorspace GRAY filOut.jp2
I also tried the following

Code: Select all

convert fileIn.Tif -define jp2:quality=60 -colorspace GRAY filOut.jp2
The result however seems to be a 3-channel JP2 image. Is there a way to make sure that the resulting image is gray-valued, i.e.,
has a single channel?

Many thanks in advance.

Kind regards,

Filip
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tuning options to convert images to JP2

Post by fmw42 »

I am not an expert on JP2. But what version of IM are you using and what platform? IM switched from the older less versatile Jasper delegate library to the OpenJpeg 2000 library? Do you know which you are using?

convert -list format

should identify that for you.

For example from my system:

Code: Select all

      JP2* JP2       rw-   JPEG-2000 File Format Syntax (2.1.0)
      JPC* JP2       rw-   JPEG-2000 Code Stream Syntax (2.1.0)
      JPE* JPEG      rw-   Joint Photographic Experts Group JFIF format (90)
     JPEG* JPEG      rw-   Joint Photographic Experts Group JFIF format (90)
      JPG* JPEG      rw-   Joint Photographic Experts Group JFIF format (90)
      JPM* JP2       rw-   JPEG-2000 Code Stream Syntax (2.1.0)
      JPS* JPEG      rw-   Joint Photographic Experts Group JFIF format (90)
      JPT* JP2       rw-   JPEG-2000 File Format Syntax (2.1.0)

Does putting -colorspace gray earlier work and differently?

Code: Select all

convert fileIn.Tif -colorspace GRAY-define jp2:quality=60  filOut.jp2
see http://www.imagemagick.org/script/comma ... php#define

"jp2:quality=value,value...
Sets the quality layer PSNR, given in dB. The order is from left to right in ascending order. The default is a single lossless quality layer. Same for JPT, JC2, and J2K"

JP2 quality is in db not percent.
Nemo_bis
Posts: 11
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Tuning options to convert images to JP2

Post by Nemo_bis »

I'm stuck on 6.7.7-10 because of reasons, is there any setting I can use? http://www.imagemagick.org/script/jp2.php seems to talk of recent versions only:

Code: Select all

$ convert 00001.tif -define jp2:quality=60 00001.60.jp2
warning: ignoring invalid option quality
$  convert 00001.tif -quality=60 00001.60.jp2
convert.im6: unrecognized option `-quality=60' @ error/convert.c/ConvertImageCommand/2273.
All the other settings on the documentation also have no effect for me: I tried [tt]-define jp2:number-resolutions=1[/tt], [tt]-define jp2:layer-number=1[/tt], [tt]-define jp2:rate=N[/tt], [tt]-colorspace GRAY[/tt] and they all gave the same output.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Tuning options to convert images to JP2

Post by snibgo »

Nemo_bis wrote:convert.im6: unrecognized option `-quality=60' @ error/convert.c/ConvertImageCommand/2273.
Don't use an "=".

Code: Select all

-quality 60
JP2 is relatively new in IM.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tuning options to convert images to JP2

Post by fmw42 »

Older releases of IM used the Jasper delegate library to process JP2. Newer release use OpenJPEG do that. Jasper is more limited in the types of JP2 that are supported. The change was at IM 6.8.9.1 and requires OpenJPEG 2.1.

From the IM Changelog

2014-04-22 6.8.9-1 Cristy <quetzlzacatenango@image...>
Require OpenJP2 version 2.1.0 (opj_stream_set_user_data() method signature change between 2.0.0 and 2.1.0).
Nemo_bis
Posts: 11
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Tuning options to convert images to JP2

Post by Nemo_bis »

Yes I know JP2 is relatively new, and it's great that IM supports it at all! The landscape for JP2/JPEG 2000 in FLOSS isn't favourable at all.
snibgo wrote:Don't use an "=".

Code: Select all

-quality 60
Ahem, right. Sorry. This works in 6.7.7-10. I got confused because neither command works on fedora 21/22, while the current Ubuntu version recognises "-quality 60". Is it the only option available with JasPer?
fmw42 wrote:Older releases of IM used the Jasper delegate library to process JP2. Newer release use OpenJPEG do that. Jasper is more limited in the types of JP2 that are supported. The change was at IM 6.8.9.1 and requires OpenJPEG 2.1.
Sure, in fact I also reported the thing to Fedora (6.8.8.10): https://bugzilla.redhat.com/show_bug.cgi?id=1267391
Do all the options in http://www.imagemagick.org/script/jp2.php work only with IM 6.8.9.1 + openjpeg 2.1+, or is any of them available for older versions, other than "-quality X"?

I'd like to do further tests, I'll check what packages exist or consider compiling myself. On Ubuntu I have both jasper and openjpeg installed but I suppose IM is built with jasper. I'm not sure whether the available openjpeg is a sufficiently recent one.

Code: Select all

$ identify -version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
$ identify -list configure | grep LIBS
LIBS          -lMagickCore -llcms2 -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lfftw3 -lfontconfig -lfreetype -lXext -lSM -lICE -lX11 -lXt -llzma -lbz2 -lz -lm -lgomp -lpthread -lltdl
$ dpkg -l | grep openjp
ii  libopenjpeg2:amd64                        1.3+dfsg-4.7ubuntu1                  amd64        JPEG 2000 image compression/decompression library
$ dpkg -l | grep jasper
ii  libjasper1:amd64                          1.900.1-14ubuntu3.2                  amd64        JasPer JPEG-2000 runtime library
Fedora currently has:

Code: Select all

$ rpm -qa | grep openjpe
openjpeg-libs-1.5.1-14.fc21.x86_64
openjpeg2-2.1.0-6.fc21.x86_64
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Tuning options to convert images to JP2

Post by fmw42 »

The older versions of IM will not work with OpenJPEG. You can only use Jasper and it is limited. See https://en.wikipedia.org/wiki/JPEG_2000

I am not 100% sure, but I think the -defines at http://www.imagemagick.org/script/comma ... php#define only work with OpenJPEG and not Jasper.
Nemo_bis
Posts: 11
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Re: Tuning options to convert images to JP2

Post by Nemo_bis »

fmw42 wrote:I am not 100% sure, but I think the -defines at http://www.imagemagick.org/script/comma ... php#define only work with OpenJPEG and not Jasper.
Might be. We have upgraded to latest ImageMagick and "-quality 85" or similar work well. The only "issue" is that Photoshop users (as well as Luratech users, cf. p. 12 http://www.digitizationguidelines.gov/s ... ession.pdf ) are used to a simplified scale for JP2 quality settings, the dB scale requires some more thinking from the user. Which brought me to some attempt at automation: viewtopic.php?f=1&t=29093

Table comparison from the document above:
Image
Post Reply