Find a specific value/text inside a dicom header

15 次查看(过去 30 天)
Hi, I have dicom files (not images) which contain a header with lots of metadata, in the form of a structure with sub-structures. I need to find all the occurances of the value 'BODY' inside this header... any ideas? thanks!!

回答(1 个)

aditi bagora
aditi bagora 2023-10-10
Hello Alec,
I understand you want to read metadata from a DICOM file and specifically want to identify the fields that contain the term 'BODY' in the metadata.
You can use "dicominfo()" function to read the metadata from the DICOM file and store it in a structure called "dicom_info". You can directly access field name using the syntax dicom_info.filed_name.
To locate all instances of the term 'BODY' within the metadata, you can follow the below steps:
1. Read the metadata using the "dicominfo()" function and save it as a structure.
2. Extract all the field names from the structure using the "fields()" function.
3. Use "cellfun()" to iterate through the field names and identify the ones that contain the term 'BODY'. This will provide you with the indices of the matching fields.
4. Utilize the "find()" function to locate the field names that match the criteria.
5. Iterate through the identified fields and extract their corresponding values using the "extractfield()" function.
Below is a sample code that finds occurrences of ‘ID’ in the fields of DICOM header.
% Reading the metadata and fields in the structure
dicom_info = dicominfo('CT-MONO2-16-ankle.dcm');
fieldnames = fields(dicom_info);
% Filter all the tags that contains ‘ID’.
matchingindices =cellfun(@(y) ~isempty(strfind(y,'ID')), fieldnames);
matchingfieldnames = fieldnames(find(matchingindices)');
% Create a cell array that contains the field names and their values
val = cell([numel(matchingfieldnames),2]);
for i=1: numel(matchingfieldnames)
val{i,1} = matchingfieldnames{i};
val{i,2} = extractfield(dicom_info, matchingfieldnames{i});
end
Please refer to the following documentation to know more about reading metadata using "dicominfo" function:
Hope this helps!
Regards,
Aditi

类别

Help CenterFile Exchange 中查找有关 DICOM Format 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by