<div dir="ltr">{<br>    typedef unsigned short PixelType;<br>    typedef itk::Image<PixelType, 2> ImageType;<br>    auto reader = itk::ImageFileReader<<div dir="ltr">ImageType>::New();<br>    reader->SetFileName("D:/TestData/input/input.tif");<br>

    reader->SetImageIO(itk::TIFFImageIO::New());<br><br>    typedef unsigned short OutputPixelType;<br>    typedef itk::Image<OutputPixelType, 2> OutputImageType;<br><br>    auto writer = itk::ImageFileWriter<OutputImageType>::New();<br>

    writer->SetFileName("D:/TestData/output/ushort_to_ushort.tif");<br>    auto image_io = itk::TIFFImageIO::New();<br>    image_io->SetPixelType(itk::ImageIOBase::SCALAR);<br>    writer->SetImageIO(image_io);<br>

    writer->SetInput(reader->GetOutput());<br>    writer->Update(); //produces completely black<br>    }<br>  <br>    {<br>    typedef itk::RGBAPixel<char> PixelType;<br>    typedef itk::Image<PixelType, 2> ImageType;<br>

    auto reader = itk::ImageFileReader<ImageType>::New();<br>    reader->SetFileName("D:/TestData/input/input.tif");<br>    reader->SetImageIO(itk::TIFFImageIO::New());<br>    reader->Update();<br>

<br>    typedef unsigned short OutputPixelType;<br>    typedef itk::Image<OutputPixelType, 2> OutputImageType;<br><br>    auto input_image = reader->GetOutput();<br>    auto output_image = OutputImageType::New();<br>

    output_image->CopyInformation(input_image);<br>    output_image->SetRegions(input_image->GetLargestPossibleRegion());<br>    output_image->Allocate();<br>    itk::ImageRegionConstIterator<ImageType> const_iterator(input_image, input_image->GetLargestPossibleRegion());<br>

    itk::ImageRegionIterator<OutputImageType> rescaled_iterator(output_image, output_image->GetLargestPossibleRegion());<br>   
 for (const_iterator.GoToBegin(), rescaled_iterator.GoToBegin(); 
!const_iterator.IsAtEnd(); ++const_iterator, ++rescaled_iterator)<br>
      {<br>      const PixelType& pixel = const_iterator.Get();<br>      rescaled_iterator.Set(((pixel.GetAlpha() * 16 + pixel.GetRed()) * 16 + pixel.GetGreen()) * 16 + pixel.GetBlue());<br>      }<br><br>    auto writer = itk::ImageFileWriter<OutputImageType>::New();<br>

    writer->SetFileName("D:/TestData/output/rgba_char_to_ushort.tif");<br>    auto image_io = itk::TIFFImageIO::New();<br>    image_io->SetPixelType(itk::ImageIOBase::SCALAR);<br>    writer->SetImageIO(image_io);<br>

    writer->SetInput(output_image);<br>    writer->Update(); //output looks the same<br>    }</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-08-13 20:50 GMT+03:00 Matt McCormick <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Marian,<br>
<br>
If<br>
<br>
  itk::Image< unsigned  short, 2 ><br>
<br>
is used for the ImageType, does it work (note the dimension specification).<br>
<br>
HTH,<br>
Matt<br>
<div><div class="h5"><br>
On Wed, Aug 13, 2014 at 1:47 PM, Мар'ян Климов <<a href="mailto:nekto1989@gmail.com">nekto1989@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> How to properly read 32-bit TIFF? I need to get itk::Image<unsigned short><br>
> on output. If I use it as ImageType for ImageFileReader, it is read as fully<br>
> black (checked contrast with Image Watch and it is for sure completely<br>
> empty). If I read it with pixel type RGBPixel<unsigned char> or<br>
> RGBAPixel<unsigned char>, it is read properly. But I need to convert it<br>
> manually to unsigned short after this. So what is the proper way of reading<br>
> it? Do I need to create templated methods for every pixeltype with<br>
> conversions to unsigned short?<br>
><br>
> Best regards,<br>
> Marian<br>
><br>
</div></div>> _______________________________________________<br>
> Community mailing list<br>
> <a href="mailto:Community@itk.org">Community@itk.org</a><br>
> <a href="http://public.kitware.com/mailman/listinfo/community" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br>
><br>
</blockquote></div><br></div>