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

g c gc12358 at googlemail.com
Mon Mar 22 13:13:54 EDT 2010


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;	
}


More information about the Insight-users mailing list