MATLAB Answers

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

60 ビュー (過去 30 日間)
Cameron Harris
Cameron Harris 2018 年 3 月 10 日
編集済み: shivan artosh 2020 年 4 月 2 日 21:35
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.

  0 件のコメント

サインイン to comment.

採用された回答

Image Analyst
Image Analyst 2018 年 3 月 10 日
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', '.png');
imwrite(thisImage, outputFileName);
end

  3 件のコメント

Cameron Harris
Cameron Harris 2018 年 3 月 10 日
Thanks for this, I had figured I could just write them out to a new format if needed. Ideally I wanted to keep the DICOM format in my network, but to be entirely honest I am not sure how much changing the format would really affect my transfer learning results, provided lossless/minimal compression in the conversion.
Happy to accept this answer for now though as PNG seems to be an easier format to work with for transfer learning for a beginner.
ahmed adam
ahmed adam 2018 年 5 月 14 日
I have the same problem now , did you change the format to PNG or continue as dicom images ?
Cameron Harris
Cameron Harris 2018 年 5 月 14 日
I continued using PNGs as I also wanted to use imagedatastore's built in image augmentation.

サインイン to comment.

その他の回答 (1 件)

Khalid
Khalid 2019 年 1 月 19 日
I have faced a similar issue in wich I had to create another readDatastoreImage function. You might solved it this way:
Create a copy of the readDatastoreImage function within the imageDatastore function and give it a different name, for example: readDicomDatastoreImage
Then change the imread(filename) function wihin the one you copyed to dicomread(filename)
finaly, use it with the imageDatastore function this way:
imds = imageDatastore(imageDir, 'FileExtensions','.dcm','ReadFcn',@readDicomDatastoreImage);
Hope this can help
Khalid

  3 件のコメント

shivan artosh
shivan artosh 2020 年 3 月 26 日 12:18
hello sir
could you please write complete the code for reading a .dicom files
thanks
Khalid Babutain
Khalid Babutain 2020 年 3 月 26 日 22:45
1. write in your main code:
imds = imageDatastore('DataSet', ...
'IncludeSubfolders',true, 'LabelSource','foldernames', ... % this for labeling by folder names
'FileExtensions','.dcm','ReadFcn',@readDicomDatastoreImage);
2. create (readDicomDatastoreImage) function that include:
function I = readDicomDatastoreImage(filename)
onState = warning('off', 'backtrace');
c = onCleanup(@() warning(onState));
I = dicomread(filename);
in this way, each time you read an image from your (imds) it will be read using (readDicomDatastoreImage) function
Hope this is clear
Khalid
shivan artosh
shivan artosh 2020 年 3 月 26 日 23:19
thank you so much sir it is really helpful

サインイン to comment.

サインイン してこの質問に回答します。


Translated by