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

C
Cameron_harris · Jul 6, 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? Many Thanks.
Expert Answer
Profile picture of Neeta Dsouza
Neeta Dsouza PhD Expert
Answered Aug 12, 2026
Perhaps write a utility that reads in all the images and stores them out in PNG format.
 
 
for k = 1 : numImages
    thisImage = dicomread(....
    outputFileName = strrep(lower(inputFileName), '.dcm', '.webp');
    imwrite(thisImage, outputFileName);
end
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!