[Insight-users] How could I filter the whole image
wanlin
wanlinzhu at gmail.com
Wed Jul 6 09:32:32 EDT 2011
Hi, mengqiu,
try to change the image dimension to 3.
const unsigned int Dimension = 3;
wanlin
On Wed, Jul 6, 2011 at 11:16 PM, Mengqiu Tian <tianmengqiu at gmail.com> wrote:
> Hi all,
>
> I have a question.
>
> I have a raw image which contains 125 frames.
> The mhd file as follows:
>
> NDims = 3
> DimSize = 512 512 125
> ElementSpacing = 0.333 0.333 0.333
> Position = 0 0 0
> ElementByteOrderMSB = False
> ElementNumberOfChannels = 1
> ElementType = MET_SHORT
> ElementDataFile = ctA0-512x512x125x16.raw
>
> I could read it and then write all frames to another image 'test.raw' by
> using RawImageIO class.
> 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
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkMetaImageIO.h"
> #include "itkWeightedImageFilter.h"
> int main( int argc, char ** argv)
> {
> typedef unsigned short PixelType;
> const unsigned int Dimension = 2;
> typedef itk::Image< PixelType, Dimension > ImageType;
> typedef itk::ImageFileReader< ImageType > ReaderType;
> typedef itk::MetaImageIO ImageIOType;
>
> const char * inputFilename = "ctA0-512x512x125x16.mhd";
> const char * outputFilename = "test.mhd";
> const short weight = 100;
>
> ReaderType::Pointer reader = ReaderType::New();
> ImageIOType::Pointer metaIn = ImageIOType::New();
>
> reader->SetFileName( inputFilename );
> reader->SetImageIO(metaIn);
> reader->Update();
>
> typedef itk::WeightedImageFilter<ImageType, ImageType> FilterType;
> FilterType::Pointer filter = FilterType::New();
>
> filter->SetInput( reader ->GetOutput());
> filter->SetWeight(weight);
> filter->Update();
>
> typedef itk::ImageFileWriter< ImageType > WriterType;
> WriterType::Pointer writer = WriterType::New();
> ImageIOType::Pointer metaOut = ImageIOType::New();
>
> writer->SetImageIO( metaOut );
> writer->SetFileName( outputFilename );
> writer->SetInput( filter->GetOutput() );
> writer->Update();
>
> return EXIT_SUCCESS;
> }
>
>
>
>
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110706/d11e6f9a/attachment-0001.htm>
More information about the Insight-users
mailing list