[ITK] Getting ImageType for TIFF

Matt McCormick matt.mccormick at kitware.com
Thu Aug 14 10:18:59 EDT 2014


Thanks for the nice example!


I have been able to reproduce the output.  If it is a bug, can the
given image be added to the repository as part of a unit test?

Thanks,
Matt

On Thu, Aug 14, 2014 at 9:51 AM, Мар'ян Климов <nekto1989 at gmail.com> wrote:
> Image Watch during debugging in Visual Studio.
> Windows Photo Viewer after results dumped to disk.
>
>
> 2014-08-14 15:35 GMT+03:00 Bill Lorensen <bill.lorensen at gmail.com>:
>
>> How are you displaying the unsigned short image? Many viewers cannot
>> properly display unsigned short.
>>
>> On Aug 14, 2014 7:23 AM, "Мар'ян Климов" <nekto1989 at gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I've tried different methods. Reading to RGBPixel<unsigned char>, then
>>> using RGBToLuminanceImageFilter and MultiplyImageFilter (2 ^ 8) produces the
>>> same visually proper image. Reading directly to <unsigned short, 2> fails.
>>> Looks like this is bug in TIFFImageIO and not in the way it is being called.
>>> http://itk-users.7.n7.nabble.com/TiffIO-strange-behaviour-td32215.html
>>>
>>> Marian
>>>
>>>
>>> 2014-08-13 23:55 GMT+03:00 Мар'ян Климов <nekto1989 at gmail.com>:
>>>>
>>>> Hi Matt,
>>>>
>>>> I hope this is proper cmakelists.txt. I'm used to using ITK connected
>>>> through *.props into Visual Studio solution.
>>>>
>>>> Best regards,
>>>> Marian
>>>>
>>>>
>>>>
>>>> 2014-08-13 22:52 GMT+03:00 Matt McCormick <matt.mccormick at kitware.com>:
>>>>
>>>>> Hi Marian,
>>>>>
>>>>> Thanks for the update.  Offhand, I am not seeing the issue.
>>>>>
>>>>> Could you please post a SSCCE [1], i.e. CMakeLists.txt, the code, and
>>>>> the input data?
>>>>>
>>>>> Thanks,
>>>>> Matt
>>>>>
>>>>> [1] http://sscce.org/
>>>>>
>>>>> On Wed, Aug 13, 2014 at 2:27 PM, Мар'ян Климов <nekto1989 at gmail.com>
>>>>> wrote:
>>>>> > {
>>>>> >     typedef unsigned short PixelType;
>>>>> >     typedef itk::Image<PixelType, 2> ImageType;
>>>>> >     auto reader = itk::ImageFileReader<
>>>>> > ImageType>::New();
>>>>> >     reader->SetFileName("D:/TestData/input/input.tif");
>>>>> >     reader->SetImageIO(itk::TIFFImageIO::New());
>>>>> >
>>>>> >     typedef unsigned short OutputPixelType;
>>>>> >     typedef itk::Image<OutputPixelType, 2> OutputImageType;
>>>>> >
>>>>> >     auto writer = itk::ImageFileWriter<OutputImageType>::New();
>>>>> >     writer->SetFileName("D:/TestData/output/ushort_to_ushort.tif");
>>>>> >     auto image_io = itk::TIFFImageIO::New();
>>>>> >     image_io->SetPixelType(itk::ImageIOBase::SCALAR);
>>>>> >     writer->SetImageIO(image_io);
>>>>> >     writer->SetInput(reader->GetOutput());
>>>>> >     writer->Update(); //produces completely black
>>>>> >     }
>>>>> >
>>>>> >     {
>>>>> >     typedef itk::RGBAPixel<char> PixelType;
>>>>> >     typedef itk::Image<PixelType, 2> ImageType;
>>>>> >     auto reader = itk::ImageFileReader<ImageType>::New();
>>>>> >     reader->SetFileName("D:/TestData/input/input.tif");
>>>>> >     reader->SetImageIO(itk::TIFFImageIO::New());
>>>>> >     reader->Update();
>>>>> >
>>>>> >     typedef unsigned short OutputPixelType;
>>>>> >     typedef itk::Image<OutputPixelType, 2> OutputImageType;
>>>>> >
>>>>> >     auto input_image = reader->GetOutput();
>>>>> >     auto output_image = OutputImageType::New();
>>>>> >     output_image->CopyInformation(input_image);
>>>>> >
>>>>> > output_image->SetRegions(input_image->GetLargestPossibleRegion());
>>>>> >     output_image->Allocate();
>>>>> >     itk::ImageRegionConstIterator<ImageType>
>>>>> > const_iterator(input_image,
>>>>> > input_image->GetLargestPossibleRegion());
>>>>> >     itk::ImageRegionIterator<OutputImageType>
>>>>> > rescaled_iterator(output_image,
>>>>> > output_image->GetLargestPossibleRegion());
>>>>> >     for (const_iterator.GoToBegin(), rescaled_iterator.GoToBegin();
>>>>> > !const_iterator.IsAtEnd(); ++const_iterator, ++rescaled_iterator)
>>>>> >       {
>>>>> >       const PixelType& pixel = const_iterator.Get();
>>>>> >       rescaled_iterator.Set(((pixel.GetAlpha() * 16 + pixel.GetRed())
>>>>> > * 16 +
>>>>> > pixel.GetGreen()) * 16 + pixel.GetBlue());
>>>>> >       }
>>>>> >
>>>>> >     auto writer = itk::ImageFileWriter<OutputImageType>::New();
>>>>> >
>>>>> > writer->SetFileName("D:/TestData/output/rgba_char_to_ushort.tif");
>>>>> >     auto image_io = itk::TIFFImageIO::New();
>>>>> >     image_io->SetPixelType(itk::ImageIOBase::SCALAR);
>>>>> >     writer->SetImageIO(image_io);
>>>>> >     writer->SetInput(output_image);
>>>>> >     writer->Update(); //output looks the same
>>>>> >     }
>>>>> >
>>>>> >
>>>>> > 2014-08-13 20:50 GMT+03:00 Matt McCormick
>>>>> > <matt.mccormick at kitware.com>:
>>>>> >>
>>>>> >> Hi Marian,
>>>>> >>
>>>>> >>
>>>>> >> If
>>>>> >>
>>>>> >>   itk::Image< unsigned  short, 2 >
>>>>> >>
>>>>> >> is used for the ImageType, does it work (note the dimension
>>>>> >> specification).
>>>>> >>
>>>>> >> HTH,
>>>>> >> Matt
>>>>> >>
>>>>> >> On Wed, Aug 13, 2014 at 1:47 PM, Мар'ян Климов <nekto1989 at gmail.com>
>>>>> >> wrote:
>>>>> >> > Hi,
>>>>> >> >
>>>>> >> > How to properly read 32-bit TIFF? I need to get
>>>>> >> > itk::Image<unsigned
>>>>> >> > short>
>>>>> >> > on output. If I use it as ImageType for ImageFileReader, it is
>>>>> >> > read as
>>>>> >> > fully
>>>>> >> > black (checked contrast with Image Watch and it is for sure
>>>>> >> > completely
>>>>> >> > empty). If I read it with pixel type RGBPixel<unsigned char> or
>>>>> >> > RGBAPixel<unsigned char>, it is read properly. But I need to
>>>>> >> > convert it
>>>>> >> > manually to unsigned short after this. So what is the proper way
>>>>> >> > of
>>>>> >> > reading
>>>>> >> > it? Do I need to create templated methods for every pixeltype with
>>>>> >> > conversions to unsigned short?
>>>>> >> >
>>>>> >> > Best regards,
>>>>> >> > Marian
>>>>> >> >
>>>>> >> > _______________________________________________
>>>>> >> > Community mailing list
>>>>> >> > Community at itk.org
>>>>> >> > http://public.kitware.com/mailman/listinfo/community
>>>>> >> >
>>>>> >
>>>>> >
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> Community mailing list
>>> Community at itk.org
>>> http://public.kitware.com/mailman/listinfo/community
>>>
>



More information about the Community mailing list