ImageDataStore read issue -- works sometimes, sometimes not

20 views (last 30 days)
I'm getting the below error when trying to read from an image datastore, manipulate, and write. The strange part is that I can read the file using imread perfectly fine. I'm literally copying the filename from the error message and pasting it into an imread command and it works. Any idea how I can troubleshoot this?
Error using matlab.io.datastore.ImageDatastore/read (line 77)
Unable to read file: <redacted filename>
Error in matlab.io.datastore.FileWritable/writeSerial (line 14)
[data, readInfo] = read(dsCopy);
Error in matlab.io.datastore.FileWritable/writeParallel (line 45)
parfor (ii = 1 : size(files,1), M)
Error in matlab.io.datastore.FileWritable/writeall (line 272)
writeParallel(ds, location, files, nvStruct);
Error in augment_images (line 101)
writeall(subds, [options.Filenames.OutputDir options.Mag],
'FilenameSuffix',suffix,
'OutputFormat',options.Filenames.OutputFormat,
'UseParallel',true);
Caused by:
Error using
matlab.io.datastore.exceptions.decorateCustomFunctionError>generateReadFcnError
(line 103)
Error using ReadFcn @readDatastoreImage for file:
<redacted filename>
Error using imread>get_full_filename (line 564)
Cannot open file "<redacted filename>" for reading.
You might not have read permission.
Error in imread (line 374)
fullname = get_full_filename(filename);
Error in readDatastoreImage (line 12)
data = imread(filename);

Answers (2)

Mahesh Taparia
Mahesh Taparia on 4 Feb 2021
Hi
It seems either the folder path is inappropriate or the files are not in the supported image format. Correct the folder path of the files, it will work.
  2 Comments
Mark Zarella
Mark Zarella on 4 Feb 2021
Edited: Mark Zarella on 4 Feb 2021
That's what I thought originally as well. But I've confirmed the folder path is correct and that the file formats are supported. The way I did this is by manually running the imread function on the SAME file path and it works fine. And I did this programmatically to ensure the difference wasn't due to manual entry.
Mahesh Taparia
Mahesh Taparia on 4 Feb 2021
Hi
Can you upload a sample image from your dataset?
Also let me know, if the below code is working your not.
imds = imageDatastore(fullfile(matlabroot,'toolbox','matlab'),...
'IncludeSubfolders',true,'FileExtensions','.tif','LabelSource','foldernames')

Sign in to comment.


Steven Lord
Steven Lord on 4 Feb 2021
If you try running imread inside a parfor loop rather than at the MATLAB prompt, does it throw an error? I'm wondering if the parallel pool is running the workers on a cluster as a different user that does not have the necessary permissions to access the data files.

Categories

Find more on Containers in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!