[Insight-users] Apply filter only on a specific region ?
Ivan Macia
imacia at vicomtech.org
Fri Feb 5 13:44:00 EST 2010
Hi,
For your original purpose, what Luis says is the correct way to
proceed. I think you mentioned already that this was working.
Just for speculative purposes, and to understand a bit better (this
includes myself) how the RequestedRegion works, I did a little
experiment (see attached program) with the MedianFilter. After reading
the image, at the output of the filter I set a requested region that
is the first quadrant of the LargestPossibleRegion as follows:
ImageType::RegionType medianRegion =
reader->GetOutput()->GetLargestPossibleRegion();
ImageType::RegionType::SizeType medianSize;
// Take the first quadrant
medianSize = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
medianSize[0] /= 2;
medianSize[1] /= 2;
medianRegion.SetSize( medianSize );
median->GetOutput()->SetRequestedRegion( medianRegion );
median->Update();
However, when running the program, the full image is processed. This
is because the median filter is in turn connected to the writer, which
I guess resets the RequestedRegion on the output of the median to the
LargestPossibleRegion. However, if we put this code before the writer
ImageType::Pointer output = median->GetOutput();
output->DisconnectPipeline();
and pass this pointer to the writer, you get the first quadrant in the
output file, of course after breaking the pipeline which is not very
'orthodox' (sometimes very useful though in GUI apps :) )
The problem here is that you cannot set a RequestedRegion() on the
writer (maybe with SetIORegion()??? ), so the correct way seems to be
to use the ExtractImageFilter or the RegionOfInterestImageFilter in
this example in order not to disconnect the pipeline. The
SetRequestedRegion() method seems to be more oriented for the filters
to handle the internals of the pipeline. However, for me seems to be
quite straightforward for processing only a part of the image (knowing
what you are doing) without additional memory. Luis correct me if I'm
wrong, I am a bit confused here.
Best regards
Iván
2010/2/5 Luis Ibanez <luis.ibanez at kitware.com>
>
> Hi Steve,
>
> Since what you want to get as output is an image that
> has the same size as the input image, with only a subregion
> being modified, you should use a pipeline such as:
>
> 1) RegionOfInterestImageFilter
> 2) MedianFilter
> 3) PastImageFilter
>
> Where the PasteImageFilter will combine the output
> of the Median, with the original input image.
>
> Regards,
>
>
> Luis
>
>
> ---------------------------------------------
> On Fri, Feb 5, 2010 at 9:04 AM, steve harris <steve.harris18 at hotmail.com> wrote:
> > hello,
> >
> > Still filtering all the image.
> >
> > Steve
> >
> >
> > ________________________________
> > Date: Fri, 5 Feb 2010 13:01:59 +0100
> > Subject: Re: [Insight-users] Apply filter only on a specific region ?
> > From: imacia at vicomtech.org
> > To: steve.harris18 at hotmail.com
> > CC: luis.ibanez at kitware.com; insight-users at itk.org
> >
> > Hi,
> >
> > Try
> >
> > medianFilter->GetOutput()->SetRequestedRegion( wantedRegion3 )
> >
> > before updating. The request must be done on the output, not in the input.
> > The pipeline calculates which is the required input to generate the output,
> > which in turn will be the output of the previous filter, and so on.
> >
> > Best regards
> >
> > Ivan
> >
> > 2010/2/5 steve harris <steve.harris18 at hotmail.com>
> >
> > Hello again,
> >
> > I open again this subject because of what Louis suggested.
> >
> >> or even use the SetRequrestedRegion()
> >> of the Median filter directly.
> >
> > I was also interested in this methods so I quickly tried it but without
> > success..
> >
> > I didn't manage to find how to set the SetRequrestedRegion of the median
> > filter directly ?
> > That's what I tried:
> >
> > start3[0] = 0;
> > start3[1] = 0;
> > start3[2] = 0;
> >
> > size3[0] = 20;
> > size3[1] = 20;
> > size3[2] = 20;
> > wantedRegion3.SetIndex(start3);
> > wantedRegion3.SetSize(size3);
> >
> > mySimpleImage->SetRequestedRegion(wantedRegion3)
> > neighRadius2[0] = 1;
> > neighRadius2[1] = 1;
> > neighRadius2[2] = 1;
> > median->SetRadius(neighRadius2);
> > median->SetInput(mySimpleImage);
> > median->Update();
> >
> > But when I display median->GetOutput() all the image has been filtred and
> > not only my requested region...
> >
> > Do I'm missing something ?
> >
> > Regards,
> > Steve
> >
> > ________________________________
> > From: steve.harris18 at hotmail.com
> > To: imacia at vicomtech.org; luis.ibanez at kitware.com
> > Date: Tue, 26 Jan 2010 10:48:22 +0000
> > CC: insight-users at itk.org
> > Subject: Re: [Insight-users] Apply filter only on a specific region ?
> >
> > Hello,
> >
> > Just a word to say that using this pipeline
> >
> > RegionOfInterestImageFilter
> > MedianImageFilter
> > PasteImageFilter
> >
> > it works, I mean I quickly tried and I got a good visual result (only the
> > part I chossed has been filtred)
> >
> > Thanks,
> > Steve
> >
> >> From: imacia at vicomtech.org
> >> To: luis.ibanez at kitware.com; steve.harris18 at hotmail.com
> >> CC: insight-users at itk.org
> >> Subject: RE: [Insight-users] Apply filter only on a specific region ?
> >> Date: Mon, 25 Jan 2010 18:15:20 +0100
> >>
> >> Hi Luis,
> >>
> >> Just a question. We were discussing here at work the meaning of the
> >> different regions (Largest vs Requested vs Buffered). One question we had
> >> is
> >> if you can process a part of the image only by setting the Requested
> >> Region
> >> on the output, which seems quite straightforward and compatible with the
> >> ITK
> >> pipeline definition. What would you get here? An image whose Largest
> >> Possible Region is the same as the one you requested?
> >>
> >> The idea I have is that the Requested Region is an important part of the
> >> ITK
> >> pipeline and is used by the filters, at least internally, so why is its
> >> use
> >> discouraged in this case?
> >>
> >> Thanks in advance
> >>
> >> Iván
> >>
> >> PD: it is common the case in which we have to process only a certain part
> >> of
> >> the image in medical applications, for example when we have to calculate
> >> statistics in a region of interest from a 3D image, as defined by the
> >> radiologist. It may be inconsistent from the point of view image
> >> processing
> >> but it works :) This is just an example but we have find many cases in
> >> which
> >> we have had to restrict ourselves only to a certain part of the image as
> >> defined by the user, due to memory limitations or for a faster processing
> >> among other reasons.
> >>
> >>
> >> -----Mensaje original-----
> >> De: insight-users-bounces at itk.org [mailto:insight-users-bounces at itk.org]
> >> En
> >> nombre de Luis Ibanez
> >> Enviado el: domingo, 24 de enero de 2010 16:11
> >> Para: dsdfdff sfdsf
> >> CC: insight-users at itk.org
> >> Asunto: Re: [Insight-users] Apply filter only on a specific region ?
> >>
> >> Hi Steve,
> >>
> >> It depends....
> >>
> >> What exactly do you want at the output ?
> >>
> >> A) The full input input with the subregion modified ?
> >>
> >> or
> >>
> >> B) only the modified subregion ?
> >>
> >> ---
> >>
> >> If you want (A) you will have to use a pipeline
> >> such as:
> >>
> >> RegionOfInterestImageFilter
> >> MedianImageFilter
> >> PasteImageFilter
> >>
> >> If you want (B) you could use simply
> >>
> >>
> >> RegionOfInterestImageFilter
> >> MedianImageFilter
> >>
> >> or even use the SetRequrestedRegion()
> >> of the Median filter directly. Although
> >> this last option is not a recommended
> >> practice, unless you are very familiar
> >> with the inner-workings of the ITK pipeline.
> >>
> >>
> >> --
> >>
> >> On a side note:
> >>
> >> Why do you want to do such thing ? :-)
> >>
> >> From the pure image processing point of view,
> >> it doesn't seem to be a good operation. You
> >> will end up with an inconsistent image...
> >>
> >>
> >>
> >> Regards,
> >>
> >>
> >> Luis
> >>
> >>
> >> --------------------------------------
> >> On Fri, Jan 22, 2010 at 5:51 AM, dsdfdff sfdsf
> >> <steve.harris18 at hotmail.com> wrote:
> >> > Hello itk user,
> >> >
> >> > I was wondering if it was possible to apply a filter only on a specific
> >> > region of an image (like setting a bundary region)?
> >> >
> >> > for example if I have a simple 3D image (let say 30x30x30) is it
> >> > possible
> >> > for example to apply the mean filter
> >> > only on the region (15x15x15)?
> >> >
> >> > regards,
> >> > Steve
> >> >
> >> > ________________________________
> >> > Faites une bonne action avec Bing Solidaire ! C'est ici !
> >> > _____________________________________
> >> > Powered by www.kitware.com
> >> >
> >> > Visit other Kitware open-source projects at
> >> > http://www.kitware.com/opensource/opensource.html
> >> >
> >> > Kitware offers ITK Training Courses, for more information visit:
> >> > http://www.kitware.com/products/protraining.html
> >> >
> >> > Please keep messages on-topic and check the ITK FAQ at:
> >> > http://www.itk.org/Wiki/ITK_FAQ
> >> >
> >> > Follow this link to subscribe/unsubscribe:
> >> > http://www.itk.org/mailman/listinfo/insight-users
> >> >
> >> >
> >> _____________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Kitware offers ITK Training Courses, for more information visit:
> >> http://www.kitware.com/products/protraining.html
> >>
> >> Please keep messages on-topic and check the ITK FAQ at:
> >> http://www.itk.org/Wiki/ITK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.itk.org/mailman/listinfo/insight-users
> >>
> >
> > ________________________________
> > Windows 7 : Trouvez le PC qui vous convient! Découvrez notre offre !
> > ________________________________
> > Votre messagerie et bien plus où que vous soyez. Passez à Windows Live
> > Hotmail, c'est gratuit ! Inscrivez-vous
> >
> > ________________________________
> > Votre messagerie et bien plus où que vous soyez. Passez à Windows Live
> > Hotmail, c'est gratuit ! Inscrivez-vous
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RequestedRegion.cxx
Type: application/octet-stream
Size: 2479 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100205/603db185/attachment.obj>
More information about the Insight-users
mailing list