writeall
R2026bDescription
writeall(
writes the data from the blocked image datastore bimds,outputLocation)bimds to PNG files at
the location specified in outputLocation. The number of output files is
the same as the number of files referenced by the datastore.
writeall(
writes data with additional options specified by one or more name-value arguments. For
example, you can specify bimds,outputLocation,Name=Value)OutputFormat and a file extension such as
"png" to specify the type of files that writeall
creates.
Examples
Create a blocked image.
bim = blockedImage("tumor_091R.tif");Create a datastore, specifying the resolution level and the block size.
bls = selectBlockLocations(bim,Levels=2,BlockSize=[512, 512]); bimds = blockedImageDatastore(bim,BlockLocationSet=bls);
Write all blocks of the datastore as PNG files in a subdirectory of the current directory.
dir = "tumor_091R_PNG_"+string(datetime("now",Format="yyyy-MM-dd-HH-mm-ss")); writeall(bimds,dir)
Create a blocked image datastore.
bim = blockedImage("tumor_091R.tif");
bls = selectBlockLocations(bim,Levels=2,BlockSize=[512, 512]);
bimds = blockedImageDatastore(bim,BlockLocationSet=bls);Write all blocks of the datastore as TIFF files in a subdirectory of the current directory, and add a suffix with the current time to each filename.
dir = "tumor_091R_TIFF"; writeall(bimds,dir,OutputFormat="TIFF",WriteFcn=@myTIFFWriteFcn, ... FilenameSuffix="__"+string(datetime("now",Format="yyyy-MM-dd-HH-mm-ss")))
The custom write function myTIFFWriteFcn writes blocks of data as TIFF files.
function myTIFFWriteFcn(data,writeInfo,outputType) if strcmp(outputType,"TIFF") dir = writeInfo.Location; filename = writeInfo.SuggestedOutputName; imwrite(data,dir+filesep+filename,"tiff") end end
Input Arguments
Blocked image datastore, specified as a blockedImageDatastore object.
Folder location to write data, specified as a character vector or string scalar.
outputLocation can specify a full or relative path. If the
UseParallel name-value argument is "on" or
"auto", then outputLocation should be a valid
path on the client session.
Example: outputLocation = "../../dir/data"
Example: outputLocation = "C:\Users\MyName\Desktop"
Data Types: char | string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: writeall(bimds,outputLocation,OutputFormat="jpeg") writes the
files from the datastore bimds to the output location in the JPEG
format.
General Options
Output file format, specified as "jpeg",
"jpg", "png", "mat", or a
string scalar or character vector. For the "jpeg" and
"jpg" output formats, you can refine the writing operation using
the Quality name-value argument.
If you need to write files of a different format than JPEG, JPG, PNG, or MAT, then
use both the OutputFormat and WriteFcn
arguments.
Data Types: char | string
Prefix to filename, specified as a character vector or string scalar.
The writeall function adds the specified prefix to each
output filename. For example, this code adds the current date to the beginning of all
filenames output from the
datastore:
prefixText = string(datetime("today")) writeall(bimds,"C:\myFolder",FilenamePrefix=prefixText)
Data Types: char | string
Suffix to filename, specified as a character vector or string scalar.
The writeall function adds the specified suffix to each
output filename. For example, this code adds the descriptive text
"jpeg_qual70" to the end of all filenames output from the
datastore:
writeall(bimds,"C:\myFolder",FilenameSuffix="jpeg_qual70")
Data Types: char | string
Option to perform computations in parallel using a parallel pool of workers, specified as one of these values:
"off"— Run in serial on the MATLAB® client."auto"— Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, then run in serial on the MATLAB client."on"— Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, then throw an error.
Before R2026b: To run in parallel, set
UseParallel to true
(1).
If you do not have a parallel pool open and automatic pool creation is enabled, then MATLAB opens a pool using the default cluster profile. To use a parallel pool to run computations in MATLAB, you must have Parallel Computing Toolbox™. For more information, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
The writeall function does not support writing data in
parallel using local threads.
Data Types: char | string
Custom writing function, specified as a function handle.
writeall uses the specified function to create the output
files.
You can use the WriteFcn argument to write data in a variety
of formats, even if writeall does not directly support the output
format.
Functional Signature
The custom writing function must accept at least three input arguments,
data, writeInfo, and
outputType:
function myWriteFcn(data,writeInfo,outputType)datacontains the output of thereadfunction operating on the datastore.writeInfois an object of typematlab.io.datastore.WriteInfowith the fields listed in this table.Field Description Type ReadInfoThe second output of the readfunctionstructSuggestedOutputNameA fully qualified, globally unique filename that meets the location and naming requirements stringLocationThe outputLocationargument passed to thewriteallfunctionstringoutputTypeis the output format to be written to, such as"jpg"or"png".
Example Function
This function writes TIFF files from a blocked image datastore:
function myTIFFWriteFcn(data,writeInfo,outputType) if strcmp(outputType,"tiff") dir = writeInfo.Location; filename = writeInfo.SuggestedOutputName; imwrite(data,dir+filesep+filename,"tiff") end end
myTIFFWriteFcn as the writing function for datastore
bimds, use these
commands:outputLocation = "C:/MyData";
writeall(bimds,outputLocation,WriteFcn=@myTIFFWriteFcn)Data Types: function_handle
Options for jpeg or jpg Output
Quality of the JPEG-compressed file, specified as a number in the range [0, 100], where 0 is lower quality and higher compression, and 100 is higher quality and lower compression.
Tips
The default output filename has the form
Image_<N>_Level_<L>_Block_<blockOrigin>.<ext>. For example,Image_1_Level_1_Block_1_1_1.jpg. The function pads the values of<N>and<L>with leading 0s, if required.
Extended Capabilities
The writeall function has automatic parallel support.
To write data in parallel, set the UseParallel argument to
"on" or "auto". The writeall
function does not support writing data in parallel using local threads.
For more information, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).
Version History
Introduced in R2023aThe UseParallel name-value argument now accepts
"off", "auto", or "on" values
instead of true (1) or false
(0). This change gives you more control over when to use a parallel
pool for parallel execution.
Specifying the UseParallel name-value argument as
true or false is not recommended. This table shows
how to update your code depending on your goal.
| Goal | Not recommended | Recommended |
|---|---|---|
Write code that runs on the MATLAB client. | writeall(bimds,outputLocation,UseParallel=false) | writeall(bimds,outputLocation,UseParallel="off") |
Write portable code that runs on a parallel pool and, if a pool is not available, runs on the MATLAB client. | writeall(bimds,outputLocation,UseParallel=true) | writeall(bimds,outputLocation,UseParallel="auto") |
Write code that runs on a parallel pool and errors if a pool is not available. | N/A | writeall(bimds,outputLocation,UseParallel="on") |
There are no plans to remove support for the true or
false values.
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)