[Insight-users] Problem with resampling
Chris Farmer
cfarmer at scitegic.com
Tue Oct 18 16:48:31 EDT 2005
Hi Martin,
Thanks for the response. The same result occurs when I try your
suggested sequence of commands, so I'm still unsure what I could be
doing wrong. Just to make sure we're on the same page, here's the
revised code I'm trying:
RGB8WriterType::Pointer w = RGB8WriterType::New();
w->SetInput(m_rgbimage);
w->SetFileName("c:\\test1.png");
w->Write(); // writes successfully
RGB8ImageType::RegionType region =
m_rgbimage->GetLargestPossibleRegion();
RGB8ImageType::SizeType size = region.GetSize();
double yscale = (double)width / size[0];
double xscale = (double)height / size[1];
typedef itk::ScaleTransform<double, 2> Transform;
Transform::Pointer scaler = Transform::New();
Transform::OutputVectorType scalevector;
scalevector[0] = yscale;
scalevector[1] = xscale;
scaler->SetScale(scalevector);
typedef itk::VectorResampleImageFilter<RGB8ImageType, RGB8ImageType>
ResampleFilterType;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
resampler->SetTransform(scaler);
resampler->SetInput(m_rgbimage);
resampler->Update();
RGB8ImageType::Pointer image2 = resampler->GetOutput();
RGB8WriterType::Pointer w2 = RGB8WriterType::New();
w2->SetInput(image2);
w2->SetFileName("c:\\test2.png");
w2->Write(); // fails with the exception mentioned before
Am I missing the point of your post? The content of the image2 object
appears the same in both this case and in my previous code.
On a side note, I think I understand the pipeline model here, and I'm
not sure why it's incorrect to call GetOutput before the Update. I
thought the nature of the pipeline architecture enabled the stringing
together of process objects and allowing the actual "work" to be done in
one fell swoop with the Update call. I thought as long as I didn't try
to *do* anything with the image2 pointer in my previous code before
updating the pipeline, I'd be okay. My (admittedly sparse) knowledge of
this is based on section 3.5 in the ITK software guide (version 2.2) and
on some minor adventures with a debugger. What sections of the guide do
you recommend for me to read to learn more about these things?
Thanks,
Chris
-----Original Message-----
From: Martin Urschler [mailto:martin at urschler.info]
Sent: Tuesday, October 18, 2005 9:15 AM
To: Chris Farmer
Cc: insight-users at itk.org
Subject: Re: [Insight-users] Problem with resampling
Chris Farmer wrote:
> typedef itk::VectorResampleImageFilter<RGB8ImageType, RGB8ImageType>
> ResampleFilterType;
> ResampleFilterType::Pointer resampler = ResampleFilterType::New();
> resampler->SetTransform(scaler);
> resampler->SetInput(m_rgbimage);
> RGB8ImageType::Pointer image2 = resampler->GetOutput();
> resampler->Update();
> image2->Update();
this passage is wrong, you are reading the result image (i guess image2)
before you have updated the filter pipeline...
an image itself is an object that is passed from pipeline stage to
pipeline stage, you are abviously misusing the image as a part of the
pipeline!
the right way of doing that is:
resampler->SetInputImage( m_rgbimage); // setup pipeline
try
{
resampler->Update();
}
catch(itk::Exception& err)
{
...
}
RGB8ImageType::Pointer resultImage = resampler->GetOutput();
I'd suggest some further reading of the software guide which excellently
explains these basic things...
regards,
Martin
More information about the Insight-users
mailing list