png images not read/displayed correctly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

png images not read/displayed correctly

Tommy Chheng
I tried opening
http://upload.wikimedia.org/wikipedia/commons/6/69/Xbox360.png in
ImageJ 1.44o GUI and it displayed the image background incorrectly.

Is there a setting I need to apply to the image before using it in ImageJ?

--
@tommychheng
http://tommy.chheng.com
Reply | Threaded
Open this post in threaded view
|

Re: png images not read/displayed correctly

ctrueden
Hi Tommy,


> I tried opening
> http://upload.wikimedia.org/wikipedia/commons/6/69/Xbox360.png in
> ImageJ 1.44o GUI and it displayed the image background incorrectly.
>
> Is there a setting I need to apply to the image before using it in ImageJ?
>

ImageJ does not support PNGs with an alpha channel.

You can read them using Bio-Formats, but it will not composite the layers
the way you expect.

Attached is a (rather slow) macro that reads PNGs with alpha and composites
the layers as you would expect, over a white background. You can change the
background color by adjusting the bgRed, bgGreen and bgBlue constants at
the beginning of the macro.

Regards,
Curtis

alpha.txt (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: png images not read/displayed correctly

Tommy Chheng
Thanks Curtis, will there be support for PNG with alpha channel in the
future 2.0 version?

my use case is a web app where i resize images:
    var ip = imp.getProcessor
    ip.setInterpolationMethod(ImageProcessor.NONE)
    ip = ip.resize(resizedDim.width, resizedDim.height, true)
    ip.getBufferedImage

What's the best way to inject the method in the macro with the
imageProcessor object?
* this machine does not have access to a X11 display and cannot run in
headless mode.


On Tue, Nov 8, 2011 at 12:48 PM, Curtis Rueden <[hidden email]> wrote:

> Hi Tommy,
>
>
>> I tried opening
>> http://upload.wikimedia.org/wikipedia/commons/6/69/Xbox360.png in
>> ImageJ 1.44o GUI and it displayed the image background incorrectly.
>>
>> Is there a setting I need to apply to the image before using it in ImageJ?
>>
>
> ImageJ does not support PNGs with an alpha channel.
>
> You can read them using Bio-Formats, but it will not composite the layers
> the way you expect.
>
> Attached is a (rather slow) macro that reads PNGs with alpha and composites
> the layers as you would expect, over a white background. You can change the
> background color by adjusting the bgRed, bgGreen and bgBlue constants at
> the beginning of the macro.
>
> Regards,
> Curtis
>



--
@tommychheng
http://tommy.chheng.com
Reply | Threaded
Open this post in threaded view
|

Re: png images not read/displayed correctly

ctrueden
Hi Tommy,

Thanks Curtis, will there be support for PNG with alpha channel in the
> future 2.0 version?
>

It will probably not be supported in the initial release of ImageJ 2.0.
However, we will almost certainly support it in a future version after that.

my use case is a web app where i resize images:
>

If all you want to do is resize PNGs with alpha channel, why not use Java's
built-in ImageIO API with BufferedImages (e.g.:
http://helpdesk.objects.com.au/java/how-do-i-scale-a-bufferedimage)? Seems
simpler than adding a dependency on ImageJ.

What's the best way to inject the method in the macro with the
> imageProcessor object?
>

Sorry, I don't understand the question...

* this machine does not have access to a X11 display and cannot run in
> headless mode.
>

You can run Java headless without an X11 display, using the
java.awt.headless=true flag, but use of certain AWT/Swing classes (e.g.,
Frame or JFrame) will throw exceptions. ImageJ can be run in headless mode
using Fiji's --headless option. Some stuff will not work though, due to how
GenericDialogs and menus work in ImageJ. We are working on a fully
headless-capable system with ImageJ2.

The other option is to install a virtual frame buffer (xvfb), which works
pretty well. Just be careful for blocking dialogs popping up in the frame
buffer and halting your execution.

Regards,
Curtis


On Tue, Nov 8, 2011 at 5:17 PM, Tommy Chheng <[hidden email]> wrote:

> Thanks Curtis, will there be support for PNG with alpha channel in the
> future 2.0 version?
>
> my use case is a web app where i resize images:
>    var ip = imp.getProcessor
>    ip.setInterpolationMethod(ImageProcessor.NONE)
>    ip = ip.resize(resizedDim.width, resizedDim.height, true)
>    ip.getBufferedImage
>
> What's the best way to inject the method in the macro with the
> imageProcessor object?
> * this machine does not have access to a X11 display and cannot run in
> headless mode.
>
>
> On Tue, Nov 8, 2011 at 12:48 PM, Curtis Rueden <[hidden email]> wrote:
> > Hi Tommy,
> >
> >
> >> I tried opening
> >> http://upload.wikimedia.org/wikipedia/commons/6/69/Xbox360.png in
> >> ImageJ 1.44o GUI and it displayed the image background incorrectly.
> >>
> >> Is there a setting I need to apply to the image before using it in
> ImageJ?
> >>
> >
> > ImageJ does not support PNGs with an alpha channel.
> >
> > You can read them using Bio-Formats, but it will not composite the layers
> > the way you expect.
> >
> > Attached is a (rather slow) macro that reads PNGs with alpha and
> composites
> > the layers as you would expect, over a white background. You can change
> the
> > background color by adjusting the bgRed, bgGreen and bgBlue constants at
> > the beginning of the macro.
> >
> > Regards,
> > Curtis
> >
>
>
>
> --
> @tommychheng
> http://tommy.chheng.com
>