how to read and save dicom images in different directories
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have series of 1600 dicom images with the name 6--12-1.dcm, 6--12-2.dcm, 6--12-3.dcm and so on. how can I read the sequence and do the filtering on images and save them in another folder? here is my code but it gives me errors, can you please help me to correct it:
source_dir=uigetdir([]); %I= dir('C:\Users\Shan\Desktop\CT Images')
pwd
d=dir([source_dir,'\6--12-*.dcm']);
totalfile=length(d);
resultfolder='C:\Users\Shan\Desktop\CT Images\Median'
for i=1:totalfile
fname=['6--12-',num2str(i), '.dcm'];
indicom=dicomread(fname);
subplot(1,2,1), imshow(indicom,[]);
title('original image number',(num2str(i)),'Interpreter','None')
medianfilter{i}=medfilt2(indicom{i},[4 4]);
BasedFileName=sprint('%d.dcm',i);
FilteredFileName=fullfile(resultfolder,BasedFileName)
dicomwrite(medianfilter, FilteredFileName);
subplot(1,2,2), imshow(medianfilter,[]);
title('median filtered image number',num2str(i),'Interpreter','None')
end
0 Commenti
Risposte (1)
Geoff Hayes
il 23 Ago 2018
Shel - you are using uigetdir to get the source directory source_dir which you use to query for the number of files in that folder which match the filter
d=dir([source_dir,'\6--12-*.dcm']);
but you are not using that source_dir when reading the file
fname=['6--12-',num2str(i), '.dcm'];
indicom=dicomread(fname);
You will want to include the source directory when reading that file
indicom=dicomread(fullfile(source_dir, fname));
Try the above and see what happens! If this doesn't help, then please copy and paste the full error message to this question.
6 Commenti
Stephen23
il 24 Ago 2018
Modificato: Stephen23
il 24 Ago 2018
@Shel: read the dicomwrite help, where it clearly lists the accepted data types for the image as "int8 | int16 | uint8 | uint16". Now look at your code: is medianfilter an integer array, as dicomwrite requires, or is it a cell array? (hint: it is a cell array, because that is what you specified it as).
It is not clear why you are putting all of this data into cell arrays as you do not seem to do any processing with them after the loop, so the cell array is probably just a pointless complication. In any case, if you are using cell arrays then you will need to access the data inside the cell array using indexing:
dicomwrite(medianfilter{i},...)
Vedere anche
Categorie
Scopri di più su DICOM Format in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!