[Insight-users] how to convert the pixeltype of a image

Siavash khallaghi siavashk at ece.ubc.ca
Tue Sep 3 02:28:36 EDT 2013


You know you can always cast the pixel type to match your needs, so 
something like this would work:

//Read image
typedef itk::Image< short, 2 >         InputImageType;
typedef itk::ImageFileReader<InputImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( "filename.tiff" );
reader->Update();

//Cast it
typedef itk::Image< double, 2> InternalImageType
typedef itk::CastImageFilter< InputImageType, InternalImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput( reader->GetOutput() );
filter->Update();

and you can grab your casted image by calling filter->GetOutput();


Siavash

On 9/2/2013 8:04 PM, Bill Lorensen wrote:
> You cannot write a float TIFF. Is that what you are trying?
>
>
> On Mon, Sep 2, 2013 at 9:35 PM, shiwei <swingsw89 at 163.com> wrote:
>> Tanks for your answer!However when I did what you have told, it still have
>> some problem below:
>>
>> itk::ExceptionObject<0031e508>
>>
>> Description:itk::Error:TIFFimageIO:TIFF supports unsigned/signed
>> char,unsigned short/signed short only.
>>
>> As I said before, I want to use some tiff images ,however  TIFF support
>> unsigned/signed char,unsigned short/signed short only, so I'm still asking
>> if there is a way to convert the uchar or ushort type to double for delica
>> use? Thank you!
>>
>>
>>
>> At 2013-09-02 20:09:33,"Bill Lorensen" <bill.lorensen at gmail.com> wrote:
>>> When you define your read, just template it over the image type you
>>> want the reader to produce.
>>> typedef itk::Image< double, 2 >         ImageType;
>>> typedef itk::ImageFileReader<ImageType> ReaderType;
>>> ReaderType::Pointer reader = ReaderType::New();
>>>
>>>
>>> On Sun, Sep 1, 2013 at 10:41 PM, shiwei <swingsw89 at 163.com> wrote:
>>>> Hi, When I was dealing with some tiff images, it only have two kinds of
>>>> pixeltype to choose: char and short. However,I need to convert the
>>>> pixeltype
>>>> to double for delica use, I'm wondering whether ITK has a way to convert
>>>> the
>>>> pixeltype to double? Thank you!
>>>>
>>>>
>>>>
>>>> _____________________________________
>>>> 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.php
>>>>
>>>> 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
>>>>
>>>
>>>
>>> --
>>> Unpaid intern in BillsBasement at noware dot com
>>
>>
>
>



More information about the Insight-users mailing list