[Insight-users] how to update the content of an image
Luis Ibanez
luis.ibanez at kitware.com
Wed Apr 30 18:42:23 EDT 2008
Hi Bert,
Thanks for posting the details of your code.
Your program can be greatly simplified by using the itk::MaskImageFilter
http://www.itk.org/Insight/Doxygen/html/classitk_1_1MaskImageFilter.html
You don't need to do the masking on your own.
By using this filter as, now you simply need to have a for-loop
in which the output of the masking is passed as new input to the
customized grayscale reconstruction filter that you created.
The key point inside the loop is to call "DisconnectPipeline"
in that new output, before you pass it as new input to the
grayscaleReconstruction filter.
Your code gets reduced to:
-----------------------------------------------------------------
grayscaleReconstruction->SetKernel( structuringElement );
typedef itk::MaskImageFilter<
ImageType, MaskType, ImageType > MaskFilterType;
MaskFilterType::Pointer maskFilter = MaskFilterType::New();
grayscaleReconstruction->SetInput( readerMarker->GetOutput() );
maskFilter->SetInput1( grayscaleReconstruction->GetOutput() );
maskFilter->SetInput2( readerMask->GetOutput() );
for (int i =0; i<numberOfIterations; i++)
{
maskFilter->Update();
ImageType::ConstPointer newMarker = maskFilter->GetOutput();
newMarker->DisconnectPipeline();
grayscaleReconstruction->SetInput( newMarker );
}
-----------------------------------------------------------------
It will be great if you post this code as a contribution to
the Insight Journal :-)
Regards,
Luis
----------------
Bert wrote:
> Hi Luis,
>
> Thanks a lot for your answer. What I am trying to do is to implement a
> reconstruction algorithm. I haven't used any of the implemented ones
> because I need to use my own structuring element.
> What I have to do is dilatation + intersection until the convergence,
> this is why I need to modify the output of the Dilate filter. Is
> possible to do it? This is the code I have:
>
> InputImageType::Pointer marker = InputImageType::New();
> InputImageType::Pointer markerDilated = InputImageType::New();
> InputImageType::Pointer mask = InputImageType::New();
>
> marker = readerMarker->GetOutput(); //read the marker image
> markerDilated = grayscaleReconstruction->GetOutput(); //read the
> dilated marker
> mask = readerMask->GetOutput(); //read the mask image
>
> // Next we create two iterators. The iterators are initialized over
> the same region.
> //The direction of iteration is set to 0, the $x$ dimension.
> IteratorType markerDilatedIt( markerDilated,
> markerDilated->GetRequestedRegion() );
> IteratorType maskIt( mask, mask->GetRequestedRegion() );
> markerDilatedIt.SetDirection(0);
> maskIt.SetDirection(0);
>
> grayscaleReconstruction->SetKernel( structuringElement );
> WriterType::Pointer writerMarkerDilated = WriterType::New();
>
> for (int i =0; i<numberOfIterations; i++)
> {
> grayscaleReconstruction->SetInput( marker );
> grayscaleReconstruction->Update();
>
>
> for ( markerDilatedIt.GoToBegin(), maskIt.GoToBegin(); !
> maskIt.IsAtEnd();
> markerDilatedIt.NextLine(), maskIt.NextLine())
> {
> markerDilatedIt.GoToBeginOfLine();
> maskIt.GoToBeginOfLine();
>
> while ( ! markerDilatedIt.IsAtEndOfLine() )
> {
> if( maskIt.Get()==0 )
> {
> markerDilatedIt.Set( 0 );
> ++markerDilatedIt;
> ++maskIt;
> }
> else
> {
> ++markerDilatedIt;
> ++maskIt;
> }
> }
> }
> writerMarkerDilated->SetFileName( argv[2] ); //overwrite the marker
> writerMarkerDilated->SetInput(markerDilated);
> writerMarkerDilated->Update();
>
> readerMarker->Update();
> marker->Update();
>
>
> }
>
> Thanks a lot for your reply
> Best
> Bert
>
>
More information about the Insight-users
mailing list