Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

multiframe dicomwrite

548 views
Skip to first unread message

sara sacchi

unread,
Dec 14, 2008, 6:19:02 PM12/14/08
to
Hi!
I'm working with multiframe dicom files.
When reading them with dicomread function, MATLAB create a 4D-array (size NxMxDxF) where image data are stored.
When I try to create a new multiframe dicom file using dicomwrite, MATLAB creates F new dicom files, where F is the number of frames.
On the contrary, I'd like to create only ONE dicom file, in which all F frames are stored.
Is it possible?
How can I do that? I have to modify dicomwrite function? Anybody has already done that?
Thank you so much for your help!!!
Sara.

sara sacchi

unread,
Dec 28, 2008, 7:46:02 AM12/28/08
to
I did it: dicomwrite function modified. Now it can write multiframe dicom files, and I can view these files also with some other (few) dicom viewers. For simiplicity, I implemented only ad hoc ultrasound case. (For the time being, I'm just experimenting with it!!!).
I have some problems with quality of the image: it decreases when writing a new multiframe dicom file using my function. I haven't discovered the reason why yet. I think it could be something about data classes (uint8, uint16, double)... I'll think about it! If any suggestion, please let me know! Thank you for help!
Sara.

"sara sacchi" <sara_...@hotmail.com> wrote in message <gi4496$5k$1...@fred.mathworks.com>...

Jeffrey

unread,
May 13, 2009, 3:28:01 PM5/13/09
to
How did you modify it. Is it working well? It would be great if matlab implemented this.

-Jeff


"sara sacchi" <sara_...@hotmail.com> wrote in message <gj7sea$93r$1...@fred.mathworks.com>...

Sune Buhl

unread,
May 14, 2009, 3:38:01 AM5/14/09
to
Hi.

Sounds great - I am also really interested in how you did the multiframe dicomwrite to a single file.

Can you maybe upload your code or give a hint?

And yes, an implementation by MATLAB would be great.

sara sacchi

unread,
May 16, 2009, 7:58:01 AM5/16/09
to
Hi guys,
it's true I modified the dicomwrite function in order to write multiframe dicom files, but I didn't succeed in solving problems with the quality of the image... and a lot of other details... which make my function not usefull in practice. As you certainly know, dicom is a standard, and files have to be validated and follow a lot ofstrict rules. Well my function create something like a dicom multiframe, but for sure it's a NOT VALIDATED dicom multiframe. Thus... unluckly, I don't know if it could be actually usefull for you.
To be honest, since I'm very busy in this periode, I stopped thinking about it: it remain just a draft. As I've just written, I didin't succeed in solving all its bugs. If you want to have a look on the code (I warn you: it's a very rough code!) I can post it. I need some time to do it, because my notebook crashed, I have to olay some time with it to extract my data. But I can do it. Give me just some time!
bye!
sara.

"Jeffrey " <i...@removeforspam.jhu.edu> wrote in message <guf701$18r$1...@fred.mathworks.com>...

Lead Bucket

unread,
May 21, 2010, 2:25:22 PM5/21/10
to
I have struggled with this same issue. After exploring the dicomwrite function a bit, it looks like the functionality is there for a multiframe dicomwrite, but its just not activated (at least as of my version which is R2008b). To get a multiframe write to a single file, I had to modify the private function dicom_encode_jpeg_lossy.m (and any other encoding function I planned on using - there seemed to be 3 provided) to cycle through the multiple frames (they are currently set to implement only a single frame). Second, I had to modify dicomwrite.m to remove the for loop associated with the multiple frames along with the three lines that had dependencies on the loop variable p (the dicom_create_IOD function call, the dicom_copy_IOD function call, and the get_filename function call which I just changed to destination = filename;).

The rest of the functionality for a multiframe write is there, so once you implement the above changes, it seems to work fine. I'm no expert on dicom format and I don't know if the resulting dicom file meets dicom specs, but all I needed was the data and not the remaining dicom info, so this worked for me.

Lead Bucket

unread,
May 21, 2010, 2:25:22 PM5/21/10
to

lovely_m M

unread,
Jun 30, 2010, 5:47:03 AM6/30/10
to
Hi Lead Bucket,

Great that you figured it out :) I've been trying to modify the functions according to your description but I can't get it to work. Could you maybe post the exact changes you made?

Many thanks,
M

Lead Bucket

