How to apply a function on all images in ImageDatastore ?

I am using Imagedatastore function for classification problem but now I need to apply an function to all images in imageDatastore
YPred =classify(net,TestImages);

 Accepted Answer

I think this is what you want.
imds = imageDatastore(files,...)
tds = transform(imds,@(img)classify(net,img));
YPred = readall(tds);

3 Comments

not exactly this but something like that, my test images are in grayscale level but I want to make it binary image using imbinaeize after that I want to classify it
tds = transform(imd,@(imd) ~imbinarize(imd));
You can do multiple transforms,
imds = imageDatastore(files,...);
tds = transform(imds,@(img) ~imbinarize(img));
tds = transform(tds,@(img) classify(net,img));
YPred = readall(tds);
Based on what you wrote, I want to make sure you understand that this:
@(imd) ~imbinarize(imd)
doesn't take in a datastore as an input, it takes the image data, one-by-one, and then calls imbinarize on each result.
It works as if you called
imds = imageDatastore(files);
while hasdata(imds)
img = read(imds); % read an image from the datastore
img = ~imbinarize(img);
Ypred(end+1) = classify(net,img);
end
Thank you so much that was exactly what i want

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!