Repository navigation
Can't save image metadata #32
Copy link
Copy link
Closed
Description
I noticed an issue when trying to save image metadata using mrd.StreamItem.ImageComplexFloat data format.
Instead of adding metadata to the file, it throughs an error.
I use the MRD library version 2.1.2-preview. I have Window 11 with Matlab R2023b.
The error should be reproduced by running this code:
clear
w = mrd.binary.MrdWriter("testfile.mrd");
h = mrd.Header();
w.write_header(h);
img = complex(randn(100,50),randn(100,50));
im_head = mrd.ImageHeader('image_type',mrd.ImageType.COMPLEX);
meta = dictionary();
meta("StudyDescription") = "Image title";
meta("InversionTime") = 3;
meta("EchoTime") = 6;
meta("FlipAngle") = 90;
img_obj = mrd.ImageComplexFloat("data",img,"head",im_head,"meta",meta);
w.write_data(mrd.StreamItem.ImageComplexFloat(img_obj));
w.end_data();
w.close();
Output should be this error:
Unrecognized method, property, or field 'is_trivially_serializable' for class
'yardl.binary.UnionSerializer'.
Error in yardl.binary.VectorSerializerBase/write (line 40)
if self.item_serializer_.is_trivially_serializable()
Error in yardl.binary.MapSerializer/write (line 33)
self.value_serializer_.write(outstream, vs(i));
Error in yardl.binary.RecordSerializer/write_ (line 27)
fs.write(outstream, field_value);
Error in mrd.binary.ImageSerializer/write (line 18)
self.write_(outstream, value.head, value.data, value.meta);
Error in yardl.binary.UnionSerializer/write (line 48)
serializer.write(outstream, value.value);
Error in yardl.binary.StreamSerializer/write (line 45)
self.item_serializer_.write(outstream, transpose(values(:, i)));
Error in mrd.binary.MrdWriter/write_data_ (line 26)
self.data_serializer.write(self.stream_, value);
Error in mrd.MrdWriterBase/write_data (line 39)
self.write_data_(value);
Error in mrd_error (line 16)
w.write_data(mrd.StreamItem.ImageComplexFloat(img_obj));
I expect that image metadata should save normally.
That is the simplest way tor reproduce the error.
I wonder if the error is caused by yardl because it appears to be that it cannot hand maps correctly. Image metadata has been defined as a map which is producing issues.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]Can not save image metadata[/-][+]Can't save image metadata[/+]naegelejd commentedon Dec 18, 2025
Thank you for opening this issue. There are two issues here:
yardlfor which I opened an issue: MATLAB UnionSerializer should derive from yardl.binary.TypeSerializer microsoft/yardl#260ImageMetaValueconstructor to store them in theImageMeta, e.g.This is because MATLAB's dictionary is statically typed, unlike in Python, for example.
simppakheikki commentedon Jan 2, 2026
Hi and thanks for help!
Unfortunately, your piece of advice did not work since it gave exactly same error.
What version and branch of MRD library you have? Which commit?
Same error again
`
Unrecognized method, property, or field 'is_trivially_serializable' for class 'yardl.binary.UnionSerializer'.
Error in yardl.binary.VectorSerializerBase/write (line 40)
if self.item_serializer_.is_trivially_serializable()
Error in yardl.binary.MapSerializer/write (line 33)
self.value_serializer_.write(outstream, vs(i));
Error in yardl.binary.RecordSerializer/write_ (line 27)
fs.write(outstream, field_value);
Error in mrd.binary.ImageSerializer/write (line 18)
self.write_(outstream, value.head, value.data, value.meta);
Error in yardl.binary.UnionSerializer/write (line 48)
serializer.write(outstream, value.value);
Error in yardl.binary.StreamSerializer/write (line 45)
self.item_serializer_.write(outstream, transpose(values(:, i)));
Error in mrd.binary.MrdWriter/write_data_ (line 26)
self.data_serializer.write(self.stream_, value);
Error in mrd.MrdWriterBase/write_data (line 39)
self.write_data_(value);
Error in untitled (line 12)
w.write_data(mrd.StreamItem.ImageComplexFloat(img));
`
naegelejd commentedon Jan 15, 2026
This will not work until the bug in Yardl is fixed and this repository is updated to use the new, fixed version of Yardl.
That being said, I fixed the bug in Yardl, so we just need to update MRD to use
yardl v0.6.6. I'll do that soon.naegelejd commentedon Jan 29, 2026
This bug is now fixed in the
mainbranch (97d3730) and the fix will be included in the next release, 2.2.0.simppakheikki commentedon Feb 17, 2026
Hi,
Your fix works! I managed to update my code.
Thanks!