We're Hiring!

Alpha channel not being saved in tiffwriter

General user discussion about using the OMERO platform to its fullest. Please ask new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

There are workflow guides for various OMERO functions on our help site - http://help.openmicroscopy.org

You should find answers to any basic questions about using the clients there.

Alpha channel not being saved in tiffwriter

Postby ebremer » Wed Jul 26, 2017 3:52 pm

Hi, I'm trying to create tiff images with alpha channels. As a basic example, I've modified the MinimumWiter example to do this. The code below is supposed to create a 512x512 RGBA image with a random color/alpha at each pixel. I get a color image with random colors, but the alpha channel appear to be locked at opaque. How can I modify this code so that the alpha values show up as random too?

Code: Select all
    String id = "d:\\images\\blank.tif";
    int w = 512, h = 512, c = 4;
    int pixelType = FormatTools.UINT8;
    byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
    for (int i=0; i<img.length; i++) img[i] = (byte) (256 * Math.random());
    ServiceFactory factory = new ServiceFactory();
    OMEXMLService service = factory.getInstance(OMEXMLService.class);
    IMetadata meta = service.createOMEXMLMetadata();
    MetadataTools.populateMetadata(meta, 0, null, false, "XYZCT",FormatTools.getPixelTypeString(pixelType), w, h, 1, c, 1, c);
    meta.setPixelsSizeC(new PositiveInteger(4), 0);
    IFormatWriter writer = new ImageWriter();
    writer.setMetadataRetrieve(meta);
    writer.setId(id);
    writer.saveBytes(0, img);
    writer.close();
    System.out.println("Done.");
ebremer
 
Posts: 3
Joined: Wed Jul 26, 2017 2:54 pm

Re: Alpha channel not being saved in tiffwriter

Postby dgault » Thu Jul 27, 2017 11:31 am

Hi,

I ran the sample code you provided and generated the random image. When read with the latest Bio-Formats release the image shows the 4 channels as expected and when the channels are split each shows the random pixel values as desired.

How are you reading or viewing the image that shows the alpha as opaque?

David Gault
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm

Re: Alpha channel not being saved in tiffwriter

Postby ebremer » Sun Aug 06, 2017 2:44 pm

It turned out that Photoshop could not display the alpha which was weird since I can create tiff's with alpha and see them in Photoshop. On a hunch, I tried Gimp and I can see the Bioformats created alpha fine.
ebremer
 
Posts: 3
Joined: Wed Jul 26, 2017 2:54 pm


Return to User Discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron