[Insight-users] Bug in CastImageFilter?

Miller, James V (Research) millerjv@crd.ge.com
Mon, 10 Feb 2003 11:27:28 -0500


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2D121.4D585C8A
Content-Type: text/plain

The issue is one of how high up the pipeline you need to search to determine the input has changed.

We see this problem alot with lengthy pipelines attached to a reader at the source.  A user changes
the filename on the reader (to a file that is a different size), and the pipeline doesn't produce the
expected result because Update() is updating the "same" RequestedRegion that it updated the last
time.  In this case, the input objects do not change (in that an input is a pointer to a different
data object).  Rather, internally the memory was reallocated/reorganized to be a different size.
Thus the pipeline, cannot simply look to see if a filter has a different input.  (Though I agree that
should also force a full update.  I think, however, that is just part of the solution.)
 



> -----Original Message-----
> From: Mark Hastenteufel [ mailto:M.Hastenteufel@dkfz-heidelberg.de
<mailto:M.Hastenteufel@dkfz-heidelberg.de> ]
> Sent: Monday, February 10, 2003 10:18 AM
> To: Miller, James V (Research); ITK Users
> Subject: Re: [Insight-users] Bug in CastImageFilter?
>
>
> Hi Jim,
>
> you're right. When calling UpdateLargestPossibleRegion()
> everything works fine.
>
> Isn't it possible to check in the Update() method
> if the input has been changed and calling
> UpdateLargestPossibleRegion() internally?
>
> Mark
>
>
>
> "Miller, James V (Research)" schrieb:
> >
> > This is a standard problem in the pipeline mechanism.
> >
> > The issue is when Update() is called the first time, no
> > RequestedRegion is set in the pipeline so it defaults to
> > setting the RequestedRegion to the LargestPossibleRegion.
> >
> > When you swap the input to the CastImageFilter and call
> > Update() a second time, the pipeline (incorrectly) assumes
> > that you want to update the same RequestedRegion that you
> > asked for (implicitly) the first time.  But you did not want
> > to update the same RequestedRegion, but rather, you wanted to
> > update a "new" RequestedRegion that matches the size of the image
> > coming from the pyramid.
> >
> > The quick fix is to change the call to Update() in your loop
> > to UpdateLargestPossibleRegion().
> >
> > Basically, there is currently no way for the pipeline to know
> > that the upstream data is not the same size as it used to be.
> >
> > I hope to add some type of "flush" mechanism which will return
> > a pipeline to its initial state so a user can change a input
> > upstream, flush the pipeline, and have an Update() do what a
> > user would expect.
> >
> > Jim
> >
> > > -----Original Message-----
> > > From: Mark Hastenteufel [ mailto:M.Hastenteufel@DKFZ-Heidelberg.de
<mailto:M.Hastenteufel@DKFZ-Heidelberg.de> ]
> > > Sent: Sunday, February 09, 2003 1:11 PM
> > > To: insight-users@public.kitware.com
> > > Subject: [Insight-users] Bug in CastImageFilter?
> > >
> > >
> > > Hi!
> > >
> > > I've found a strange behaviour in itk::CastImageFilter. I've
> > > implemented a simple program which produces an image
> > > pyramid.
> > > The images on the respective level are written out to disk. The
> > > images are converted from float (internal type of PyramidFilter)
> > > to short using an ikt::CastImageFilter.
> > >
> > >
> > > Typedef's:
> > >
> > >         typedef itk::Image<short,2> TInputImage2;
> > >         typedef itk::Image<double,2> TOutputImage;
> > >         typedef itk::MultiResolutionPyramidImageFilter<
> TOutputImage,
> > > TOutputImage > PyramidType;
> > >         typedef itk::CastImageFilter< TOutputImage,TInputImage2 >
> > > CastFilterType;
> > >
> > >
> > > If using the following code:
> > >
> > >
> > >   myPyramid->SetNumberOfLevels(noLevels);
> > >   myPyramid->SetInput( image );
> > >   myPyramid->UpdateLargestPossibleRegion();
> > >
> > >   CastFilterType::Pointer myCaster = CastFilterType::New();
> > >   for (int i=0 ; i<noLevels ; i++)
> > >   {
> > >     myCaster->SetInput( myPyramid->GetOutput(i) );
> > >     myCaster->Update();
> > >
> > >     char s[100];
> > >     sprintf(s,"level%d.pic",i);
> > >     Pic2itk::saveImage<TInputImage2>(s,myCaster->GetOutput());
> > >   }
> > >
> > >
> > > just the image on the coarsest level is OK! The others
> are corrupted.
> > > This seems due to CastImageFilter. If declaring a cast-filter
> > > inside the for-loop, everything is OK!
> > >
> > >   myPyramid->SetNumberOfLevels(noLevels);
> > >   myPyramid->SetInput(myCaster2->GetOutput() );
> > >   myPyramid->UpdateLargestPossibleRegion();
> > >
> > >   for (int i=0 ; i<noLevels ; i++)
> > >   {
> > >     CastFilterType::Pointer myCaster = CastFilterType::New();
> > >     myCaster->SetInput( myPyramid->GetOutput(i) );
> > >     myCaster->Update();
> > >
> > >     char s[100];
> > >     sprintf(s,"level%d.pic",i);
> > >     Pic2itk::saveImage<TInputImage2>(s,myCaster->GetOutput());
> > >   }
> > >
> > >
> > > It seems, that the CastImageFilter doesn't work if SetInput is
> > > called more than one time. Is this a bug or did I made something
> > > wrong?
> > >
> > >
> > > Mark
> > > _______________________________________________
> > > Insight-users mailing list
> > > Insight-users@public.kitware.com
> > > http://public.kitware.com/mailman/listinfo/insight-users
<http://public.kitware.com/mailman/listinfo/insight-users> 
> > >
>
> --
> Mark Hastenteufel
> Deutsches Krebsforschungszentrum         (German Cancer
> Research Center)
> Div. Medical and Biological Informatics H0100    Tel: (+49)
> 6221-42 2353
> Im Neuenheimer Feld 280                          Fax: (+49)
> 6221-42 2345
> D-69120 Heidelberg              e-mail           
> M.Hastenteufel@DKFZ.de
> Germany                        
http://www.dkfz.de/mbi/people/markh.html <http://www.dkfz.de/mbi/people/markh.html> 



