How can I label DICOM images for classification based on folder name

Cameron-Harris · Jun 3, 2021 · 2.3K views
Question
I want to carry out transfer learning using  AlexNet for a set of 128x128 DICOM images. It looks like on of the most efficient methods of storing and labeling images is using imageDatastore, however I don't think this supports DICOM formats, I can create the store with no errors using:     images = imageDatastore(fullfile(pwd,'Project_Segmentations'),... 'IncludeSubfolders',true,'FileExtensions','.dcm',... 'LabelSource','foldernames'); This correctly labels the DICOMs based on the name of the folder they are in, however, when I try to use this data for training I'm met with the error: Error using matlab.io.datastore.ImageDatastore/readimage (line 32) Error using ReadFcn @readDatastoreImage function handle for file Which makes sense given imread doesn't support DICOM images.   Ideally I want to keep the DICOM file format, is there anyway I can achieve this data labeling for DICOM images?
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 17, 2026
Labeling DICOM images for classification based on folder names is a straightforward process. Here’s a high-level overview of how you can achieve this:
 
 
 
for k = 1 : numImages
    thisImage = dicomread(....
    outputFileName = strrep(lower(inputFileName), '.dcm', '.webp');
    imwrite(thisImage, outputFileName);
end
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!