[vtkusers] READING RAW FILE

Gomez, Alberto alberto.gomez at kcl.ac.uk
Thu Feb 25 05:16:54 EST 2010


Hi,

1) There is a metaImage reading method in VTK as well, but I have never 
used it.
2) I do not know how data is stored but I believe that it is compressed 
binary format (i.e. you can not just read the .raw file as if it was a 
text file containing the voxel values).

Give a look to this wiki though:

http://www.itk.org/Wiki/MetaIO

Here you will find a lot of useful information about MetaImage, 
including the differences between VTK and ITK.

Also, I just found the doc for vtkMetaImageReader

http://www.vtk.org/doc/release/5.4/html/a01038.html

If you look here, you find the same I told you before: you need a mhd file.

For what I know of vtk, you should use it this way:

vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();

reader->SetFileName(filename);

vtkSmartPointer<vtkImageData> vtkImage = 
vtkSmartPointer<vtkImageData>::New();

reader->Update();

vtkImage = reader->GetOutput();

Hope this helps

nikhil singhania wrote:
> Thanks a lot Mr. Gomez,
> considering your approach, I have another question in mind, We have
> done all configuration for vtk , now at the mid point using itk, which
> we have not used till now, I don't know much of itk, since i used vtk
> for most purpose, there must be similar object in vtk too. The
> filereading i did for a sample data "HeadMRVolume.raw", where my input
> was just the raw file and not the .mhd file. Anyway my question is
> that can we do it in vtk only.
> And sir by any chance do you know how is data stored in the raw file
> so that we can write a code to read it, i mean like x,y cordinated
> stored for one slice then next slice like that or what..? This
> question has been bugging my mind for so long.
>
> On 24/02/2010, Gomez, Alberto <alberto.gomez at kcl.ac.uk> wrote:
>   
>> Hi,
>>
>> my advice is that if you do not have the mhd file, but you have all the
>> information, then generate it yourself. Mhd files are text files that
>> have this shape (for example):
>>
>> ObjectType = Image
>> NDims = 3
>> BinaryData = True
>> BinaryDataByteOrderMSB = False
>> CompressedData = False
>> TransformMatrix = 1 0 0 0 1 0 0 0 1
>> Offset = 0.0 0.0 0.0
>> CenterOfRotation = 0 0 0
>> AnatomicalOrientation = RAI
>> ElementSpacing = 1 1 1
>> DimSize = 200 180 160
>> ElementNumberOfChannels = 4
>> ElementType = MET_FLOAT
>> ElementDataFile = filename.raw
>>
>> Then, you can open it easily. I read it with ITK (itkFileReader supports
>> this format), store it into an itkImage object and I have full acces to
>> voxel data. Then you can do downsampling and finally  you can convert it
>> to VTK and visualise it, I believe you want to do some processing on it
>> before visualisation, so opening it with ITK looks a reasonable approach
>> to me. You can also open it with a viewer supporting mhd format (like
>> ImageJ + 3D IO plugin), but You will quickly run out of memory.
>>
>>
>>
>>
>> nikhil singhania wrote:
>>     
>>> I agree with you there is .mhd file containing all that, but working
>>> with larger data of human male 3.5 gb, i do not have the .mhd file but
>>> i have all the information but still , since we don't know how is data
>>> stored in raw file, i am not able to extract the desired data from raw
>>> file. I am not visualizing directly but i have to visualize after some
>>> sampling because for such a large data it's not possible..
>>>
>>> On 24/02/2010, Gomez, Alberto <alberto.gomez at kcl.ac.uk> wrote:
>>>
>>>       
>>>> A .raw typically comes together with another file, for example a .mhd
>>>> file. This is the file you have to open. It contains information like
>>>> the spacing, the size, etc, and a link to the .raw file. I am not sure
>>>> if this is always this way though...
>>>>
>>>> good luck
>>>>
>>>> nikhil singhania wrote:
>>>>
>>>>         
>>>>> hi all,
>>>>> We are trying to read a .raw file. It's a single 3d file. We are
>>>>> unaware of its structure so we are not able to apply any aglorithm. We
>>>>> want to get the voxel information and output that to a text file.
>>>>> Please help us if there is any such information.
>>>>>
>>>>>
>>>>>           
>>>> --
>>>>
>>>> Alberto Gómez
>>>>
>>>> /Division of Imaging Sciences
>>>> The Rayne Institute
>>>> 4th Floor, Lambeth Wing
>>>> St Thomas' Hospital
>>>> London SE1 7EH /
>>>>
>>>> phone: +44 (0) 20 718 88364
>>>> email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> --
>>
>> Alberto Gómez
>>
>> /Division of Imaging Sciences
>> The Rayne Institute
>> 4th Floor, Lambeth Wing
>> St Thomas' Hospital
>> London SE1 7EH /
>>
>> phone: +44 (0) 20 718 88364
>> email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>
>>
>>
>>     
>
>
>   


-- 

Alberto Gómez

/Division of Imaging Sciences
The Rayne Institute
4th Floor, Lambeth Wing
St Thomas' Hospital
London SE1 7EH /

phone: +44 (0) 20 718 88364
email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>




More information about the vtkusers mailing list