------_=_NextPart_001_01C2D121.4D585C8A
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<TITLE></TITLE>

<META content="MSHTML 6.00.2715.400" name=GENERATOR></HEAD>
<BODY>
<P><FONT size=2>The issue is one of how high up the pipeline you need to search 
to determine the input has changed.</FONT></P>
<DIV><FONT size=2>We see this problem alot with lengthy pipelines attached to a 
reader at the source.&nbsp; A user changes the filename on the reader (to a file 
that is a different size), and the pipeline doesn't produce the expected result 
because Update() is updating the "same" RequestedRegion that it updated the last 
time.&nbsp; In this case, the input objects do not change (in that an input is a 
pointer to a different data object).&nbsp; Rather, internally the memory was 
reallocated/reorganized to be a different size.&nbsp; Thus the pipeline, cannot 
simply look to see if a filter has a different input.&nbsp; (Though I agree that 
should also force a full update.&nbsp; I think, however, that is just part of 
the solution.)</FONT></DIV>
<DIV><FONT size=2><FONT color=#0000ff></FONT>&nbsp;</DIV>
<P><BR><BR>&gt; -----Original Message-----<BR>&gt; From: Mark Hastenteufel [<A 
href="mailto:M.Hastenteufel@dkfz-heidelberg.de">mailto:M.Hastenteufel@dkfz-heidelberg.de</A>]<BR>&gt; 
Sent: Monday, February 10, 2003 10:18 AM<BR>&gt; To: Miller, James V (Research); 
ITK Users<BR>&gt; Subject: Re: [Insight-users] Bug in 
CastImageFilter?<BR>&gt;<BR>&gt;<BR>&gt; Hi Jim,<BR>&gt;<BR>&gt; you're right. 
When calling UpdateLargestPossibleRegion()<BR>&gt; everything works 
fine.<BR>&gt;<BR>&gt; Isn't it possible to check in the Update() method<BR>&gt; 
if the input has been changed and calling<BR>&gt; UpdateLargestPossibleRegion() 
internally?<BR>&gt;<BR>&gt; Mark<BR>&gt;<BR>&gt;<BR>&gt;<BR>&gt; "Miller, James 
V (Research)" schrieb:<BR>&gt; &gt;<BR>&gt; &gt; This is a standard problem in 
the pipeline mechanism.<BR>&gt; &gt;<BR>&gt; &gt; The issue is when Update() is 
called the first time, no<BR>&gt; &gt; RequestedRegion is set in the pipeline so 
it defaults to<BR>&gt; &gt; setting the RequestedRegion to the 
LargestPossibleRegion.<BR>&gt; &gt;<BR>&gt; &gt; When you swap the input to the 
CastImageFilter and call<BR>&gt; &gt; Update() a second time, the pipeline 
(incorrectly) assumes<BR>&gt; &gt; that you want to update the same 
RequestedRegion that you<BR>&gt; &gt; asked for (implicitly) the first 
time.&nbsp; But you did not want<BR>&gt; &gt; to update the same 
RequestedRegion, but rather, you wanted to<BR>&gt; &gt; update a "new" 
RequestedRegion that matches the size of the image<BR>&gt; &gt; coming from the 
pyramid.<BR>&gt; &gt;<BR>&gt; &gt; The quick fix is to change the call to 
Update() in your loop<BR>&gt; &gt; to UpdateLargestPossibleRegion().<BR>&gt; 
&gt;<BR>&gt; &gt; Basically, there is currently no way for the pipeline to 
know<BR>&gt; &gt; that the upstream data is not the same size as it used to 
be.<BR>&gt; &gt;<BR>&gt; &gt; I hope to add some type of "flush" mechanism which 
will return<BR>&gt; &gt; a pipeline to its initial state so a user can change a 
input<BR>&gt; &gt; upstream, flush the pipeline, and have an Update() do what 
a<BR>&gt; &gt; user would expect.<BR>&gt; &gt;<BR>&gt; &gt; Jim<BR>&gt; 
&gt;<BR>&gt; &gt; &gt; -----Original Message-----<BR>&gt; &gt; &gt; From: Mark 
Hastenteufel [<A 
href="mailto:M.Hastenteufel@DKFZ-Heidelberg.de">mailto:M.Hastenteufel@DKFZ-Heidelberg.de</A>]<BR>&gt; 
&gt; &gt; Sent: Sunday, February 09, 2003 1:11 PM<BR>&gt; &gt; &gt; To: 
insight-users@public.kitware.com<BR>&gt; &gt; &gt; Subject: [Insight-users] Bug 
in CastImageFilter?<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; 
Hi!<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; I've found a strange behaviour in 
itk::CastImageFilter. I've<BR>&gt; &gt; &gt; implemented a simple program which 
produces an image<BR>&gt; &gt; &gt; pyramid.<BR>&gt; &gt; &gt; The images on the 
respective level are written out to disk. The<BR>&gt; &gt; &gt; images are 
converted from float (internal type of PyramidFilter)<BR>&gt; &gt; &gt; to short 
using an ikt::CastImageFilter.<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; 
&gt; Typedef's:<BR>&gt; &gt; &gt;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef 
itk::Image&lt;short,2&gt; TInputImage2;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef 
itk::Image&lt;double,2&gt; TOutputImage;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef 
itk::MultiResolutionPyramidImageFilter&lt;<BR>&gt; TOutputImage,<BR>&gt; &gt; 
&gt; TOutputImage &gt; PyramidType;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef 
itk::CastImageFilter&lt; TOutputImage,TInputImage2 &gt;<BR>&gt; &gt; &gt; 
CastFilterType;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; If using 
the following code:<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; myPyramid-&gt;SetNumberOfLevels(noLevels);<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; myPyramid-&gt;SetInput( image );<BR>&gt; &gt; &gt;&nbsp;&nbsp; 
myPyramid-&gt;UpdateLargestPossibleRegion();<BR>&gt; &gt; &gt;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; CastFilterType::Pointer myCaster = 
CastFilterType::New();<BR>&gt; &gt; &gt;&nbsp;&nbsp; for (int i=0 ; 
i&lt;noLevels ; i++)<BR>&gt; &gt; &gt;&nbsp;&nbsp; {<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; myCaster-&gt;SetInput( myPyramid-&gt;GetOutput(i) 
);<BR>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; myCaster-&gt;Update();<BR>&gt; &gt; 
&gt;<BR>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; char s[100];<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s,"level%d.pic",i);<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
Pic2itk::saveImage&lt;TInputImage2&gt;(s,myCaster-&gt;GetOutput());<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; }<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; just 
the image on the coarsest level is OK! The others<BR>&gt; are corrupted.<BR>&gt; 
&gt; &gt; This seems due to CastImageFilter. If declaring a cast-filter<BR>&gt; 
&gt; &gt; inside the for-loop, everything is OK!<BR>&gt; &gt; &gt;<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; myPyramid-&gt;SetNumberOfLevels(noLevels);<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; myPyramid-&gt;SetInput(myCaster2-&gt;GetOutput() );<BR>&gt; 
&gt; &gt;&nbsp;&nbsp; myPyramid-&gt;UpdateLargestPossibleRegion();<BR>&gt; &gt; 
&gt;<BR>&gt; &gt; &gt;&nbsp;&nbsp; for (int i=0 ; i&lt;noLevels ; i++)<BR>&gt; 
&gt; &gt;&nbsp;&nbsp; {<BR>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; 
CastFilterType::Pointer myCaster = CastFilterType::New();<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; myCaster-&gt;SetInput( myPyramid-&gt;GetOutput(i) 
);<BR>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; myCaster-&gt;Update();<BR>&gt; &gt; 
&gt;<BR>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; char s[100];<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(s,"level%d.pic",i);<BR>&gt; &gt; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp; 
Pic2itk::saveImage&lt;TInputImage2&gt;(s,myCaster-&gt;GetOutput());<BR>&gt; &gt; 
&gt;&nbsp;&nbsp; }<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; It 
seems, that the CastImageFilter doesn't work if SetInput is<BR>&gt; &gt; &gt; 
called more than one time. Is this a bug or did I made something<BR>&gt; &gt; 
&gt; wrong?<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt;<BR>&gt; &gt; &gt; Mark<BR>&gt; 
&gt; &gt; _______________________________________________<BR>&gt; &gt; &gt; 
Insight-users mailing list<BR>&gt; &gt; &gt; 
Insight-users@public.kitware.com<BR>&gt; &gt; &gt; <A 
href="http://public.kitware.com/mailman/listinfo/insight-users" 
target=_blank>http://public.kitware.com/mailman/listinfo/insight-users</A><BR>&gt; 
&gt; &gt;<BR>&gt;<BR>&gt; --<BR>&gt; Mark Hastenteufel<BR>&gt; Deutsches 
Krebsforschungszentrum&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (German 
Cancer<BR>&gt; Research Center)<BR>&gt; Div. Medical and Biological Informatics 
H0100&nbsp;&nbsp;&nbsp; Tel: (+49)<BR>&gt; 6221-42 2353<BR>&gt; Im Neuenheimer 
Feld 
280&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Fax: (+49)<BR>&gt; 6221-42 2345<BR>&gt; D-69120 
Heidelberg&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
e-mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&gt; 
M.Hastenteufel@DKFZ.de<BR>&gt; 
Germany&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><A 
href="http://www.dkfz.de/mbi/people/markh.html" 
target=_blank>http://www.dkfz.de/mbi/people/markh.html</A><BR></P></FONT></BODY></HTML>

------_=_NextPart_001_01C2D121.4D585C8A--