PngSaver¶
- class io.savers.PngSaver¶
Bases:
io.savers.BaseSaverPNGSAVER - Saver for Portable Network Graphics (PNG) output.
PNG is a lossless raster format. Because PNG files are inherently 2-D, every Z-slice is saved as a separate file (always sequence mode). Multichannel data with more than 3 colour channels is not supported (PNG maximum = 3 channels + optional alpha).
Handled format strings: ‘Portable Network Graphics (
*.png)’ - used when saving image layer ‘PNG format (*.png)’ - alias used for mask/labelsDATA DIMENSIONS Input data : [H, W, D, C, T] imwrite call: [H, W, C] per 2-D slice (Z and T loops)
NOTES * For indexed images metadata.colormap (or metadata.lutColors) is used as the colour table. * Resolution metadata (pixels/unit) is stored in the PNG file if metadata.xResolution and metadata.yResolution are provided. * When options.FilenameGenerator = ‘Use original filename’, slice names are derived from metadata.sliceName when available.
USAGE EXAMPLES
%% 1. Direct saver use saver = io.SaverFactory.create('Portable Network Graphics (``*.png``)'); opts.Format = 'Portable Network Graphics (``*.png``)'; opts.showWaitbar = false; opts.silent = true; opts.overwrite = true; opts.FilenameGenerator = 'Use sequential filename'; meta.filename = 'source.tif'; meta.colorType = 'grayscale'; meta.lutColors = [1 1 1]; meta.dataClass = 'uint8'; meta.maxInt = 255; meta.sliceName = {}; meta.xResolution = 72; meta.yResolution = 72; meta.imageDescription = 'EM dataset'; data = uint8(rand(256,256,10,1,1)*255); % [H W D C T] fnOut = saver.save(data, meta, '/output/slice.png', opts); % Generates /output/slice_01.png … /output/slice_10.png%% 2. Via MibDataset (intermediate layer) opts.Format = 'Portable Network Graphics (``*.png``)'; opts.showWaitbar = false; opts.silent = true; opts.overwrite = true; fnOut = dataset.save('image', '/output/slice.png', opts);%% 3. Save mask as PNG sequence opts.Format = 'PNG format (``*.png``)'; opts.showWaitbar = false; opts.silent = true; opts.overwrite = true; fnOut = dataset.save('mask', '/output/Mask_slice.png', opts);SEE ALSO io.SaverFactory, io.savers.BaseSaver, io.savers.TiffSaver, core.MibImage.save, core.MibDataset.save
- Constructor Summary
- PngSaver(options)¶
PNGSAVER - Constructor for PngSaver class.
- Syntax:
saver = io.savers.PngSaver(options)- Input Arguments:
options - (optional) struct, saver-level options (usually empty; per-save options are passed to
save()instead)
- Output Arguments:
obj - instance of the PngSaver class
- Method Summary
- getSupportedFormats(~)¶
GETSUPPORTEDFORMATS - Return format strings handled by PngSaver.
- Syntax:
formats = obj.getSupportedFormats()- Input Arguments:
(none)
- Output Arguments:
formats - cell array of format strings for PNG output
- save(data, metadata, filename, options)¶
SAVE - Write a PNG 2-D sequence (one file per Z-slice × time point).
- Syntax:
fnOut = obj.save(data, metadata, filename, options)
PNG stores one 2-D image per Z-slice and optionally per time point. The stem of the output filename is used as the base for sequential numbering.
- Input Arguments:
data - [H, W, D, C, T] numeric array
metadata - struct with fields:
colorType-'grayscale'|'multichannel'|'indexed'lutColors- (optional) [N × 3] colormap for indexed imagescolormap- (optional) [N × 3] colormap (alternative tolutColors)sliceName- (optional) per-slice source filenames (for ‘Use original filename’ mode)imageDescription- (optional) [char] comment/description string for PNG filesxResolution- (optional) [numeric] X resolution in pixels/unit; default:72yResolution- (optional) [numeric] Y resolution in pixels/unit; default:72
filename - [char] full path template, e.g.
'/out/slice.png'; stem is used as base for sequential namesoptions - struct with fields:
Format- format stringshowWaitbar- logical; default:truesilent- logical, suppress dialogs; default:falseoverwrite- logical; default:trueFilenameGenerator-'Use original filename'|'Use sequential filename'
- Output Arguments:
fnOut - cell of char [{nD × nT} × 1] with all saved paths, or single char when only one slice was saved
Example - see class-level documentation above.
PNG is inherently per-slice, so
saveis a thin wrapper over the streaming primitivesaveStream(single code path).
- saveStream(provider, metadata, filename, options)¶
SAVESTREAM - Write a PNG 2-D sequence one slice at a time from a SliceProvider.
Memory-bounded twin of
save: pulls each Z-slice (per time point) fromprovider.getSlice(z, t)and writes it as an individual PNG. Seeio.savers.BaseSaver.saveStream.Example - stream a level to a numbered PNG sequence:
provider = io.savers.MibImageSliceProvider(img, 'image', 2, [], numZ, 1, zScale); saver = io.savers.PngSaver(struct()); meta.colorType = 'grayscale'; saver.saveStream(provider, meta, 'C:\out\slice.png', ... struct('silent',true,'showWaitbar',false,'FilenameGenerator','Use sequential filename')); % → C:\out\slice_001.png … slice_NNN.png