Hi, mengqiu, <br><br>try to change the image dimension to 3.<br><br>const unsigned int Dimension = 3;<br><br><br>wanlin<br><br><div class="gmail_quote">On Wed, Jul 6, 2011 at 11:16 PM, Mengqiu Tian <span dir="ltr"><<a href="mailto:tianmengqiu@gmail.com">tianmengqiu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br><br>I have a question.<br><br>I have a raw image which contains 125 frames. <br>
The mhd file as follows:<br><br>
         NDims = 3<br>DimSize = 512 512 125<br>ElementSpacing = 0.333 0.333 0.333<br>Position = 0 0 0<br>ElementByteOrderMSB = False<br>ElementNumberOfChannels = 1<br>ElementType = MET_SHORT<br>ElementDataFile = ctA0-512x512x125x16.raw<br>
<br>I could read it and then write all frames to another image 'test.raw' by using RawImageIO class.<br>How could I realize it with MetaImageIO class? My program as follows, and I added a filter which mulitply the image by a constant 100. However, I could filter only the first frame and write it to test.raw<br>
<br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkMetaImageIO.h"<br>#include "itkWeightedImageFilter.h"<br>int main( int argc, char ** argv)<br>
{<br> typedef unsigned short PixelType;<br> const unsigned int Dimension = 2;<br> typedef itk::Image< PixelType, Dimension > ImageType;<br> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
typedef itk::MetaImageIO ImageIOType;<br> <br> const char * inputFilename = "ctA0-512x512x125x16.mhd";<br> const char * outputFilename = "test.mhd";<br> const short weight = 100;<br>
<br> ReaderType::Pointer reader = ReaderType::New();<br> ImageIOType::Pointer metaIn = ImageIOType::New();<br><br> reader->SetFileName( inputFilename );<br> reader->SetImageIO(metaIn);<br> reader->Update();<br>
<br> typedef itk::WeightedImageFilter<ImageType, ImageType> FilterType;<br>
FilterType::Pointer filter = FilterType::New();<br><br> filter->SetInput( reader ->GetOutput());<br> filter->SetWeight(weight);<br> filter->Update();<br><br> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br> ImageIOType::Pointer metaOut = ImageIOType::New();<br><br> writer->SetImageIO( metaOut );<br> writer->SetFileName( outputFilename );<br> writer->SetInput( filter->GetOutput() );<br>
writer->Update();<br> <br> return EXIT_SUCCESS;<br>}<br> <br><br><br><br><br>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br>