How do I control the output class of combine() with multiple image and trasnformedimage datastores?

2 views (last 30 days)
I am trying to train an image to image regression network. I have a series of input and output images in different folders. I create seperate imagedatastore for each folder than use combine() to create the input for the network. When I use combine on the two datastores as long as one of them is a pure imageDataStore the output is a cell array as trainnetwork() expects, but if both imagedatastores are also transformed than the output becomes an array concating the two images.
Minimal reproducible code:
dataDir = fullfile(toolboxdir('vision'),'visiondata','triangleImages');
imageDir = fullfile(dataDir,'trainingImages');
imds = imageDatastore(imageDir);
targetSize = [224,224];
imdsTransformed = transform(imds,@(x) imresize(x,targetSize));
combinedDS1 = combine(imdsTransformed, imds);
combinedDS2 = combine(imdsTransformed, imdsTransformed);
response1 = preview(combinedDS1);
response2 = preview(combinedDS2);
whos response1
Name Size Bytes Class Attributes response1 1x2 51408 cell
whos response2
Name Size Bytes Class Attributes response2 8x448 3584 uint8
Given that the folders are dozens of gigabytes and I only want to transform the output image to do some proof of concept and parameter tuning exiperements, I don't want to save whole new batch of images to disk. Any way I can get combine() to concate two transformedDataStore and output a cell array?

Accepted Answer

Matt J
Matt J on 10 Feb 2024
imdsTransformed = transform(imds,@(x) {imresize(x,targetSize)} );
  1 Comment
Christopher Greulich
Christopher Greulich on 12 Feb 2024
Edited: Christopher Greulich on 12 Feb 2024
Thanks! I can't believe I didn't try this. I tried, before submitting the question, using "cell()" instead of "{}" and was getting "Invalid Transform function defined on datastore.".
Glad it was this simple.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!