JpgSaver¶
- class io.savers.JpgSaver¶
Bases:
io.savers.BaseSaverJPGSAVER - Saver for JPEG output - one file per Z-slice (always a 2-D sequence).
JPEG is a lossy format suitable for display purposes; it is NOT recommended for quantitative analysis. uint16 multichannel data cannot be saved as JPEG (MATLAB limitation); use uint8 RGB only.
Handled format string: ‘Joint Photographic Experts Group (
*.jpg)’DATA DIMENSIONS Input data : [H, W, D, C, T] imwrite call: [H, W, C] per 2-D slice (C ≤ 3, class == uint8)
NOTES * options.Quality (0-100, default 90): JPEG quality factor. * options.Compression (‘lossy’|’lossless’, default ‘lossy’). * JPEG does not support indexed colourmaps; ‘indexed’ colour images will be saved using the raw index values as greyscale.
USAGE EXAMPLES
%% 1. Direct saver use saver = io.SaverFactory.create('Joint Photographic Experts Group (``*.jpg``)'); opts.Format = 'Joint Photographic Experts Group (``*.jpg``)'; opts.Quality = 90; opts.Compression = 'lossy'; opts.showWaitbar = false; opts.silent = true; opts.overwrite = true; opts.FilenameGenerator = 'Use sequential filename'; meta.filename = 'source.tif'; meta.colorType = 'multichannel'; meta.lutColors = eye(3); meta.dataClass = 'uint8'; meta.maxInt = 255; meta.sliceName = {}; meta.imageDescription = ''; data = uint8(rand(256,256,10,3,1)*255); % [H W D C T], RGB fnOut = saver.save(data, meta, '/output/slice.jpg', opts); % Generates /output/slice_01.jpg … /output/slice_10.jpg%% 2. Via MibModel with quality control BatchOpt.LayerType = {'image'}; BatchOpt.Format = {'Joint Photographic Experts Group (``*.jpg``)'}; BatchOpt.Quality = '90'; BatchOpt.Compression = 'lossy'; BatchOpt.OutputDirectoryPolicy = {'Full path'}; BatchOpt.DestinationDirectory = '/output'; BatchOpt.FilenamePolicy = {'Use existing name'}; BatchOpt.showWaitbar = false; BatchOpt.mibBatchTooltip.LayerType = ''; model.save('image', [], BatchOpt);SEE ALSO io.SaverFactory, io.savers.BaseSaver, io.savers.PngSaver
- Constructor Summary
- JpgSaver(options)¶
JPGSAVER - Constructor for JpgSaver class.
- Syntax:
saver = io.savers.JpgSaver(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 JpgSaver class
- Method Summary
- getSupportedFormats(~)¶
GETSUPPORTEDFORMATS - Return format strings handled by JpgSaver.
- Syntax:
formats = obj.getSupportedFormats()- Input Arguments:
(none)
- Output Arguments:
formats - cell array of format strings for JPEG output
- save(data, metadata, filename, options)¶
SAVE - Write JPEG 2-D sequence (one file per Z-slice × time point).
- Syntax:
fnOut = obj.save(data, metadata, filename, options)- Input Arguments:
data - [H, W, D, C, T] uint8 (or uint16 greyscale)
metadata - struct with fields:
colorType- data type (multichannel RGB must be uint8)sliceName- (optional) per-slice source filenamesimageDescription- (optional) JPEG Comment tag
filename - full path template, e.g.
'/out/frame.jpg'options - struct with fields:
Quality- [double] 0-100; default:90Compression- [char]'lossy'|'lossless'; default:'lossy'showWaitbar- logical; default:truesilent- logical, suppress dialogs; default:falseoverwrite- logical; default:trueFilenameGenerator- [char] filename generation mode
- Output Arguments:
fnOut - cell of char with all saved paths, or single char if only one slice
JPEG is inherently per-slice, so
saveis a thin wrapper over the streaming primitivesaveStream(single code path).
- saveStream(provider, metadata, filename, options)¶
SAVESTREAM - Write a JPEG 2-D sequence one slice at a time from a SliceProvider. See
io.savers.BaseSaver.saveStream.Example - stream a level to a JPEG sequence (quality 90):
provider = io.savers.MibImageSliceProvider(img, 'image', 2, [], numZ, 1, zScale); saver = io.savers.JpgSaver(struct()); meta.colorType = 'grayscale'; saver.saveStream(provider, meta, 'C:\out\frame.jpg', ... struct('silent',true,'showWaitbar',false,'Quality',90,'Compression','lossy', ... 'FilenameGenerator','Use sequential filename'));