[Insight-users] Filter re-use problems

Zachary Pincus zpincus at stanford.edu
Sat Feb 5 16:02:46 EST 2005


Hello,

I'm trying to re-use a ResampleImageFilter in a tight loop of a 
program. Unfortunately, I get corrupted output from the second use of 
the same filter each iteration. Only if I make a new resampler each 
time can I get valid output.

Here's the story: each iteration, I call two functions that use the 
same ResamleImageFilter to perform two transforms on an image that's 
being cached as m_CurrentPosition.Value(). (Yes, this is terrible 
design -- I should be able to compose the transforms, and/or I should 
be using a pipeline of two resample filters. However, I've got my 
reasons for doing things this way.)

Here's what it looks like:

Function 1:
   mask = m_CurrentPosition.Value(); // fetch the cached mask
   [...compute transform...]
   m_Resampler->SetTransform(affineReverseTransform);
   m_Resampler->SetSize(size);
   m_Resampler->SetOutputOrigin(lowerLeft);
   m_Resampler->SetInput(mask);
   m_Resampler->Update();		
   m_CurrentPosition.Value() = m_Resampler->GetOutput(); // cache the 
newly-transformed mask

Function 2:
   mask = m_CurrentPosition.Value(); // fetch the cached mask, which was 
transformed by function 1
   [...compute transform...]
   m_Resampler->SetTransform(translate);
   m_Resampler->SetSize(newSize);
   m_Resampler->SetOutputOrigin(newOriginPoint);
   m_Resampler->SetInput(mask);
   m_Resampler->Update();
   m_CurrentPosition.Value() = m_Resampler->GetOutput(); // cache the 
doubly-transformed mask


Now, unless I make a new resampler filter before function 2 is called, 
I get very corrupted output from function 2. (The image is wisted and 
torn, with an incorrect origin.) Note that if I do not make a new 
resampler, then in the next iteration (with a new image in 
m_CurrentPosition), function 1 again computes good output, and function 
2 again fails. So it's not like the resampler is permanently broken. It 
seems to be something I'm doing in function 2.

Does anyone have any ideas here? I would be most grateful!

Thanks,

Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine



More information about the Insight-users mailing list