unread,
Jul 20, 2010, 6:11:03 PM7/20/10
to
"lovely_m M" <love...@hotmail.nl> wrote in message <i0f3qn$eng$1...@fred.mathworks.com>...

Hi M,

First, I created a copy of the private directory .../toolbox/images/iptformats/private and dicomwrite so I didn't muck things up with the original version. Then, in the dicom_encode_jpeg_lossy.m file, I modified frames to reflect the true number of frames and added a for loop:

frames = size(X,4);
for p = 1:frames
tempfile = tempname;
imwrite(X(:,:,:,p), tempfile, 'jpeg');
.....
%frames = 1;
.....
end

Next, in dicomwrite.m I commented out the for loop that cycled through the frames, removed the dependency of X on p, and changed the destination to filename, all in the write_message subfunction:

.....
%for p = 1:num_frames
.....
[attrs, msg, status] = dicom_create_IOD(SOP_UID, X, map, ...
.....
[attrs, msg, status] = dicom_copy_IOD(X, map, ...
,....
destination = filename;
%destination = get_filename(filename, p, num_frames);
.....
%end

That was it. It seemed to work fine for me here, although I was using the 'copy' option. I didn't test it for the other options. It gave me one or two warnings on one of the dicom variables not being correct, but I was okay with that.

Hope this works for you!
-LB

K P

unread,
Jan 5, 2011, 1:33:05 PM1/5/11
to
Hi Lead Bucket,

Could you please give me more info on the code for multiframe dicomwrite. I am creating a multiframe dicom file with several tif images.
I tried the changes in the two functions as you mentioned but how am i suppose to add multiple frames using dicomwrite function( ie. in the programme code what is the syntax for adding multiple frames at a time). I am still ale to add only one frame.
Looking forward for your help.

Thank You
Kamlesh

"Lead Bucket" wrote in message <i256tn$gj5$1...@fred.mathworks.com>...

sara sacchi

unread,
Jan 21, 2011, 5:06:04 AM1/21/11
to
Hi guys,
Although I stopped thinking about the multiframe dicomwrite beacuse of other commitments, reading your updates makes me want to handle again this issue.
I tried the solution suggested by LB and it works fine!
Of course, you cannot guaranteed about DICOM specs validation, but in my opinion it's a good solution to be used for unofficial or academic purposes.
I agree with you: an official and validated MATLAB implementation of this functionality would be great!

Just a clarification for Kamlesh: maybe you've already suceeded in making it work, but if not... see below!
The instructions that LB gave us are corrected, but the following oversight:
in the dicom_encode_jpeg_lossy.m file, also del line fragments{1}=..... need to be changed in order to take into account the p parameter.
See below.

frames = size(X,4);
for p = 1:frames
tempfile = tempname;
imwrite(X(:,:,:,p), tempfile, 'jpeg');
.....

fragments{p} = fread(fid, inf, 'uint8=>uint8');
%fragments{1} = fread(fid, inf, 'uint8=>uint8');


%frames = 1;
.....
end

Hoping this helps!
Thank you guys!
Best regards,
Sara.

"K P" <kamleshp...@gmail.com> wrote in message <ig2dh1$np7$1...@fred.mathworks.com>...

Lead Bucket

unread,
Jan 26, 2011, 12:45:05 PM1/26/11
to

> Just a clarification for Kamlesh: maybe you've already suceeded in making it work, but if not... see below!
> The instructions that LB gave us are corrected, but the following oversight:
> in the dicom_encode_jpeg_lossy.m file, also del line fragments{1}=..... need to be changed in order to take into account the p parameter.
> See below.
>
> frames = size(X,4);
> for p = 1:frames
> tempfile = tempname;
> imwrite(X(:,:,:,p), tempfile, 'jpeg');
> .....
> fragments{p} = fread(fid, inf, 'uint8=>uint8');
> %fragments{1} = fread(fid, inf, 'uint8=>uint8');
> %frames = 1;
> .....
> end
>

Thanks for the correcting my oversight Sara! Kamlesh, I think that should solve your problem. Sorry about the omission.

-LB

Patrick

unread,
May 19, 2011, 5:50:07 PM5/19/11
to
I have gotten these modifications to work for me ... i would appear you need a multiframe dicom image to use as "template" in order for it to work. Read in the metadata from the template using dicominfo, then pass the metadata when you use dicomwrite with the 'CreateMode', 'copy' paramaeter as Lead Bucket suggests.

At least when I read this back in from MATLAB dicomread, this works and returns an 4 D arrray with my image data. The NEMA reader I have is complaining about not supporting jpeg.

If I don't do this, it won't work ... reading the file back in results in only a single frame and the NumberOfFrames field is missing from dicominfo. There may be a way to add the 'NumberOfFrames' field to the metadata, so you don't need a template file, but not sure if I have the time to bother with that.

Patrick

unread,
May 19, 2011, 6:05:05 PM5/19/11
to
Looks like I spoke to soon, it is giving me back an array of the correct dimensions, but the data is junk... *sigh*

Yao

unread,
Jul 5, 2011, 10:44:12 PM7/5/11
to
"Patrick " <prap...@gmail.com> wrote in message <ir446h$nb4$1...@newscl01ah.mathworks.com>...

> Looks like I spoke to soon, it is giving me back an array of the correct dimensions, but the data is junk... *sigh*

Hello everyone, are you still working on this function?

I guess I kind of succeeded in the first part where I got a 1xp cell named fragments. Then I followed the instructions on dicomwrite modification and stopped with the following error reported:

Undefined function or method 'dicom_create_IOD' for input arguments of type 'cell'.

Can anybody tell me what I should do next? Is there anything wrong with my program? If not, how can I convert cell to dcm (or other formats recognizable)?

many thanks!

ZZ

Lead Bucket

unread,
Jul 8, 2011, 8:26:09 PM7/8/11
to
"Patrick " <prap...@gmail.com> wrote in message <ir43af$kr9$1...@newscl01ah.mathworks.com>...

> I have gotten these modifications to work for me ... i would appear you need a multiframe dicom image to use as "template" in order for it to work. Read in the metadata from the template using dicominfo, then pass the metadata when you use dicomwrite with the 'CreateMode', 'copy' paramaeter as Lead Bucket suggests.
>
> At least when I read this back in from MATLAB dicomread, this works and returns an 4 D arrray with my image data. The NEMA reader I have is complaining about not supporting jpeg.
>
> If I don't do this, it won't work ... reading the file back in results in only a single frame and the NumberOfFrames field is missing from dicominfo. There may be a way to add the 'NumberOfFrames' field to the metadata, so you don't need a template file, but not sure if I have the time to bother with that.

Patrick, I'm not sure why NumberOfFrames is missing from dicominfo, mine seems to be retained. However, I do recall that I had an issue with dicomread when it tried to read multiframe dicom file and the dicom data did not contain an offset table. I think I mentioned this somewhere in another thread, but the basic problem was that dicomread looks for an offset table, and if none exists it assumes that there is only one image and just loads the first frame (it completely disregards NumberOfFrames).

I believe that no offset table is produced for the modifications I provided to dicomwrite, so the same problem may persist when you try to use dicomread. I've had to modify dicomread so that it uses NumberOfFrames to read in the frames. That will probably be an issue if NumberOfFrames doesn't exist for you. Perhaps your data is coming out junk due to one of these issues, but I'm really not that familiar with dicom data formats.

As for your NEMA reader, I am unfamiliar with that (I don't really know much about dicom files/formats either - its not my area of expertise), but I do recall that ImageJ has an issue with compressed JPEG in dicom files. Maybe its the same thing with your NEMA reader.

Yao - The issue might be that you are using the 'Create' option for 'CreateMode' (this is the default, by the way, if you don't specify 'Copy'). I always needed to use the 'Copy' option because Matlab does not support the data type I was working with (which was ultrasound data). I do get a few warnings about some of the attributes being wrong in the dicom info, but for my work I don't really need the dicom info, so its not an issue for me.

-LB

Jaroslav

unread,
Jun 1, 2012, 6:50:12 AM6/1/12
to
"Lead Bucket" wrote in message <iv8771$i9m$1...@newscl01ah.mathworks.com>...
I would like to ask, if this all is possible also for writing without compression. Better said, what kind of modifications and where should be made to enable this.
Thank you very much.

Lead Bucket

unread,
Jul 9, 2012, 5:19:08 PM7/9/12
to

> I would like to ask, if this all is possible also for writing without compression. Better said, what kind of modifications and where should be made to enable this.
> Thank you very much.

It is possible. Either direct your program to use dicom_encode_jpeg_lossless or modify the function to use whatever lossless encoder you wish (with the modifications for multiframe writes, of course!). This function just uses imwrite to created the dicom image data, and you can (probably) use any of the available formats under imwrite. I do not know, however, if you will violate any dicom standards by using the other encoders.

-LB
0 new messages