[Insight-users] Pad image with 0 but keep its type what ever it is
Bill Lorensen
bill.lorensen at gmail.com
Sun Jan 31 10:53:19 EST 2010
You can use itk to determine the pixel type of a file. We do this all
of the time in Slicer3. Here is a snippet of code:
namespace itk
{
// Description:
// Get the PixelType and ComponentType from fileName
void GetImageType (std::string fileName,
ImageIOBase::IOPixelType &pixelType,
ImageIOBase::IOComponentType &componentType)
{
typedef itk::Image<unsigned char, 3> ImageType;
itk::ImageFileReader<ImageType>::Pointer imageReader =
itk::ImageFileReader<ImageType>::New();
imageReader->SetFileName(fileName.c_str());
imageReader->UpdateOutputInformation();
pixelType = imageReader->GetImageIO()->GetPixelType();
componentType = imageReader->GetImageIO()->GetComponentType();
}
}
Here is a sample use:
int main( int argc, char * argv[] )
{
PARSE_ARGS;
itk::ImageIOBase::IOPixelType pixelType;
itk::ImageIOBase::IOComponentType componentType;
try
{
itk::GetImageType (inputVolume1, pixelType, componentType);
switch (componentType)
{
case itk::ImageIOBase::UCHAR:
return DoIt( argc, argv, static_cast<unsigned char>(0));
break;
case itk::ImageIOBase::CHAR:
return DoIt( argc, argv, static_cast<char>(0));
break;
case itk::ImageIOBase::USHORT:
return DoIt( argc, argv, static_cast<unsigned short>(0));
break;
case itk::ImageIOBase::SHORT:
return DoIt( argc, argv, static_cast<short>(0));
break;
case itk::ImageIOBase::UINT:
return DoIt( argc, argv, static_cast<unsigned int>(0));
break;
case itk::ImageIOBase::INT:
return DoIt( argc, argv, static_cast<int>(0));
break;
case itk::ImageIOBase::ULONG:
return DoIt( argc, argv, static_cast<unsigned long>(0));
break;
case itk::ImageIOBase::LONG:
return DoIt( argc, argv, static_cast<long>(0));
break;
case itk::ImageIOBase::FLOAT:
return DoIt( argc, argv, static_cast<float>(0));
break;
case itk::ImageIOBase::DOUBLE:
return DoIt( argc, argv, static_cast<double>(0));
break;
case itk::ImageIOBase::UNKNOWNCOMPONENTTYPE:
default:
std::cout << "unknown component type" << std::endl;
break;
}
// This filter handles all types on input, but only produces
// signed types
}
catch( itk::ExceptionObject &excep)
{
std::cerr << argv[0] << ": exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
On Sat, Jan 30, 2010 at 8:27 AM, Mike Jackson
<mike.jackson at bluequartz.net> wrote:
> You could use C++ templates to instantiate the type of InputPixelType
> that you want which could be used as an input argument to the program.
> In Order to NOT have that type of argument you would need to be able
> to use NON-Itk classes to read part of the input image in order to
> determine what type of pixels are being used and then instantiate the
> correct type of output pixel type.
> _________________________________________________________
> Mike Jackson mike.jackson at bluequartz.net
>
> On Sat, Jan 30, 2010 at 5:32 AM, <lynx.abraxas at freenet.de> wrote:
>> On 28/01/10 17:00:57, Luis Ibanez wrote:
>>> Hi Lynx,
>>>
>>>
>>> What *exactly*
>>> is the problem that you are observing ?
>>>
>>
>> Thanks Luis for Your answer.
>> My main problem is that I'd like to create a single program to pad an input
>> image of arbitary InputPixelType with zeros. If I use my code it only works
>> for unsigned short InputPixelType. Is there a way to make my code work for any
>> InputPixelType? Or would I have to create many programs (eg pad_uc, pad_us,
>> pad_float...) where each single one is just for one InputPixelType?
>> Or asked differently: Is it possible to code the padding without having to
>> specify the InputPixelType?
>>
>> Thanks for any help or hint on this.
>> Lynx
>>
>>
>> _____________________________________
>> 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
>>
> _____________________________________
> 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
>
More information about the Insight-users
mailing list