[Insight-users] Problem with resampling

Chris Farmer cfarmer at scitegic.com
Tue Oct 18 19:39:22 EDT 2005


Just a quick note for the archives:

I found the source of my problem with image resampling.  I was trying to
use the filter without setting its size.  When I added this code:

RGB8ImageType::SizeType   outsize;
outsize[0] = (double)size[0] / scalevector[0];
outsize[1] = (double)size[1] / scalevector[1];
resampler->SetSize( outsize );

all was well.  I guess I just assumed that the size would be inferred
from the original image size and the scaling factor, but it makes sense
that you should specify it explicitly.  I would have expected a far
different exception to be thrown than the one I got from the PNG innards
based on my error here, though.

I went on a brief wild goose chase thanks to Martin's assertion that I
lacked basic understanding of the pipeline model, but I feel much more
comfortable with the model now.  So, thanks!  :)




 

-----Original Message-----
From: Chris Farmer 
Sent: Tuesday, October 18, 2005 1:49 PM
To: Martin Urschler
Cc: insight-users at itk.org
Subject: RE: [Insight-users] Problem with resampling



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


 


More information about the Insight-users mailing list