[ITK-users] itkImageFileWriter + ExtractSliceImageFilter: largest region exception

Marcos fotosentido at gmail.com
Wed Sep 9 12:21:54 EDT 2015


Ok, finally, I got it.

I left the duplicated thing, but it wasn't the pipeline.

I didn't see a warning from compiler, and the exception message didn't give
me that clue:
the pixeltype I was using.


A lot of examples are using *unsigned short *or *signed short*, right? So I
was.
Reviewing the source code on the imageio classes:

"BMPImageIO supports unsigned char only"
"JPEG supports unsigned char/int only"
"PNG supports unsigned char and unsigned short"

I just changed to *unsigned char*, and everything works fine.
Thanks for all the ideas, I really appreciate it. It's not easy trying to
help without all the info.
I didn't realise the problem was outside my method. Sorry.

It takes some time to get things working, but it's great when it happens.


2015-09-09 17:36 GMT+02:00 Marcos <fotosentido at gmail.com>:

> Hi,
>
> GetBufferedRegion gives me the same numbers as GetLargestPossibleRegion:
> index: 0, 0, 0
> size: 512, 512, 12
>
> I also tried, just after reading the image, using ImageDuplicator:
>
> reader = ReaderType::New();
>
>     reader->SetFileName(fileName);
>
>
>     dicomIO = itk::GDCMImageIO::New();
>
>
>     typedef itk::ImageDuplicator< ImageType > DuplicatorType;
>
>     DuplicatorType::Pointer duplicator = DuplicatorType::New();
>
>
>
>     reader->SetImageIO(dicomIO);
>
>     try
>
>     {
>
>         reader->Update();
>
>         image = reader->GetOutput();
>
>
>         // duplicar imagen
>
>         duplicator->SetInputImage(image);
>
>         duplicator->Update();
>
>         imageToSave = duplicator->GetOutput();
>
>      }
>
>      catch
>
>      ...
>
>
>
> None worked.
>
> I saw the ExtractImageFilter example, so I changed to extracter->SetDirectionCollapseToSubmatrix() instead of SetDirectionCollapseToIdentity().
>
> The filename is "C:/Users/M/r.png", in Windows.
> Nothing. Same error.
>
> bmp: itkbmpimageio.cxx:727
> jpg: itkjpegimageio.cxx:454
> png: itkpngimageio.cxx:521
>
> By the way, it would be better if the exception messages were captured in my writer's try catch. I have to dive into these sources.
>
>
> 2015-09-08 22:05 GMT+02:00 Bradley Lowekamp <blowekamp at mail.nih.gov>:
>
>> Hello,
>>
>> You can use the Image::GetBufferedRegion method and print the resulting
>> ImageRegion.
>>
>> This looks like there is a pipelining issue to me. I'd recommend trying
>> to simplify by not reusing the Image data object. Yes you will need to
>> recompute, but it may help to narrow down the problem.
>>
>> Brad
>>
>>
>>
>> On Sep 8, 2015, at 3:06 PM, Marcos <fotosentido at gmail.com> wrote:
>>
>> Hi,
>>
>> I know the input and desired regions, not sure how to look for the
>> buffered region.
>>
>> 1. Reviewing my code I saw I didn't set the input image for the
>> extracter, so I added:
>> extracter->SetInput(image);
>>
>> Good, right? But no. Still the same error.
>>
>> 2. Then I tried switching to itkExtractImageFilter, and I got:
>> Exception at 0x7633c42d, code: 0xe06d7363: C++ exception, flags=0x1
>> (execution cannot be continued) (first chance) at
>> c:\itk-4.8.0-installed\include\itk-4.8\itkextractimagefilter.hxx:242
>>
>> So I had to look inside this code (why don't throw me more info in the
>> try catch?) to see what's happening, and I read this:
>> itkExceptionMacro( << "It is required that the strategy for collapsing
>> the direction matrix be explicitly specified. " << "Set with either
>> myfilter->SetDirectionCollapseToIdentity() or
>> myfilter->SetDirectionCollapseToSubmatrix() " << typeid( ImageBase<
>> InputImageDimension > * ).name() );
>> 3. I also tried to insert a:
>> image->Update();
>> or
>> image->UpdateOutputData();
>> with same results.
>>
>> I was thinking about passing the reader, but I'd like to apply changes to
>> my image, so this method would receive a modified copy (no DeepCopy method
>> like in vtk?)
>>
>>
>> Yes, the input image is connected to a pipeline:
>> itk::Image -> itk::ImageToVTKImageFilter -> vtk::vtkImageFlip ->
>> vtkImageData -> vtkImageViewer2
>>
>>
>> Thanks again for your interest.
>>
>>
>> 2015-09-08 16:16 GMT+02:00 Bradley Lowekamp <blowekamp at mail.nih.gov>:
>>
>>> Hello,
>>>
>>> What is the buffered region for the input image? Is the input image
>>> connected to a pipeline?
>>>
>>> Perhaps you just forgot to update the input image before running this
>>> function?
>>>
>>> Brad
>>>
>>> On Sep 7, 2015, at 5:21 PM, Marcos <fotosentido at gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I have a method that was exporting fine one frame from my itk::Image.
>>>
>>> My method:
>>>
>>> void Exporter::exportOriginal(QString fileName, ImageType::Pointer image, int frame)
>>>
>>> {
>>>
>>>     typedef itk::ImageFileWriter<FrameImageType> WriterType;
>>>
>>>     WriterType::Pointer writer = WriterType::New();
>>>
>>>
>>>     writer->SetFileName(fileName.toStdString().c_str());
>>>
>>>
>>>     ImageType::RegionType inputRegion = image->GetLargestPossibleRegion();
>>>
>>>
>>>     ImageType::IndexType index = inputRegion.GetIndex();
>>>
>>>     ImageType::SizeType size = inputRegion.GetSize();
>>>
>>>
>>>     index[0] = 0;
>>>
>>>     index[1] = 0;
>>>
>>>     index[2] = frame;
>>>
>>>
>>>     // 3D to 2D
>>>
>>>     size[2] = 0;
>>>
>>>
>>>     ImageType::RegionType outputRegion;
>>>
>>>     outputRegion.SetIndex(index);
>>>
>>>     outputRegion.SetSize(size);
>>>
>>>
>>>     typedef itk::Testing::ExtractSliceImageFilter<ImageType, FrameImageType> ExtractType;
>>>
>>>     ExtractType::Pointer extracter = ExtractType::New();
>>>
>>>     extracter->SetExtractionRegion(outputRegion);
>>>
>>>
>>>     writer->SetInput(extracter->GetOutput());
>>>
>>>     try
>>>
>>>     {
>>>
>>>         writer->Update();
>>>
>>>     }
>>>
>>>     catch (itk::ExceptionObject &ex)
>>>
>>>     {
>>>
>>>         std:cerr << ex << std::endl;
>>>
>>>     }
>>>
>>> }
>>>
>>>
>>> as inputRegion, I have:
>>> index: [0, 0, 0]
>>> size: [512, 512, 12]
>>>
>>> as outputRegion, I have:
>>> index: [0, 0, 1]                   # first frame
>>> size: [512, 512, 0]
>>>
>>>
>>>
>>> But I'm not sure what happened, now with every image I got an exception:
>>> itkimagefilewriter.hxx:287: "Largest possible region does not fully
>>> contain requested paste IO region"
>>>
>>> By the way, my try catch is not getting the exception message, I had to
>>> look inside the writer class.
>>> Any ideas? 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://public.kitware.com/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.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://public.kitware.com/mailman/listinfo/insight-users
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150909/5644ee41/attachment.html>


More information about the Insight-users mailing list