Using pydicom in MatLab
Show older comments
I'm experimenting with using pydicom functions inside MatLab as an alternative to dicominfo to speed up reading of dicoms.
I import the module and read the dicom header of the file dcmFile using dcmread:
py.importlib.import_module('pydicom');
ds=py.pydicom.dcmread([dcmFile],false,true);
It works really well, but how do I efficiently extract single tags from the ds object?
As an example, in python, I would use ds[0008,103e] or ds.SeriesDescription to get the Series Description tag. But this doesn't work in Matlab for the Python FileDataset object.
The following works, but is rather cumbersome:
tmp=ds.data_element('SeriesDescription'); seriesDescription=char(tmp.value);
Is there a better way to extract tags?
Thanks,
Lars
3 Comments
Rik
on 4 Nov 2020
You could consider using parts of the Dicom Toolbox that Dirk-Jan Kroon published on the FEX. I am also working on that, but my code is not yet in a shape where I'm comfortable publishing it on the FEX myself. The code by Dirk-Jan is less robust, but it often at least an order of magnitude faster than dicomread and dicominfo.
Lars Tolbod
on 4 Nov 2020
Rik
on 4 Nov 2020
I assumed he would be using his same code everywhere, apparently not. This submission doesn't use the builtin tools. You might want to use the code below to create the dictionary.
%%replace this
% Load Dicom Tag Library
functionname='ReadDicomElementList.m';
functiondir=which(functionname);
functiondir=functiondir(1:end-length(functionname));
load([functiondir 'Dictonary/DicomTagDictionary.mat']);
%%with this
dict_base=ingest_dict;
dcmdic.group=zeros(size(dict_base,1),1);
dcmdic.element=zeros(size(dict_base,1),1);
for n=1:size(dict_base,1)
dcmdic.group(n)=hex2dec(dict_base{n,1});
dcmdic.element(n)=hex2dec(dict_base{n,2});
end
dcmdic.type=dict_base(:,3);
dcmdic.name=dict_base(:,4);
Answers (0)
Categories
Find more on DICOM Format in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!