[Insight-users] C++ question
Karthik Krishnan
karthik.krishnan at kitware.com
Wed Sep 24 11:47:36 EDT 2008
Yes..
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.
//pass 1:
itk::ImageFileReader< itk::Image< double, 3 > > DummyReaderType;
DummyReaderType::Pointer reader = DummyReaderType::New();
reader->GenerateOutputInformation();
pixelComponentType = reader->GetImageIO()->GetComponentType(); //
assuming one component per pixel.
switch( pixelType )
{
case itk::ImageIOBase::CHAR:
{
typedef itk::Image< char, 3 > ImageType;
itk::ImageFileReader< itk::Image< char, 3 > > ReaderType;
ReaderType::Pointer bulkReader = ReaderType::New();
reader->Update();
ImageType::Pointer image = reader->GetOutput();
MyTemplatedClass<signed char> runner;
runner.Execute(); // do stuff with image
break;
}
case itk::ImageIOBase::UCHAR:
{
....
}
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.
>
> -Luke
>
> 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
>>> question.
>>>
>>> I'd like to be able to do something like this...
>>>
>>> int main(int argc, char** argv)
>>> {
>>> typedef double
>>> PixelType;
>>> unsigned int dimension = 4;
>>>
>>> typedef itk::Image<PixelType, dimension> ImageType;
>>> }
>>>
>>> This won't compile because dimension isn't const. Ideally i'd like this
>>> to
>>> be passed in as a command line argument. Is there a way to get around the
>>> typedef?
>>>
>>
>> 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.
>>> -Luke
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>>
>>
>>
>>
>
--
Karthik Krishnan
R&D Engineer,
Kitware Inc.
Ph: 518 371 3971 x119
Fax: 518 371 3971
More information about the Insight-users
mailing list