Page 1 of 1

Creating transparent JPEG2000

Posted: 2014-12-08T02:32:37-07:00
by alasdairdf
I'm having a very difficult time trying to create a transparent JPEG2000. Specifically I want to create a transparent JPC file (JPEG2000 codestream) but a transparent JP2 would be a start.

As far as I can tell ImageMagick uses JasPer library for JPEG2000 conversion. The problem with using JasPer directly is that none of its support input formats themselves support transparency, even though the JasPer documentation implies that transparency is supported (it doesn't say it is or isn't, but it does talk a bit about how transparency is encoded.)

I found this post from a few months ago on this forum with someone asking a very similar question to mine:
viewtopic.php?t=24922

In that post the user got it working somehow, but there is no actual solution posted there. So at least this shows that what I want to do is possible!

I was previously using whatever version of IM came with Ubuntu 14.04, but have now upgraded to the latest to try to get this to work:

Code: Select all

Version: ImageMagick 6.9.0-0 Q16 x86_64 2014-12-08 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates (built-in): fontconfig freetype jbig jng jp2 jpeg lcms lzma openexr pangocairo png tiff webp x xml zlib
Both JasPer library and OpenJPEG were installed before ImageMagick. I'm using Ubuntu 14.04.

On both the previous version and this version the resulting JPEG2000 have black background instead of transparent.
Things I have tried, on both versions are:
convert test.png test.jp2
convert test.png -define jp2:rate=0.3 -define compression=JPEG2000 test.jp2
convert test.png -alpha Set -background transparent test2.jp2
convert test.png -background none test3.jp2

None of these work. All of them turn the previously transparent background black.

I also tried converting test.png to PNG8 and then converting that to JP2, thinking that since PNG8 supports only full transparency (instead of partial transparency) it might help it decide to be transparent. But no, the background is still black on the JP2.

Here is a test image:
Image

I just don't understand... :(

Any ideas?

Re: Creating transparent JPEG2000

Posted: 2014-12-08T03:17:51-07:00
by alasdairdf
Figured it out. It did work all along, just Photoshop had the transparent layer disabled by default.

EDIT:
OK, so it's not solved. It's not actually transparent, but it does contain an alpha layer. But the alpha layer does not do anything. If I convert it back from a jp2 to a PNG then the only thing I get back is the transparency mask. Photoshop does not recognize the transparency but it does recognize the transparency mask as a layer, just not a transparent one.

Re: Creating transparent JPEG2000

Posted: 2014-12-08T04:46:22-07:00
by alasdairdf
After hours more of testing I've discovered that converting from PNG to TIFF does exactly the same thing: there is an "Alpha 1" channel and it's not correctly recognized by anything.

This is what Photoshop displays for the channels for both TIFF and JP2:
Image

Whereas if the image (TIFF or JP2) is created in Photoshop itself, or loaded from IM PNG, then there is no Alpha 1 channel and the alpha is part of the RGB channel. Also when the transparency works correctly the layer is always called "Layer 0", and when it doesn't work and there is an Alpha 1 channel then the layer is "Background" (if that is in any way relevant.)

Attempting to convert the image with Alpha 1 channel to JPG will copy only the mask and ignore the rest of the image!

All very strange behavior.

Re: Creating transparent JPEG2000

Posted: 2014-12-08T11:04:33-07:00
by alasdairdf
I give up. I'll make my own mask as a separate image and apply it myself on display.

Re: Creating transparent JPEG2000

Posted: 2014-12-08T12:12:40-07:00
by fmw42
As far as I can tell ImageMagick uses JasPer library for JPEG2000 conversion
Current versions of IM (since 6.8.9-1) now use OpenJPEG rather than Jasper. Jasper is much more limiting.

What version of IM and platform are you using? You should always identify those when asking questions on this forum.

Re: Creating transparent JPEG2000

Posted: 2014-12-08T12:15:23-07:00
by fmw42
IM can now specify the alpha type for tiff (as of about 6.8.9.9 for unspecified)

-define tiff:alpha=(unspecified, associated, unassociated)

That controls whether you get alpha transparency or background transparency

Re: Creating transparent JPEG2000

Posted: 2014-12-09T04:27:00-07:00
by alasdairdf
Hi Fred, I put the version in the first post.

Re: Creating transparent JPEG2000

Posted: 2014-12-09T10:59:58-07:00
by fmw42
alasdairdf wrote:Hi Fred, I put the version in the first post.
Sorry, if I missed that.

Re: Creating transparent JPEG2000

Posted: 2014-12-10T00:11:29-07:00
by alasdairdf
OK so defining the alpha type works on TIFF files, but JP2 files still refuse to set the alpha correctly.

Re: Creating transparent JPEG2000

Posted: 2014-12-10T10:26:56-07:00
by fmw42
Sorry I know little about JP2000 and transparency. Does OpenJPEG support that? IM is now using that rather than Jasper, which was much more limiting.