Saving 3D image

Hi,
I have a series of CT image slices that I've uploaded into MATLAB and are stacked in one variable. How do I save it out as a 3D image?

Answers (2)

Sean de Wolski
Sean de Wolski on 7 Dec 2011
Does it need to be accessible from another program?
doc save
I would just use save and save it as a matfile. If it has to be readable from another program (or someone without MATLAB) use fopen/fwrite
doc fopen
doc fwrite

11 Comments

Ka Zhang
Ka Zhang on 7 Dec 2011
Yes, I'm using another program called elastix for image registration. It's ran from a command line, so I don't think fopen/fwrite will work. Thanks!
fopen/fwrite will write it to binary. What format does elastix require? You're going to have to write to that format if elastix doesn't except raw binary.
Ka Zhang
Ka Zhang on 12 Dec 2011
For elastix TIFF, JPEG, PNG, BMP, and DICOM seem to be common. Is there any way I could save my variable with all the slices as one of those formats?
Walter Roberson
Walter Roberson on 12 Dec 2011
DICOM could do that for sure, in a format that elastix would be likely to understand.
The TIFF format does allow multiple images per file, but you would have to know exactly how elastix wanted the images named (or numbered)... and considering that JPEG and PNG and BMP files cannot handle multiple images per file, I would think it likely that elastix is not designed to look for the possibility of all of the slices being stored in the one TIFF file.
Ka Zhang
Ka Zhang on 12 Dec 2011
Is there anything special I need to specify with dicomwrite for a 3D variable? I'm getting errors when using dicomwrite.
Sean de Wolski
Sean de Wolski on 12 Dec 2011
How are you calling dicomwrite and what are the _full_ error messages?
Ka Zhang
Ka Zhang on 12 Dec 2011
>> dicomwrite('images','027_3D.dcm');
??? Error using ==> dicom_prep_ImagePixel>getPixelStorage at 168
Invalid datatype for image pixels.
Error in ==> dicom_prep_ImagePixel at 14
[ba, bs, hb, pr] = getPixelStorage(X, txfr);
Error in ==> dicom_prep_metadata at 40
metadata = dicom_prep_ImagePixel(metadata, X, map, txfr);
Error in ==> dicom_create_IOD at 30
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr);
Error in ==> dicomwrite>write_message at 236
[attrs, msg, status] = dicom_create_IOD(SOP_UID, X(:,:,:,p), map, ...
Error in ==> dicomwrite at 195
status = write_message(X, filename, map, metadata, options);
Sean de Wolski
Sean de Wolski on 12 Dec 2011
You're calling dicomwrite with 'images' which is a 1x6 string (typo, probably).
dicomwrite(images,'027_3D.dcm');
Ka Zhang
Ka Zhang on 12 Dec 2011
oops that was silly. But it seems it is not the problem:
>> dicomwrite(image027,'027_3D.dcm');
??? Error using ==> dicom_prep_ImagePixel>getPhotometricInterp at 98
Cannot determine photometric interpretation.
Error in ==> dicom_prep_ImagePixel at 10
metadata.(dicom_name_lookup('0028', '0004')) = getPhotometricInterp(X, map, txfr);
Error in ==> dicom_prep_metadata at 40
metadata = dicom_prep_ImagePixel(metadata, X, map, txfr);
Error in ==> dicom_create_IOD at 30
metadata = dicom_prep_metadata(IOD_UID, metadata, X, map, options.txfr);
Error in ==> dicomwrite>write_message at 236
[attrs, msg, status] = dicom_create_IOD(SOP_UID, X(:,:,:,p), map, ...
Error in ==> dicomwrite at 195
status = write_message(X, filename, map, metadata, options);
Sean de Wolski
Sean de Wolski on 12 Dec 2011
what does
whos images
return?
Ka Zhang
Ka Zhang on 12 Dec 2011
it's
Name Size Bytes Class Attributes
image027 512x512x99 207618048 double

Sign in to comment.

Walter Roberson
Walter Roberson on 12 Dec 2011

0 votes

1 Comment

Ka Zhang
Ka Zhang on 12 Dec 2011
unfortunately that writes out the 3D MATLAB variable into 2D slices with each slice as an individual dicom file. Thanks though

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Asked:

on 7 Dec 2011

Community Treasure Hunt

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

Start Hunting!