Thread Subject:
Created raw file cannot be read

Subject: Created raw file cannot be read

From: Siti_Mustaqim

Date: 5 Jul, 2012 00:56:55

Message: 1 of 6

Hi,
I have problem in creating raw file for image matlab file. I have CT image which has been sampled to 168x168x72 double and I would like to use elastix/ITK for registration. I convert them to raw file as follows:

fid=fopen('CTdata.raw','w+');
fwrite(fid,CTdata,'double');

Then CTdata.raw is created in my existing path. I take a 'mhd' file somewhere, delete the contents and put the information related to my data and save as CTdata.mhd.

Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be read. I also tried elastix toolbox yet failed.

Is my way correct? Can someone please advise?

Thank you.

Subject: Created raw file cannot be read

From: dpb

Date: 5 Jul, 2012 13:30:07

Message: 2 of 6

On 7/4/2012 7:56 PM, Siti_Mustaqim wrote:
> Hi,
> I have problem in creating raw file for image matlab file. I have CT
> image which has been sampled to 168x168x72 double and I would like
> touse elastix/ITK for registration. I convert them to raw file as follows:
>
> fid=fopen('CTdata.raw','w+');
> fwrite(fid,CTdata,'double');
>
> Then CTdata.raw is created in my existing path. I take a 'mhd' file
> somewhere, delete the contents and put the information related to my
> data and save as CTdata.mhd.
>
> Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be
> read.I also tried elastix toolbox yet failed.
>
> Is my way correct? Can someone please advise?

I've no clue about "mha_read_volume" but it appears you're confusing
that somehow the extension on a file has any bearing on it's content.

If you wrote the file w/ fwrite() and then just (in effect) renamed it
by the machinations to a file w/ another extension, it's still the same
stream file fwrite() wrote.

So, read it back w/ fread()

fid=fopen('CTdata.mhd','r');
x=fread(fid);
fid=fclose(fid);
x=reshape(x,168,168,72);

If you're trying to create a file in some other specific format you'll
have to write out whatever that format is specifically either from
knowing it and writing the pieces-parts w/ a combination of fwrite()
calls of the appropriate form/info or find some utility that does so. I
have no knowledge of what a 'mhd' file might be...

--

Subject: Created raw file cannot be read

From: Siti_Mustaqim

Date: 5 Jul, 2012 15:30:28

Message: 3 of 6


Thank you for your reply,
Actually I follow the instruction in this link;

http://www.itk.org/pipermail/insight-users/2007-November/024337.html


mhd image and raw file is for medical images. I want to use them for ITK appication which is new to me.

Thanks again.



On Thursday, 5 July 2012 21:30:07 UTC+8, dpb wrote:
> On 7/4/2012 7:56 PM, Siti_Mustaqim wrote:
> > Hi,
> > I have problem in creating raw file for image matlab file. I have CT
> > image which has been sampled to 168x168x72 double and I would like
> > touse elastix/ITK for registration. I convert them to raw file as follows:
> >
> > fid=fopen('CTdata.raw','w+');
> > fwrite(fid,CTdata,'double');
> >
> > Then CTdata.raw is created in my existing path. I take a 'mhd' file
> > somewhere, delete the contents and put the information related to my
> > data and save as CTdata.mhd.
> >
> > Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be
> > read.I also tried elastix toolbox yet failed.
> >
> > Is my way correct? Can someone please advise?
>
> I've no clue about "mha_read_volume" but it appears you're confusing
> that somehow the extension on a file has any bearing on it's content.
>
> If you wrote the file w/ fwrite() and then just (in effect) renamed it
> by the machinations to a file w/ another extension, it's still the same
> stream file fwrite() wrote.
>
> So, read it back w/ fread()
>
> fid=fopen('CTdata.mhd','r');
> x=fread(fid);
> fid=fclose(fid);
> x=reshape(x,168,168,72);
>
> If you're trying to create a file in some other specific format you'll
> have to write out whatever that format is specifically either from
> knowing it and writing the pieces-parts w/ a combination of fwrite()
> calls of the appropriate form/info or find some utility that does so. I
> have no knowledge of what a 'mhd' file might be...
>
> --

