ExamsInfo(i,:) = {infx(i), thisfile};
WarmFuzzy = 0;
data_folder = uigetdir;
files_in_folder = dir( fullfile(data_folder, '*.dcm'));
files_in_folder = files_in_folder( [files_in_folder.bytes] > 0);
filenames_in_folder = fullfile(data_folder, {files_in_folder.name});
num_files_in_folder = numel(filenamess_in_folder);
DB2 = strings([num_files_in_folder,2]);
dlu = dicomlookup('0008', '103E');
ExamsInfo = cell(num_files_in_folder,2);
Flag(1:num_files_in_folder) = true;
Flag1(1:num_files_in_folder) = true;
n = num_files_in_folder;
infx(1:10) = dicominfo(filenames_in_folder{1});
for i = 1:num_files_in_folder
infx(i) = dicominfo(filenames_in_folder{i});
str1(i) = infx(i).(dlu);
end
parfor i = 1 : num_files_in_folder
newDB2 = strings(1,2);
thisfile = filenames_in_folder{i};
try
infx(i) = dicominfo(thisfile);
catch ME
Flag(i) = false;
warning("Problem: dicominfo error.");
newDB2(1) = "Bad DICOM File";
newDB2(2) = thisfile;
end
if (Flag(i))
Flag1(i) = true;
try
str1(i) = infx(i).(dlu);
catch ME
warning("No Series Discription");
newDB2(1) = "Nyet";
newDB2(2) = thisfile;
Flag1(i) = false;
end
if(Flag1(i))
newDB2(1) = str1(i);
newDB2(2) = thisfile;
end
ExamsInfo(i,:) = [{infx(i)},{thisfile}];
end
DB2(i,:) = newDB2;
end
disp("Done reading in the directory information");
Dicom_type = {'[GA-N_CTAC_60s] Rest Rb' '[NG_NAC_60s] Stress Rb' 'Cardiac-ldCT' '[NG_NAC_60s] Rest Rb' '[NG_CTAC_60s] Rest Rb' '[NG_CTAC_60s] Stress Rb' '[GA-N_CTAC_60s] Stress Rb'};
prime = 1033;
LTA = strings(prime,361);
ptr_lga(prime,361) = int16(0);
for i = 1:prime
ptr_lga(1,1) = 0;
end
nitem(1:prime) = int16(1);
hflag = true;
for i= 1:num_files_in_folder
Logical_Flag = (DB2(i,1) ~= "Bad DICOM File") && (DB2(i,1) ~= "Nyet") ...
&& convertCharsToStrings((ExamsInfo{i, 1}.AccessionNumber) ...
== convertCharsToStrings(ExamsInfo{1, 1}.AccessionNumber));
if (Logical_Flag)
if (hflag)
arr = convertStringsToChars(DB2(i,1));
hash = mod(string2hash(arr), prime)+1;
end
hflag = true;
switch LTA(hash,1)
case ""
LTA(hash,1)= DB2(i,1);
nitem(hash) = nitem(hash) + 1;
LTA(hash,nitem(hash)) = DB2(i,2);
lg2 = false;
lg = ( DB2(i,1) == Dicom_type);
for j = 1:7
lg2 = lg2 | lg(j);
end
if lg2
ptr_lga(hash,nitem(hash)) = int16(ExamsInfo{i,1}.InstanceNumber);
ptr_lga(hash,1) = ptr_lga(hash,1) +1;
end
case DB2(i,1)
nitem(hash) = nitem(hash) + 1;
LTA(hash,nitem(hash)) = DB2(i,2);
lg2 = false;
lg = ( DB2(i,1) == Dicom_type);
for j = 1:7
lg2 = lg2 | lg(j);
end
if lg2
ptr_lga(hash,nitem(hash)) = int16(ExamsInfo{i,1}.InstanceNumber);
ptr_lga(hash,1) = ptr_lga(hash,1) +1;
end
otherwise
if ~(LTA(hash,1) == DB2(i,1))
hflag = false;
i = i-1;
hash = mod((hash+7),prime);
else
error('Unexpected event - Halting execution');
end
end
end
end
Dicom_name = {"Rest_gated_AC" "StressNG_NAC" "Cardiac_CT" "Rest_NG_NAC" "Rest_NG_AC" "Stress_NG_AC" "Stress_gated_AC"};
exit;
hashtag(1:7) = int16(0);
Rand_Num_Name = string( int16(rand(1,1) * 50000));
for i=1:7
hashtag(i) = mod(string2hash(char(Dicom_type(i))), prime)+1;
while (Dicom_type(i) ~= LTA(hashtag(i)))
hashtag(i) = mod((hashtag(i)+7),prime);
end
slicex = dicomread(LTA(hashtag(i),2));
num_slices = ptr_lga(hashtag(i),1);
[x,y] = size(slicex);
Dimage = int16(zeros(num_slices,x,y));
for k = 1:num_slices
indx = ptr_lga(hashtag(i),(k+1));
Dimage(indx, 1:x,1:y) = dicomread(LTA(hashtag(i),(k+1)));
end
save(strcat(string(Dicom_name(i)),"_", Rand_Num_Name, ".mat"), 'Dimage')
end
IDt.PatientName = ExamsInfo{1, 1}.PatientName;
IDt.AccessionNumber = ExamsInfo{1, 1}.AccessionNumber;
IDt.StudyDate = ExamsInfo{1, 1}.StudyDate;
save(char(strcat("IDt", Rand_Num_Name, ".mat")), 'IDt')
Best Answer