Matlab: how to save TIFF with transparency or PNG without compression?

I need to process many images and save the results in transparency image files in Matlab. But PNG compression takes too much time for me. How to save PNG without compression or TIFF with transparency? Are there other ways to save an image without compression and transparency?

This is my first question here, sorry for my poor English and the wrong style of the question if there are any errors in question.

+4
source share
3 answers

Using the TIFF class in Matlab, you can write TIFF with transparency:

%# create a synthetic RGBA image ch = checkerboard(100); rgba = repmat(ch,[1,1,4]); rgba(:,:,4) = rgba(:,:,4)==0; rgba = uint8(round(rgba*255)); %# create a tiff object tob = Tiff('test.tif','w'); %# you need to set Photometric before Compression tob.setTag('Photometric',Tiff.Photometric.RGB) tob.setTag('Compression',Tiff.Compression.None) %# tell the program that channel 4 is alpha tob.setTag('ExtraSamples',Tiff.ExtraSamples.AssociatedAlpha) %# set additional tags (you may want to use the structure %# version of this for convenience) tob.setTag('ImageLength',size(ch,1)); tob.setTag('ImageWidth',size(ch,2)); tob.setTag('BitsPerSample',8); tob.setTag('RowsPerStrip',16); tob.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky); tob.setTag('Software','MATLAB') tob.setTag('SamplesPerPixel',4); %# write and close the file tob.write(rgba) tob.close %# open in Photoshop - see transparency! 
+4
source

Matlab imwrite has no parameter for PNG compression level. If so, you can set it to zero without compression. While for TIFF it has the none option for Compression , the alpha channel is missing. You can write to the old Sun Raster (RAS) format with alpha and no compression. Although nothing is likely to be able to read it.

+1
source

"There is no uncompressed PNG variant. You can store uncompressed data using only an uncompressed deflation block"

An uncompressed deflate block uses a header of 5 bytes + up to 65535 bytes of uncompressed data for each block.

http://www.w3.org/TR/PNG-Rationale.html

0
source

All Articles