[Insight-users] how to rerun a filter on the same image?

Luis Ibanez luis.ibanez at kitware.com
Tue Mar 23 16:10:10 EDT 2010


Hi George,

If you only changed a pixel value of the image,
then the image is not "aware" of this change.


ITK filters first check if their input images have changed,
and if they have not, then they don't run the process,
since their current output is still valid.

You have to tell the image that you have modified it,
you can do so by calling the method Modified():

Your code should look like:

             filter->SetInput( image );
             filter->Update();

             image->SetPixel( index, pixelValue );

             image->Modified();

             filter->Update();


NOTE: however, that if the image is the output of
a previous filter, then you SHOULD NOT be
modifying its pixel data, unless you first disconnect
it from the previous filter.

Such disconnection can be done with the call

               image->DisconnectPipeline();


--------------

Just for the record:

In your code, the trick of calling

                  SetInput( NULL )
                  SetInput( image )

works fine because it tricks the filter into
believing that it has a fresh new input image.


     Regards,


            Luis


--------------------------------------------------
On Mon, Mar 22, 2010 at 1:13 PM, g c <gc12358 at googlemail.com> wrote:
> Hi,
>
> I'm trying to rerun a rescale filter on the same image after I change
> a pixel in that image. I'm using the 'solution' shown in the example
> code below, but I guess there exists a better way to get the rescale
> filter to execute again?
>
> many thanks,
>
> George
>
> ====================
>
> #include <itkImage.h>
> #include <itkRescaleIntensityImageFilter.h>
> #include <itkImageFileReader.h>
>
> typedef float PixelType;
> typedef itk::Image< PixelType, 2 > ImageType;
> typedef itk::RescaleIntensityImageFilter< ImageType, ImageType >
> RescaleFilterType;
> typedef itk::ImageFileReader< ImageType > ReaderType;
>
> int main( int argc, char *argv[] )
> {
>    ReaderType::Pointer reader = ReaderType::New();
>    reader->SetFileName( argv[1] );
>    reader->Update();
>    ImageType::Pointer image = reader->GetOutput();
>
>    ImageType::IndexType index;
>    index[0] = 100;
>    index[1] = 100;
>    std::cout << image->GetPixel( index ) << std::endl;
>
>    RescaleFilterType::Pointer rescale = RescaleFilterType::New();
>    rescale->SetOutputMinimum( 0 );
>    rescale->SetOutputMaximum( 100 );
>    rescale->SetInput( image );
>    rescale->Update();
>    std::cout << rescale->GetOutput()->GetPixel( index ) << std::endl;
>
>    image->SetPixel( index, 1000 );
>
> //WORKS WHEN FOLLOWING TWO LINES UNCOMMENTED
> //    rescale->SetInput( NULL );
> //    rescale->SetInput( image );
>
>    rescale->Update();
>    std::cout << rescale->GetOutput()->GetPixel( index ) << std::endl;
>
>    return EXIT_SUCCESS;
> }
> _____________________________________
> 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
>


More information about the Insight-users mailing list