Clear Filters
Clear Filters

Error in combined image datastore and pixel datastore for image segmentation

7 views (last 30 days)
The image datastore file considers the folder directory itself as a data file and the pixel datastore does not include the folder name as a data. Hence, there is a mismatch between the imds and pxds. How to avoid considering the parent directory as a file in imds.
Please
This leads to 1 more file in the imds, giving the following error:
Error using matlab.io.datastore.CombinedDatastore/subset
Expected indices to be an array with all of the values <= 780.
Please help in resolving this issue.
Thank you.

Answers (1)

Shubh
Shubh on 23 Jan 2024
Hi Divya,
It sounds like you're encountering an issue where the Image Datastore ('imds') in MATLAB is including the parent directory as an additional file, leading to a mismatch in the number of files compared to the Pixel Datastore ('pxds'). This discrepancy causes an error when you try to process these datastores together, as their lengths are different.
The typical cause for this issue is that the folder structure or the way the 'imageDatastore' function is being called includes an unwanted file or directory. To resolve this issue, you can:
  1. Check Your Folder Structure: Make sure that the folder you are pointing to with 'imds' contains only the image files you want to include and no subfolders or additional files.
  2. Specify File Extensions: Explicitly specify the file extensions of the images you want to include in the datastore. This can prevent MATLAB from mistakenly including a directory.
  3. Verify Contents Before Processing: Check the contents of your datastores before attempting to use them together.
Here's how you can implement these steps in MATLAB:
1. Check Folder Structure
Ensure your image folder contains only the image files. No additional files or subdirectories should be present.
2. Create Image and Pixel Datastores with Specific File Extensions
imageFolder = 'path_to_your_image_folder'; % Specify your image folder path
fileExtensions = {'.jpg', '.png'}; % List of file extensions to include
% Create an ImageDatastore with specified file extensions
imds = imageDatastore(imageFolder, 'FileExtensions', fileExtensions);
% Assuming you have a corresponding pixel label folder
pixelLabelFolder = 'path_to_your_pixel_label_folder'; % Specify your pixel label folder path
pxds = pixelLabelDatastore(pixelLabelFolder, classNames, labelIDs); % classNames and labelIDs should be defined as per your data
3. Verify Contents
% Display the number of files in each datastore
disp(['Number of files in IMDS: ', num2str(numel(imds.Files))]);
disp(['Number of files in PXDS: ', num2str(numel(pxds.Files))]);
% Optional: Print file names to manually inspect
disp('Files in IMDS:');
disp(imds.Files);
disp('Files in PXDS:');
disp(pxds.Files);
If the numbers of files are different, you need to rectify this by ensuring both 'imds' and 'pxds' are pointing to corresponding and equal numbers of files.
By following these steps, you should be able to resolve the mismatch issue between your image datastore and pixel label datastore. If the issue persists, it might be necessary to manually inspect the folder and files to identify any anomalies.
Hope this helps!

Categories

Find more on Convert Image Type 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!