[ITK-users] SetOutputOrigin(origin) not working on writer
Matias Montroull
matimontg at gmail.com
Tue May 17 21:51:45 EDT 2016
Thanks, I actually had to add this line of code to the writer:
writer->UseInputMetaDataDictionaryOff();
Not sure why but it worked and it also copied all tags from the original
image into the output image.
El dom., 15 de may. de 2016 a la(s) 12:45, Bill Lorensen <
bill.lorensen at gmail.com> escribió:
> After
> reader->SetFileName(argv[1]);
> reader->Update();
>
> No need for inputImage->Update();
>
> Since you did not Update the reader, the origin and spacing will be
> (0,0,0) and(1,1,1) by defulat.
>
>
> On Sat, May 14, 2016 at 7:42 PM, Matias Montroull <matimontg at gmail.com>
> wrote:
> > Hi,
> >
> > I have the following code to flip an image and preserve origin and
> spacing.
> > For some reason, the writer doesn't copy the Origin from the original
> image
> > into the output Image.
> >
> > I can see the Output Image origin is the Original Image origin but I
> don't
> > understand why the writer doesn't take that value. I have no issues with
> the
> > spacing, that one is copied just fine into the output image.
> >
> > I'm using ITK 4.7.2
> >
> > #include "itkImage.h"
> > #include "itkImageFileReader.h"
> > #include "itkImageFileWriter.h"
> > #include "itkFlipImageFilter.h"
> > #include "itkChangeInformationImageFilter.h"
> >
> > int main(int argc, char* argv[])
> > {
> > if (argc != 4)
> > {
> > std::cerr << "Usage: " << argv[0];
> > std::cerr << " <InputFileName> <OutputFileName> <AxisToFlip>";
> > std::cerr << std::endl;
> > return EXIT_FAILURE;
> > }
> >
> > typedef itk::Image<signed short, 2 > ImageType;
> >
> > typedef itk::ImageFileReader< ImageType > ReaderType;
> > ReaderType::Pointer reader = ReaderType::New();
> >
> > reader->SetFileName(argv[1]);
> >
> > ImageType::Pointer inputImage = reader->GetOutput();
> > inputImage->Update(); //Importante!! Sin esto no agarra el origen
> >
> > ImageType::PointType origin = inputImage->GetOrigin();
> > ImageType::SpacingType spacing = inputImage->GetSpacing();
> >
> > typedef itk::FlipImageFilter< ImageType > FlipImageFilterType;
> > FlipImageFilterType::Pointer flipFilter = FlipImageFilterType::New();
> >
> > typedef itk::ChangeInformationImageFilter< ImageType > FilterType;
> > FilterType::Pointer filter = FilterType::New();
> > filter->SetInput(reader->GetOutput());
> >
> > filter->SetOutputOrigin(origin);
> > filter->ChangeOriginOn();
> > filter->SetOutputSpacing(spacing);
> > filter->ChangeSpacingOn();
> >
> > flipFilter->SetInput(filter->GetOutput());
> > flipFilter->Update();
> >
> > FlipImageFilterType::FlipAxesArrayType flipAxes;
> > if (atoi(argv[3]) == 0)
> > {
> > flipAxes[0] = true;
> > flipAxes[1] = false;
> > }
> > else
> > {
> > flipAxes[0] = false;
> > flipAxes[1] = true;
> > }
> >
> > flipFilter->SetFlipAxes(flipAxes);
> > typedef itk::ImageFileWriter< ImageType > WriterType;
> > WriterType::Pointer writer = WriterType::New();
> > writer->SetFileName(argv[2]);
> > writer->SetInput(flipFilter->GetOutput());
> > try
> > {
> > writer->Update();
> > std::cout << "Input origin is: " << reader->GetOutput()->GetOrigin() <<
> > std::endl;
> > std::cout << "Output origin is: " <<
> flipFilter->GetOutput()->GetOrigin() <<
> > std::endl;
> > }
> > catch (itk::ExceptionObject & error)
> > {
> > std::cerr << "Error: " << error << std::endl;
> > return EXIT_FAILURE;
> > }
> >
> > return EXIT_SUCCESS;
> > }
> >
> > --
> > Matias
> >
> > _____________________________________
> > 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
> >
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com
>
--
Matias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160518/052723fb/attachment.html>
More information about the Insight-users
mailing list