Page 1 of 1

Alpha channel not being saved in tiffwriter

PostPosted: Wed Jul 26, 2017 3:52 pm
by ebremer
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.");

Re: Alpha channel not being saved in tiffwriter

PostPosted: Thu Jul 27, 2017 11:31 am
by dgault
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

Re: Alpha channel not being saved in tiffwriter

PostPosted: Sun Aug 06, 2017 2:44 pm
by ebremer
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.