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

Illustration
Cameron_harris - 2021-07-06T10:03:15+00:00
Question: How can I label DICOM images for classification based on folder name

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 answered . 2025-11-20

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


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!