MATLAB: How read the 3D image

image processingImage Processing Toolboxmha format

I read the .mha file using mha_read_header(filename),but it is showing error.
Invalid field name: 'dim[0]'.
Error in mha_read_header (line 78) info.(type)=data;
Error in three (line 1) info = mha_read_header('a.mha'); What can I do to solve this problem.

Best Answer

I'm assuming you're using this function (always a good idea to mention where your code comes from). I don't know anything about it but after a quick glance it would appear that your file contains a field in the header that the reader doesn't know about. When reading unknown field, it simply creates a field with the same name in the output structure.
Unfortunately, in your case, that unknown field is not a valid field name for matlab structures. The quick fix would be to modify that line 78 to:
info(matlab.lang.makeValidName(type)) = data;
While that would fix the immediate error, there's no guarantee that the code will yet be able to read your file since, as said, the code knows nothing about that dim[0] field which may well be critical.
Related Question