[Insight-users] C++ question
karthik.krishnan at kitware.com
Wed Sep 24 11:47:36 EDT 2008
You could read the image with the itk::ImageFileReader class in two
passes. In the first pass, just read the headers. In the second pass,
read everything including the bulk data.
itk::ImageFileReader< itk::Image< double, 3 > > DummyReaderType;
DummyReaderType::Pointer reader = DummyReaderType::New();
pixelComponentType = reader->GetImageIO()->GetComponentType(); //
assuming one component per pixel.
switch( pixelType )
typedef itk::Image< char, 3 > ImageType;
itk::ImageFileReader< itk::Image< char, 3 > > ReaderType;
ReaderType::Pointer bulkReader = ReaderType::New();
ImageType::Pointer image = reader->GetOutput();
MyTemplatedClass<signed char> runner;
runner.Execute(); // do stuff with image
Take a look at InsightApplications/VolViewPlugins/vtkITK*.cxx for
example . We instantiate all possible pixel types. We have to do this
since pixeltypes in VTK are specified at run-time, while in ITK are a
compile time choice.. A similar thing is done in Slicer.
On Wed, Sep 24, 2008 at 11:23 AM, Luke Bloy <luke.bloy at gmail.com> wrote:
> I was worried that would be the answer.
> How do you guys handle reading image files? is there a way to probe a file
> to figure out its Pixeltype / dimension? This would be useful for apps that
> want to work in the native format of the image that is being read.
> Karthik Krishnan wrote:
>> On Wed, Sep 24, 2008 at 10:55 AM, Luke Bloy <luke.bloy at gmail.com> wrote:
>>> Hi All,
>>> I'm not, by a long shot, a c++ guru so i have perhaps a pretty basic
>>> I'd like to be able to do something like this...
>>> int main(int argc, char** argv)
>>> typedef double
>>> unsigned int dimension = 4;
>>> typedef itk::Image<PixelType, dimension> ImageType;
>>> This won't compile because dimension isn't const. Ideally i'd like this
>>> be passed in as a command line argument. Is there a way to get around the
>> Nope. templates have to be instantiated at compile time, not at run time.
>> To get the behaviour you desire, what we tend to do is to instantiate
>> all possible templates and choose the right template at run-time,
>> something like
>> switch (dimension)
>> case 3:
>> typedef itk::Image<PixelType, 3> ImageType;
>> // do stuff
>> case 2:
>> typedef itk::Image<PixelType, 2> ImageType;
>> // do stuff
>>> Thanks for any help.
>>> Insight-users mailing list
>>> Insight-users at itk.org
Ph: 518 371 3971 x119
Fax: 518 371 3971
More information about the Insight-users