[ITK-users] SetOutputOrigin(origin) not working on writer
Bill Lorensen
bill.lorensen at gmail.com
Sun May 15 11:45:37 EDT 2016
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
More information about the Insight-users
mailing list