-
Notifications
You must be signed in to change notification settings - Fork 13
/
DICOMDeIdentify.m
59 lines (53 loc) · 1.83 KB
/
DICOMDeIdentify.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function DICOMDeIdentify
% DICOMDeIdentify
% 1. Create a top-level directory and then create subdirectories for each
% of your subjects and name them, e.g., 'S01', 'S02', 'S03', ... etc.
% 2. Copy each subject's DICOM (.dcm) files into their respective folder
% that you created in step 1.
% 3. Run this script from within the top-level directory
% Author: Mark Mikkelsen (Johns Hopkins University, 2018)
% Additional fields to remove
attrbs.StudyDate = '';
attrbs.SeriesDate = '';
attrbs.AcquisitionDate = '';
attrbs.ContentDate = '';
attrbs.StudyTime = '';
attrbs.SeriesTime = '';
attrbs.AcquisitionTime = '';
attrbs.ContentTime = '';
attrbs.ClinicalTrialProtocolName = '';
attrbs.PerformedStationName = '';
attrbs.PerformedLocation = '';
attrbs.PerformedProcedureStepDescription = '';
attrbs.PerformedProcedureStepStartDate = '';
attrbs.PerformedProcedureStepStartTime = '';
attrbs.PerformedProcedureStepID = '';
attrbs.PerformedProcedureStepDescription = '';
homeDir = pwd;
A = dir;
A = A(~ismember({A.name},{'.','..'}));
reverseStr = '';
for ii = 1:length(A)
if isfolder(A(ii).name)
if ~exist([A(ii).name '_anon'],'dir')
mkdir([A(ii).name '_anon']);
end
msg = sprintf('\n\nAnonymizing: %s',A(ii).name);
fprintf([reverseStr, msg]);
reverseStr = repmat(sprintf('\b'),1,length(msg));
cd(A(ii).name);
B = dir;
B = B(~ismember({B.name}, {'.','..','.DS_Store'}));
fprintf('\n\n');
for jj = 1:length(B)
if exist(B(jj).name,'file') == 2
dicomanon(B(jj).name, ['../' A(ii).name '_anon/' B(jj).name], 'update', attrbs);
msg2 = sprintf([B(jj).name ' ---> ' A(ii).name '_anon/' B(jj).name '\n']);
fprintf(msg2);
end
end
end
cd(homeDir);
end
cd(homeDir);
fprintf('\nDone!\n');