[Insight-users] Filter re-use problems
Karthik Krishnan
Karthik.Krishnan at kitware.com
Sun Feb 6 03:17:23 EST 2005
Hi Zach,
Sorry about the earlier mail.
Please use
mask->UpdateLargestPossibleRegion() instead of Update();
I am guessing that the size of the input to the resampler in the second
function changes because the resampler in the first function is changing
the resolution.
Does this help ?
Thanks
kk
Zachary Pincus wrote:
> Karthik,
>
> Thanks for your email!
>
> I tried the mask->Update() bit, and that actually causes an exception.
> Strange.
>
> Here's function 2 again:
> Function 2:
> mask = m_CurrentPosition.Value();
> (0)
> [...compute transform...]
> m_Resampler->SetTransform(translate);
> m_Resampler->SetSize(newSize);
> m_Resampler->SetOutputOrigin(newOriginPoint);
> (1)
> m_Resampler->SetInput(mask);
> (2)
> m_Resampler->Update();
> m_CurrentPosition.Value() = m_Resampler->GetOutput();
>
> If I put mask->Update() at position 0 or 2, there is no change. If I
> put it at position 1, an exception gets thrown:
>
>> itk::InvalidRequestedRegionError (0x13017f0)
>> Location: "Image::PropagateRequestedRegion()"
>> File:
>> /Developer/Local/ITK/ITK-CVS-src/Insight/Code/Common/itkDataObject.cxx
>> Line: 397
>> Description: Requested region is (at least partially) outside the
>> largest possible region.
>
>
>
> I then instrumented my code as requested, at the following locations:
>
> Function 1:
> mask = m_CurrentPosition.Value();
> (0)
> [...compute transform...]
> m_Resampler->SetTransform(affineReverseTransform);
> m_Resampler->SetSize(size);
> m_Resampler->SetOutputOrigin(lowerLeft);
> (1)
> m_Resampler->SetInput(mask);
> (2)
> m_Resampler->Update();
> (3)
> m_CurrentPosition.Value() = m_Resampler->GetOutput();
> (4)
>
> Function 2:
> mask = m_CurrentPosition.Value();
> (5)
> [...compute transform...]
> m_Resampler->SetTransform(translate);
> m_Resampler->SetSize(newSize);
> m_Resampler->SetOutputOrigin(newOriginPoint);
> (6)
> m_Resampler->SetInput(mask);
> (7)
> m_Resampler->Update();
> (8)
> m_CurrentPosition.Value() = m_Resampler->GetOutput();
> (9)
>
>
> The output is as follows. (Also note that in both [...compute
> transform...] portions of the code, I use a MomentsCalculator object
> with mask as the input to determine the transform, and I use
> mask->TransformPhysicalPointToIndex() and vice-versa. Other than that,
> I don't mess with the mask object.)
>
> 0 MaskMT: 92 ResamplerMT: 81
> 1 MaskMT: 92 ResamplerMT: 122
> 2 MaskMT: 92 ResamplerMT: 124
> 3 MaskMT: 92 ResamplerMT: 124
> 4 MaskMT: 92 ResamplerMT: 124
> 5 MaskMT: 130 ResamplerMT: 124
> 6 MaskMT: 130 ResamplerMT: 139
> 7 MaskMT: 130 ResamplerMT: 140
> 8 MaskMT: 146 ResamplerMT: 141
> 9 MaskMT: 146 ResamplerMT: 141
>
> The only odd thing that I notice is that the mask is modified by the
> second call to m_Resampler->Update(), but not the first.
>
> I can send my (slightly nasty) code if that would help...
>
> Thanks,
>
> Zach Pincus
>
> Department of Biochemistry and Program in Biomedical Informatics
> Stanford University School of Medicine
>
>
>
> On Feb 5, 2005, at 6:01 PM, Karthik Krishnan wrote:
>
>> Hi Zach,
>>
>> Could you insert the line
>> mask->Update();
>> right before the
>> m_Resampler->SetInput(mask);
>> line in Function 2
>>
>> and see if it works.
>>
>> Could you also please print out
>> std::cout << mask->GetMTime() << std::endl;
>> std::cout << m_Resampler->GetMTime() << std::endl;
>> at a bunch of positions, to help debug the problem.
>>
>> But I think the first solution may work.
>>
>> Thanks
>> kk
>>
>> Zachary Pincus wrote:
>>
>>> 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
>
>>>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list