Subject: Created raw file cannot be read

From: dpb

Date: 5 Jul, 2012 15:42:26

Message: 4 of 6

On 7/5/2012 10:30 AM, Siti_Mustaqim wrote:

...[top posting repaired. Please don't do that--hard follow
conversation makes]...

> On Thursday, 5 July 2012 21:30:07 UTC+8, dpb wrote:
>> On 7/4/2012 7:56 PM, Siti_Mustaqim wrote:
>>> Hi,
>>> I have problem in creating raw file for image matlab file. I have CT
>>> image which has been sampled to 168x168x72 double and I would like
>>> touse elastix/ITK for registration. I convert them to raw file as follows:
>>>
>>> fid=fopen('CTdata.raw','w+');
>>> fwrite(fid,CTdata,'double');
>>>
>>> Then CTdata.raw is created in my existing path. I take a 'mhd' file
>>> somewhere, delete the contents and put the information related to my
>>> data and save as CTdata.mhd.
>>>
>>> Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be
>>> read.I also tried elastix toolbox yet failed.
>>>
>>> Is my way correct? Can someone please advise?
...
 > Thank you for your reply,
 > Actually I follow the instruction in this link;
 >
 > http://www.itk.org/pipermail/insight-users/2007-November/024337.html
 >
 >
 > mhd image and raw file is for medical images. I want to use them for
ITK appication which is new to me.
...

 From you description, it sounded like you simply copied the image data
into the other file; you didn't show/say anything about writing a header
so there's no way to know what may be the problem.

It could be you didn't format the header-file information correctly or
something else.

Did you look at the content of the created .mhd file? Does it appear to
follow the correct form? What kind of an error message, if any, did you
get trying to load it?

The crystal ball doesn't have much to go on here...

--

Subject: Created raw file cannot be read

From: Siti_Mustaqim

Date: 5 Jul, 2012 16:33:55

Message: 5 of 6

I have overlooked the responses in the cited ITK discussion, there is a matlab file to convert mat to mhd;

http://old.nabble.com/How-to-read-.Mat-File-using-ITK-%2B-C%2B%2B-td30402760.html

by:

-----------------
Jean-Pierre Roux
CNRS UMR 5220, INSERM U1440

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Then after editing the mha_read_volume; I can get the image back in mat from created mhd and raw files; In the mha_read_volume function; it implements this command;

datasize=prod(info.Dimensions)*info.BitDepth/8;

where my mhd file generated BitDepth=0 causing the datasize to be 0; and fail to create the matrix. Many thanks to both of them Dr. Roux and Dr. Dirk-Jan.



On Thursday, 5 July 2012 23:30:28 UTC+8, Siti_Mustaqim wrote:
> Thank you for your reply,
> Actually I follow the instruction in this link;
>
> http://www.itk.org/pipermail/insight-users/2007-November/024337.html
>
>
> mhd image and raw file is for medical images. I want to use them for ITK appication which is new to me.
>
> Thanks again.
>
>
>
> On Thursday, 5 July 2012 21:30:07 UTC+8, dpb wrote:
> > On 7/4/2012 7:56 PM, Siti_Mustaqim wrote:
> > > Hi,
> > > I have problem in creating raw file for image matlab file. I have CT
> > > image which has been sampled to 168x168x72 double and I would like
> > > touse elastix/ITK for registration. I convert them to raw file as follows:
> > >
> > > fid=fopen('CTdata.raw','w+');
> > > fwrite(fid,CTdata,'double');
> > >
> > > Then CTdata.raw is created in my existing path. I take a 'mhd' file
> > > somewhere, delete the contents and put the information related to my
> > > data and save as CTdata.mhd.
> > >
> > > Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be
> > > read.I also tried elastix toolbox yet failed.
> > >
> > > Is my way correct? Can someone please advise?
> >
> > I've no clue about "mha_read_volume" but it appears you're confusing
> > that somehow the extension on a file has any bearing on it's content.
> >
> > If you wrote the file w/ fwrite() and then just (in effect) renamed it
> > by the machinations to a file w/ another extension, it's still the same
> > stream file fwrite() wrote.
> >
> > So, read it back w/ fread()
> >
> > fid=fopen('CTdata.mhd','r');
> > x=fread(fid);
> > fid=fclose(fid);
> > x=reshape(x,168,168,72);
> >
> > If you're trying to create a file in some other specific format you'll
> > have to write out whatever that format is specifically either from
> > knowing it and writing the pieces-parts w/ a combination of fwrite()
> > calls of the appropriate form/info or find some utility that does so. I
> > have no knowledge of what a 'mhd' file might be...
> >
> > --

