forked from Chaogan-Yan/REST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest_DicomSorter.m
executable file
·42 lines (40 loc) · 1.81 KB
/
rest_DicomSorter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function dirlist=rest_DicomSorter(rawdir,outdir,dicomtype,DirectoryHierarchy)
% FORMAT dirlist=rest_DicomSorter(rawdir,outdir,dicomtype,DirectoryHierarchy)
% Input:
% rawdir - directory of source files
% outdir - directory to store the sorted dir
% dicomtype - The File name surfix of the DICOM files. e.g. IMA, dcm or none.
% DirectoryHierarchy - The Hierarchy of Directory: 0 - SubjectName/SeriesName; 1 - SeriesName/SubjectName.
% Output:
% *.IMA/*.dcm/*.* - Sorted DICOM images.
% By YAN Chao-Gan and Dong Zhang-Ye 091212.
% State Key Laboratory of Cognitive Neuroscience and Learning, Beijing Normal University, China, 100875
% http://www.restfmri.net
% Mail to Authors: <a href="[email protected]">YAN Chao-Gan</a>; <a href="[email protected]">DONG Zhang-Ye</a>
% Version=1.0;
% Release=20091215;
%------------------------------------------------------------------------------------------------------------------------------
if strcmp(dicomtype,'none')
rawdatatmp=dir([rawdir,filesep,'*']);
rawdata= rawdatatmp(3:end);
else
rawdata=dir([rawdir,filesep,'*.',dicomtype]);
end
dirlist={};
for i=1:length(rawdata)
rest_waitbar(i/length(rawdata), ...
rawdir, ...
'DICOM Sorting','Child','NeedCancelBtn');
dicominfotmp = dicominfo([rawdir,filesep,rawdata(i).name]);
Indextmp=['0000',int2str(dicominfotmp.SeriesNumber)];
if DirectoryHierarchy==0
dirname=[outdir,filesep,dicominfotmp.PatientID,filesep,Indextmp(end-3:end),'_',dicominfotmp.ProtocolName];
else
dirname=[outdir,filesep,Indextmp(end-3:end),'_',dicominfotmp.ProtocolName,filesep,dicominfotmp.PatientID];
end
if ~isdir(dirname)
mkdir(dirname);
dirlist=[dirlist;dirname];
end
copyfile([rawdir,filesep,rawdata(i).name],dirname);
end