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!!
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 DICOM Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!