Subject: Created raw file cannot be read

From: Siti_Mustaqim

Date: 5 Jul, 2012 16:42:42

Message: 6 of 6


Many thanks to you too DBP :).



On Friday, 6 July 2012 00:33:55 UTC+8, Siti_Mustaqim wrote:
> I have overlooked the responses in the cited ITK discussion, there is a matlab file to convert mat to mhd;
>
> http://old.nabble.com/How-to-read-.Mat-File-using-ITK-%2B-C%2B%2B-td30402760.html
>
> by:
>
> -----------------
> Jean-Pierre Roux
> CNRS UMR 5220, INSERM U1440
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> Then after editing the mha_read_volume; I can get the image back in mat from created mhd and raw files; In the mha_read_volume function; it implements this command;
>
> datasize=prod(info.Dimensions)*info.BitDepth/8;
>
> where my mhd file generated BitDepth=0 causing the datasize to be 0; and fail to create the matrix. Many thanks to both of them Dr. Roux and Dr. Dirk-Jan.
>
>
>
> On Thursday, 5 July 2012 23:30:28 UTC+8, Siti_Mustaqim wrote:
> > Thank you for your reply,
> > Actually I follow the instruction in this link;
> >
> > http://www.itk.org/pipermail/insight-users/2007-November/024337.html
> >
> >
> > mhd image and raw file is for medical images. I want to use them for ITK appication which is new to me.
> >
> > Thanks again.
> >
> >
> >
> > On Thursday, 5 July 2012 21:30:07 UTC+8, dpb wrote:
> > > On 7/4/2012 7:56 PM, Siti_Mustaqim wrote:
> > > > Hi,
> > > > I have problem in creating raw file for image matlab file. I have CT
> > > > image which has been sampled to 168x168x72 double and I would like
> > > > touse elastix/ITK for registration. I convert them to raw file as follows:
> > > >
> > > > fid=fopen('CTdata.raw','w+');
> > > > fwrite(fid,CTdata,'double');
> > > >
> > > > Then CTdata.raw is created in my existing path. I take a 'mhd' file
> > > > somewhere, delete the contents and put the information related to my
> > > > data and save as CTdata.mhd.
> > > >
> > > > Then I tried to use "mha_read_volume" by Dirk-Jan; it couldnt be
> > > > read.I also tried elastix toolbox yet failed.
> > > >
> > > > Is my way correct? Can someone please advise?
> > >
> > > I've no clue about "mha_read_volume" but it appears you're confusing
> > > that somehow the extension on a file has any bearing on it's content.
> > >
> > > If you wrote the file w/ fwrite() and then just (in effect) renamed it
> > > by the machinations to a file w/ another extension, it's still the same
> > > stream file fwrite() wrote.
> > >
> > > So, read it back w/ fread()
> > >
> > > fid=fopen('CTdata.mhd','r');
> > > x=fread(fid);
> > > fid=fclose(fid);
> > > x=reshape(x,168,168,72);
> > >
> > > If you're trying to create a file in some other specific format you'll
> > > have to write out whatever that format is specifically either from
> > > knowing it and writing the pieces-parts w/ a combination of fwrite()
> > > calls of the appropriate form/info or find some utility that does so. I
> > > have no knowledge of what a 'mhd' file might be...
> > >
> > > --

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us