Can't open files
Mostra commenti meno recenti
Hi,
I'm not really familiar with MATLAB, but I need it to extract some information for my project.
I'm using a code (CGITA) that aimes to open and analys medical images (DICOM).
But I'm not able to open these images as I got the following error:
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in parse_directory_for_dicom (line 97)
fileinfo.PatientName.GivenName = 'N/A';
Error in CGITA_GUI>load_Primary_btn_Callback (line 450)
[filelist fusion_filelist] = parse_directory_for_dicom(Primary_dir);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CGITA_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CGITA_GUI('load_Primary_btn_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Appreciate your help.
4 Commenti
Rik
il 9 Lug 2019
Can you provide a link to the code you're using? And what release are you using? Have you tried using the debugger to determine the data type of the variables around this line of code?
Nora A
il 9 Lug 2019
I'm using R2018a
function varargout = parse_directory_for_dicom(dirname);
all_files_list = list_all_files(dirname, {}, '');
%cd(handles.dicom_folder);
% % Alternative option
% dirname = get(handles.original_dir,'String');
% if ~isdir(dirname)
% errordlg('This is not a valid folder');
% return;
% end
%a = dir(dirname);
study_ID = []; % create empty cell array
study_description_name = {};
% description_location = {};
%b = ls(dirname);
%dirlen = length(b)-2; % must subtract "." & ".." 2 elements
dirlen = length(all_files_list);
filelist = {};
if dirlen ==0
return;
end
do_fields_table= [8 4158; 8 49; 8 32; 8 4144; 32 16; 8 8487; 16 16; 8 16; 32 13];
dicomdict('set', 'dicom-dict_truncated.txt');
%tic
timing_n = floor(dirlen/20);
h = waitbar(0,'Parsing the directory for DICOM files. Please wait...');
steps = dirlen;
for i = 1:dirlen
%dicomread = fullfile(handles.dicom_folder, a(i+2).name);
%info = dicominfo(all_files_list{i});
if mod(i, timing_n) == 0
waitbar(i / steps);
end
if exist('dcmreadfile')
info = [];
try
info = dcmreadfile(all_files_list{i});
catch EM
end
else
info = dicominfo_Dean_rev(all_files_list{i}, do_fields_table);
end
%if ~isempty(info) && isfield(info, 'StudyID')
if ~isempty(info) && isfield(info, 'StudyInstanceUID')
%warndlg('No dicom files found');
%else
%find_location = strcmp(study_ID, info.StudyID); % "find(study_ID == info.StudyID)" is unavailable because info.StudyID is a string
find_location = strcmp(study_ID, info.StudyInstanceUID); % "find(study_ID == info.StudyID)" is unavailable because info.StudyID is a string
if sum(find_location) == 0
% new ID for the ID List
%study_ID{end+1} = info.StudyID;
study_ID{end+1} = info.StudyInstanceUID;
find_location = length(study_ID);
study_description_name{find_location}.description{1} = info.SeriesDescription;
study_description{find_location}.description{1}.filename{1} = all_files_list{i};
else
% ID already exists in list
if isfield(study_description{find_location}, 'description')
description_location = find(strcmp(study_description_name{find_location}.description, info.SeriesDescription));
if isempty(description_location)
study_description_name{find_location}.description{end+1} = info.SeriesDescription;
study_description{find_location}.description{end+1}.filename{1} = all_files_list{i};
else
study_description{find_location}.description{description_location}.filename{end+1} = all_files_list{i};
% study_description_name{find_location}.description{description_location} = info.SeriesDescription;
end
else
study_description_name{find_location}.description{1} = info.SeriesDescription;
study_description{find_location}.description{1}.filename{1} = all_files_list{i};
end
end
end
end
close(h)
dicomdict('factory');
table_content = {};
datatable = {};
for i = 1:length(study_ID)
for j = 1:length(study_description_name{i}.description)
if exist('dcmreadfile')
fileinfo = dcmreadfile(study_description{i}.description{j}.filename{1});
else
fileinfo = dicominfo(study_description{i}.description{j}.filename{1});
end
if ~isfield(fileinfo.PatientName, 'GivenName')
fileinfo.PatientName.GivenName = 'N/A';
end
if ~isfield(fileinfo.PatientName, 'FamilyName')
fileinfo.PatientName.FamilyName = 'N/A';
end
if ~isfield(fileinfo, 'SeriesTime')
datatable(end+1,:) = {study_description{i}.description{j}.filename, []};
fileinfo.SeriesTime = 'N/A';
else
datatable(end+1,:) = {study_description{i}.description{j}.filename, fileinfo.SeriesTime};
end
table_content(end+1,:) = {false, false, fileinfo.PatientID, fileinfo.PatientName.FamilyName, fileinfo.PatientName.GivenName, study_ID{i}, study_description_name{i}.description{j}, fileinfo.StudyDate, fileinfo.SeriesTime, ...
length(study_description{i}.description{j}.filename), false};
end
end
if size(datatable,1) == 1
% simple case. Return the list.
filelist = study_description{1}.description{1}.filename;
else
[filelist fusion_filelist] = DICOM_selection_GUI(datatable, table_content, fileinfo, study_ID, study_description);
end
varargout{1} = filelist;
if exist('fusion_filelist')
varargout{2} = fusion_filelist;
else
varargout{2} = '';
end
return;
Rik
il 9 Lug 2019
This code seems very much a work in progress. There is a lot of commented code, and not all comments accurately describe what the code is doing.
The Image Processing Toolbox function dicominfo apparently has a different output from that custom function dcmreadfile. The code below should reproduce your error.
clc
clear fileinfo
fileinfo.PatientName='foo';
if ~isfield(fileinfo.PatientName, 'GivenName')
fileinfo.PatientName.GivenName = 'N/A';
else
disp('condition returned false')
end
This example shows the probable root cause: fileinfo.PatientName is already a char array, instead of a struct, as that assignment assumes.
mahmoud hafez
il 4 Feb 2023
This code old work and agree with old Matlab version, so, you can use an older version of MATLAB to avoid this error.
Risposte (1)
Image Analyst
il 4 Feb 2023
Try changing the first few lines of the function to this
function varargout = parse_directory_for_dicom(dirname)
dirListing = dir(fullfile(dirname, '*.dcm'));
all_files_list = fullfile(dirname, {dirListing.name})
Categorie
Scopri di più su Read and Write Image Data from Files in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!