[ITK] Getting ImageType for TIFF

Мар'ян Климов nekto1989 at gmail.com
Wed Aug 13 16:55:51 EDT 2014


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
> >> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140813/5fa8f67f/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ReadTIFF32bit.zip
Type: application/zip
Size: 63889 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20140813/5fa8f67f/attachment-0002.zip>


More information about the Community mailing list