multi-spectral images with imageDatastore

7 views (last 30 days)
OJ27
OJ27 on 19 Aug 2020
Edited: OJ27 on 19 Aug 2020
I have images in different directories that I would like to concatenate before passing them to a CNN. I have two class labels separated in two folders. Within each folder, there are subfolders corresponding to the channels of the multi-spectral image. To concatenate these images I created two functions
function multi = cat_datastore(label,dir1,dir2,dir3)
rgb = imageDatastore(dir1);
rgb.Labels = categorical(repelem(label,length(rgb.Files)));
mask = imageDatastore(dir2);
mask.Labels = rgb.Labels ;
seg = imageDatastore(dir3);
seg.Labels = rgb.Labels ;
imds = combine(rgb, mask, seg);
multi = transform(imds,@concat_mask);
end
and
concat_mask
which concatenates all channels. If I run read(muti), then I can see the final image is of size WxHxN, with N being the number of channels. My question is in regards to combining this datastore with the images in the other label. I assumed
imds = combine(multi1, multi2);
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
would be helpful but when trying to run, I get an error 'Check for missing argument or incorrect argument data type in call to function 'splitEachLabel'. This makes sense because splitEachLabel is expecting an imageDatastore object rathern than a TransformedDatastore or a CombineDatastore.
I also tried (even though I am not a fan of this), writing all images to a folder and then create a datastore from it. So I ran,
writeall(multi1, dir ,'FolderLayout','flatten','OutputFormat', 'tif') ;
but I get an error
Unable to open file "" for writing. You might not have write permission.
Any advice? Should I just write a for loop and save the concatenated images in a folder?

Answers (0)

Community Treasure Hunt

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

Start Hunting!