combine
Description
dsnew = combine(
combines
multiple datastores to create a ds1,ds2,...,dsN
)CombinedDatastore
object using the data
returned by the read
function on the input datastores.
dsnew = combine(
combines multiple datastores based on the specified read order. The read order determines
the creation of either a ds1,ds2,...,dsN
,ReadOrder=order
)CombinedDatastore
or
SequentialDatastore
object.
Examples
Combine Datastores
Create a datastore that maintains parity between the pair of images of the underlying datastores. For instance, create two separate image datastores, and then create a combined datastore that reads corresponding images from the two image datastores.
Create a datastore imds1
representing a collection of three images.
imds1 = imageDatastore({'street1.jpg','street2.jpg','peppers.png'});
Create a second datastore imds2
by transforming the images of imds1
to grayscale images.
imds2 = transform(imds1,@(x) im2gray(x));
Create a combined datastore from imds1
and imds2
.
imdsCombined = combine(imds1,imds2);
Read the first pair of images from the combined datastore. Each read operation on this combined datastore returns a pair of images represented by a 1
-by-2
cell array.
dataOut = read(imdsCombined)
dataOut=1×2 cell array
{480x640x3 uint8} {480x640 uint8}
Display the output of the first read from the combined datastore.
imshow(imtile(dataOut));
Combine Datastores Sequentially
Create a datastore that reads from two image datastores one after the other.
Create an ImageDatastore
ds1
representing a collection of two images. Then, create a second ImageDatastore
ds2
by transforming the images of ds1
to grayscale images. Combine ds1
and ds2
to create a SequentialDatastore
object.
ds1 = imageDatastore(["peppers.png","street2.jpg"]); ds2 = transform(ds1,@(x) im2gray(x)); dsseq = combine(ds1,ds2,ReadOrder="sequential");
Read the first three images from the SequentialDatastore
object. Each read operation on this SequentialDatastore
object returns a single image represented by a 1-by-1 cell array.
img1 = read(dsseq); img2 = read(dsseq); img3 = read(dsseq);
Input Arguments
ds1,ds2,...,dsN
— Datastores to combine
datastore objects
Datastores to combine, specified as two or more comma-separated datastore objects. For a complete list of built-in datastores, see Select Datastore for File Format or Application. You also can specify custom datastores.
order
— Order in which data is read
"associated"
(default) | "sequential"
Order in which data is read, specified as "associated"
or
"sequential"
.
"associated"
creates aCombinedDatastore
object that is the horizontally concatenated result of the read operation from each of the underlying datastores."sequential"
creates aSequentialDatastore
object that sequentially reads from the underlying datastores without concatenation.
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
Usage notes and limitations:
In a thread-based environment, you can use
combine
only with the following datastores:ImageDatastore
objectsCombinedDatastore
,SequentialDatastore
, orTransformedDatastore
objects you create fromImageDatastore
objects by usingcombine
ortransform
You can use
combine
with other datastores if you have Parallel Computing Toolbox™. To do so, run the function using a process-backed parallel pool instead of usingbackgroundPool
orThreadPool
(use eitherProcessPool
orClusterPool
).
For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2019aR2022b: Sequentially read data from multiple datastores
Sequentially read data from multiple datastores without concatenation.
See Also
CombinedDatastore
| SequentialDatastore
| read
| readall
| reset
| hasdata
| preview
| transform
Ouvrir l'exemple
Vous possédez une version modifiée de cet exemple. Souhaitez-vous ouvrir cet exemple avec vos modifications ?
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)