[Insight-users] Problems with image corruption : Shouldn't use LargestPossibleRegion for Iterators.

Radhika Sivaramakrishna Radhika Sivaramakrishna" <radshashi at earthlink . net
Wed, 17 Dec 2003 18:38:40 -0800


Hi Luis,
Thanks for your suggestion. I will try this also, but I am not sure if this
is the problem though it is a good suggestion. After I sent off that piece
of code to you, I decided to do some more experimenting. In the code I sent
you I reused extracter2D (ExtractImageFilter Pointer) twice once to extract
a slice from the greyscale image, and then a second time to extract a slice
off the mask image. I decided to use two different pointers (one
extracter2Dimage and another extracter2Dmask) and lo and behold, things
started working and things were written out correctly. I dont understand why
this should happen? Could you explain?

Radhika


----- Original Message ----- 
From: "Luis Ibanez" <luis . ibanez at kitware . com>
To: "Radhika Sivaramakrishna" <radshashi at earthlink . net>
Cc: <insight-users at itk . org>
Sent: Wednesday, December 17, 2003 11:19 AM
Subject: Re: [Insight-users] Problems with image corruption : Shouldn't use
LargestPossibleRegion for Iterators.


> Hi Radhika,
>
> It seems that the error is related to the use of
> "GetLargestPossibleRegion()" in order to define
> the iterators in line 230 of your code:
>
>
> >     ImageType2D::RegionType region = binimg->GetLargestPossibleRegion();
> >     ConstIteratorType maskit (mask, region);
> >     ConstIteratorType binimgit( binimg, region );
> >     IteratorType newmaskit(newmask,region);
> >
> >    maskit.GoToBegin();
> >    binimgit.GoToBegin();
> >    newmaskit.GoToBegin();
> >    while( ! maskit.IsAtEnd() && ! binimgit.IsAtEnd() && !
newmaskit.IsAtEnd())
> >      {
> > newmaskit.Set(binimgit.Get());
> >        if( maskit.Get() == 0 )   // if mask pixel is off
> >          {
> > newmaskit.Set(0);
> >          }
> >        ++maskit;
> > ++binimgit;
> > ++newmaskit;
> >      }
>
> In general you shouldn't use "LargestPossibleRegion"
> since there is no guarranty that all this data is
> going to be in memory.  The safe region to use is the
> "Buffered" region.
>
> Just to make sure that this is the problem, please
> insert the line:
>
>             binimg->Print( std::cout )
>
> in line 229, run the program and look at the printed
> values of the image regions. There will be: Requested,
> Buffered and LargestPossible region.
>
> My guess is that the largest possible region is
> larger than the buffered region and your iterators
> are stepping out of the image buffers, therefore
> corrupting the memory.
>
> BTW the process that you are attempting with the
> iterators is done by the MaskImageFilter
> http://www . itk . org/Insight/Doxygen/html/classitk_1_1MaskImageFilter . html
>
> You may simply replace this while loop with a
> MaskImageFilter.
>
>
>
> Please let us know what you find.
>
>
> Thanks
>
>
>    Luis
>
>
>
> ------------------------------------
> Radhika Sivaramakrishna wrote:
> > Hi Luis,
> > I am having some problems with my program. I have enclosed a portion of
> > my code here where the problem is. I am not able to figure it out.
> > Basically, "binimg" in my code is the output of the relabel filter. At
> > that point when I write it out, it is correct. However, further down the
> > line, when I try to write out the output of the relabel filter, it is
> > corrupted. In fact, all are corrupted and they all have the same values
> > which is that of the result of the mask filter. Even "gs" the output of
> > the extractimagefilter is wrong at the point where I am writing it out.
> > Could you help me figure out the problem? Maybe there is something wrong
> > in the way I am setting the region of iteration for each or is there a
> > problem in reusing the extractimagefilter for first extracting a
> > greyscale slice and then using the same thing to extract a mask?
> >
> > Thanks
> > Radhika
> >
>
>
>