MATLAB: Write a dicom image with input that is not dicom

dicomdicomwriteimage processing

Hi fellows,
Before showing the link, I have already read the documentation for dicomwrite. It turns out that it works in the instance of an input image already being a dicom image.
I want to create a dicom file using an image that is an object in matlab environment.
I understand that the metadata structure go nuts, because there is no info in the structure (as the input is not derived from a dicom file).
When I try to create the dicom image, I get the following message:
Error using dicom_prep_ImagePixel>getPhotometricInterp (line 134)
Cannot determine photometric interpretation.
Error in dicom_prep_ImagePixel (line 9)
metadata.(dicom_name_lookup('0028', '0004', dictionary)) =
getPhotometricInterp(metadata, X, map, txfr, dictionary);
Error in dicom_prep_metadata (line 51)
metadata = 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 276)
[attrs, status] = dicom_create_IOD(SOP_UID, X, map, ...
Error in dicomwrite (line 212)
[status, options] = write_message(X, filename, map, metadata,
options);
How can I surpass this issue?
Thanks in advance

Best Answer

I recommend that you find an existing dicom file that has the same properties you want, and use dicominfo() to read the meta-data. (You could store the metadata somewhere so that you did not need to keep the base image around.)
Then when you use dicomwrite() pass the saved metadata before any name/value pairs. dicomwrite() knows enough to override the information about the number of pixels, but will retain (most of?) the other information. You would want to do some testing to ensure it does not accidentally duplicate UUIDs specific to the patient.