Hello,
I am a beginner in using simpleitk. I have came across an issue with when reading specific header informatic from my MINC file resulting in [UNKNOWN_PRINT_CHARACTERISTICS]. However, when I view these information using external programs like ITKsnap, these information are present. Any suggestions on how I can fix this? See example below:
reader = sitk.ImageFileReader()
reader.SetImageIO("MINCImageIO")
reader.SetFileName(inputImageFileName)
image = reader.Execute()
metadata = {key: reader.GetMetaData(key) for key in reader.GetMetaDataKeys()}
age = metadata.get("patient:age", "")
This would then output:
[UNKNOWN_PRINT_CHARACTERISTICS]
As compared to when viewing this specific header information in ITKsnap
This specific information is viewable. Any suggestions on how this can be fixed?
dzenanz
(Dženan ZukiÄ)
August 16, 2024, 2:03pm
2
This is a general problem with printing entries of MetaDataDictionary
values from Python. @blowekamp I guess we should fix this?
Amazing! Please let me know when there is a fix or an alternative. This would definitely help stream line some of my work.
blowekamp
(Bradley Lowekamp)
August 16, 2024, 2:30pm
4
What version of SimpleITK are you using? What binaries were installed etc.?
Also do you have a sample MINC file with this field that could be shared?
@gdevenyi Do you know where this field is added into the metadata dictionary in MINICIO?
I am using 2.3.1, I can definitely share the environment I am using.
Unfortunately I canāt share the MINC file as itās confidential. Thanks
gdevenyi
(Gabriel A. Devenyi)
August 20, 2024, 3:53pm
6
The relevant lines which iterate over all of the header objects in the MINC file are here:
// iterate over all root level groups , and extract all underlying attributes
// unfortunately more complicated attribute structure of MINC2 is not supported
// at least it is not used anywhere
milisthandle_t grplist;
if ((milist_start(m_MINCPImpl->m_Volume, "", 0, &grplist)) == MI_NOERROR)
{
char group_name[256];
milisthandle_t attlist;
while (milist_grp_next(grplist, group_name, sizeof(group_name)) == MI_NOERROR)
{
if ((milist_start(m_MINCPImpl->m_Volume, group_name, 1, &attlist)) == MI_NOERROR)
{
char attribute[256];
while (milist_attr_next(
m_MINCPImpl->m_Volume, attlist, group_name, sizeof(group_name), attribute, sizeof(attribute)) ==
MI_NOERROR)
{
This file has been truncated. show original
blowekamp
(Bradley Lowekamp)
August 20, 2024, 5:08pm
7
@gdevenyi Thank you. Do you have a sample MINC files with one of these array fields that I could use to further investigate?
blowekamp
(Bradley Lowekamp)
August 20, 2024, 5:46pm
8
After writing a quick implementation to call the value objectās Print method or operator<< if implemented I read the documentation for the MetaDataObject class:
* The behavior of the MetaDataObject<Type>::Print() function has many plausible
* application dependent implementations. The default implementation prints the
* string "[UNKNOWN PRINT CHARACTERISTICS]" that works for all possible
* MetaDataObject types.
*
* The application developer may overload the default implementation to provide
* a specialized Print() characteristics to produce results desirable for their application.
* A set of very crude Macros {NATIVE_TYPE_METADATAPRINT, ITK_OBJECT_TYPE_METADATAPRINT_1COMMA,
* ITK_IMAGE_TYPE_METADATAPRINT } are provided to facilitate a very simple implementation, and as an example.
So it appear that this is a feature and not a bug? @hjmjohnson
It would appear that it is simpleITKās responsibility to explicitly implement the Print method for these types, and avoid conflict of other libraries using ITK.
2 Likes
phcerdan
(Pablo Hernandez-Cerdan)
August 20, 2024, 11:15pm
9
I hit this some time ago, and had a stab on it.
InsightSoftwareConsortium:master
ā phcerdan:fix_metadataobject_print
opened 12:37AM - 14 Dec 23 UTC
Also removes dead code related to METADATAPRINT
Fix #1454
## PR Checklist
ā¦
- [x] No [API changes](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#breaking-changes) were made (or the changes have been approved)
- [x] No [major design changes](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#design-changes) were made (or the changes have been approved)
- [x] Added test (or behavior not changed)
- [x] Updated API documentation (or API not changed)
- [NA] Added Python wrapping to new files (if any) as described in [ITK Software Guide](https://itk.org/ItkSoftwareGuide.pdf) Section 9.5
However, I didnāt have time to fight compilers to address reviewers comments to get to the finish line.
In case somebody wants to follow on.
2 Likes
gdevenyi
(Gabriel A. Devenyi)
August 21, 2024, 7:36pm
10
Hereās a rich MINC2 file generated by dcm2mnc,
2 Likes
blowekamp
(Bradley Lowekamp)
August 21, 2024, 8:41pm
11
@gdevenyi Thank you for the image
@phcerdan Thanks for the reference to the PR, and the open issue. Which includes @hjmjohnson comment that he is in favor of removing the old macros, and including support for printing for the MetaDataObjects directly in ITK.
I made a PR with the implementation I did before I saw yours.
InsightSoftwareConsortium:master
ā blowekamp:print_metadata_object
opened 03:12PM - 21 Aug 24 UTC
Also removes dead code related to METADATAPRINT
Does not currently add printiā¦ ng for std::vector.
Fix #1454
Near duplicate of: #4368
Co-Author: Pablo Hernandez-Cerdan <pablo.hernandez.cerdan@outlook.com>
<!-- The text within this markup is a comment, and is intended to provide
guidelines to open a Pull Request for the ITK repository. This text will not
be part of the Pull Request. -->
<!-- See the CONTRIBUTING (CONTRIBUTING.md) guide. Specifically:
Start ITK commit messages with a standard prefix (and a space):
* BUG: fix for runtime crash or incorrect result
* COMP: compiler error or warning fix
* DOC: documentation change
* ENH: new functionality
* PERF: performance improvement
* STYLE: no logic impact (indentation, comments)
* WIP: Work In Progress not ready for merge
Provide a short, meaningful message that describes the change you made.
When the PR is based on a single commit, the commit message is usually left as
the PR message.
A reference to a related issue or pull request (https://help.github.com/articles/basic-writing-and-formatting-syntax/#referencing-issues-and-pull-requests)
in your repository. You can automatically
close a related issues using keywords (https://help.github.com/articles/closing-issues-using-keywords/)
@mentions (https://help.github.com/articles/basic-writing-and-formatting-syntax/#mentioning-people-and-teams)
of the person or team responsible for reviewing proposed changes. -->
## PR Checklist
- [ ] No [API changes](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#breaking-changes) were made (or the changes have been approved)
- [ ] No [major design changes](https://github.com/InsightSoftwareConsortium/ITK/blob/master/CONTRIBUTING.md#design-changes) were made (or the changes have been approved)
- [ ] Added test (or behavior not changed)
- [ ] Updated API documentation (or API not changed)
- [ ] Added [license](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Utilities/KWStyle/ITKHeader.h) to new files (if any)
- [ ] Added Python wrapping to new files (if any) as described in [ITK Software Guide](https://itk.org/ItkSoftwareGuide.pdf) Section 9.5
- [ ] Added [ITK examples](https://github.com/InsightSoftwareConsortium/ITKSphinxExamples) for all new major features (if any)
Refer to the [ITK Software Guide](https://itk.org/ItkSoftwareGuide.pdf) for
further development details if necessary.
It appears to work with the current infrastructure.
3 Likes