I have a set of data from an ultrasound image that I need to convert from a .mat file to a file that can be viewed in CAD software or 3D slicer.

3 views (last 30 days)
I have a data set that is a 601x601x601 double that was run through image processing code after an ultrasound to become this, representing a 3D model from the scan. When I load this into volumeViewer or volumeSegmenter, I can see the image from the scan clearly. My issue is that I need to convert this to a file type that can be loaded into 3D slicer for medical imaging, or another CAD software for viewing and saving.
I have tried using stlwrite, dicomwrite, and meshexport with no luck. The data set itself is too large to open and view in matlab as a variable or send on here. The code examples I have used are attached. I was able to successfully output with stlwrite, however, when loading it into CAD software it was not the image it was meant to be, just a large cylindrical shape.
These are the errors I get when using dicomwrite:
Error using images.internal.dicom.dicom_prep_ImagePixel>getPhotometricInterp (line 134)
Cannot determine photometric interpretation.
Error in images.internal.dicom.dicom_prep_ImagePixel (line 9)
metadata.(images.internal.dicom.lookupActions('0028', '0004', dictionary)) = getPhotometricInterp(metadata, X, map, txfr, dictionary);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in dicom_prep_metadata (line 51)
metadata = images.internal.dicom.dicom_prep_ImagePixel(metadata, X, map, txfr, useMetadataBitDepths, dictionary);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in dicom_create_IOD (line 26)
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr, options.usemetadatabitdepths, dictionary);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in dicomwrite>write_message (line 92)
[attrs, status] = dicom_create_IOD(SOP_UID, X, map, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in dicomwrite (line 28)
[status, options] = write_message(X, filename, map, metadata, options);

Answers (1)

Walter Roberson
Walter Roberson on 5 Dec 2024
By far the easiest way to write dicom files is to already have a representative file of the same type, and use dicominfo() on the representative file, and to dicomwrite() citing the reference information.
If you start from scratch then you need to fill out numerous fields in the dicom header. The photometric interpretation is just one of the many fields that need to be constructed before dicomwrite() can succeed.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!