[Insight-users] Median filter on Volume: Performance

John Drescher drescherjm at gmail.com
Wed Feb 23 08:45:04 EST 2011


On Wed, Feb 23, 2011 at 8:36 AM, sacrif <markus_m at gmx.net> wrote:
>
> Hello!
>
> Actually I simply want to load a volume, run a median filter on it and write
> the resulting volume back to disk. Therefore I implemented the following
> code:
>
>
> typedef signed short PixelType;
> static const unsigned int Dimension = 3;
> typedef itk::Image<PixelType, Dimension> InputImageType;
> typedef itk::Image<PixelType, Dimension> OutputImageType;
> typedef itk::ImageFileReader<InputImageType> ReaderType;
> typedef itk::ImageFileWriter< InputImageType >  WriterType;
> typedef itk::MedianImageFilter< InputImageType, OutputImageType >
> MedianFilterType;
>
> void MyClass::createMedianHdrFile(std::string filename)
> {
>        ReaderType::Pointer reader = ReaderType::New();
>        reader->SetFileName(filename.c_str());
>
>        MedianFilterType::Pointer medianFilter = MedianFilterType::New();
>        InputImageType::SizeType indexRadius;
>        indexRadius[0] = 10; // radius along x
>        indexRadius[1] = 10; // radius along y
>        indexRadius[2] = 10; // radius along z
>        medianFilter->SetRadius( indexRadius );
>        medianFilter->SetInput(reader->GetOutput());
>
>        std::string fnNoEnding = getFilenameWithErasedEnding(filename, ".hdr");
>        std::string fnNewEnding = getFilenameWithNewEnding(fnNoEnding,
> "_Median.hdr");
>
>        WriterType::Pointer writer = WriterType::New();
>        writer->SetFileName( fnNewEnding.c_str());
>        writer->SetInput( medianFilter->GetOutput() );
>        writer->Update();
>        cout << "Median End" << endl;
> }
>
>
> Basically this works if I use a very small filter with "indexRadius[0/1/2] =
> 1;". However, as soon as I use "indexRadius[0/1/2] = 10;" the calculation
> seems to take for ever.
> In the meanwhile the program ran for approximately 3 hours and did not
> finish yet. Is it really possible that the calculation of a "median volume"
> takes such a long time? And is there any way to reduce this time span?
>
> My input and output volume are in the Analyze format. For the current test
> run my input and output volume dimensions are  96x96x96 and the filter size
> is 10x10x10. However, I would also like to create "median volumes" of even
> larger data sets and with larger Filter dimensions.
> The test input volume min and max intensity are -1093 and 1086,
> respectively.
>
> Additionally I wanted to ask whether there is a simple way to run apply a
> spherical median filter of a certain radius instead of using the cuboid
> defined by "indexRadius[0/1/2]".
>

If this is windows and Visual Studio are you running the release
version? I found the debug version to be > 50 times slower than the
Release version.

John


More information about the Insight-users mailing list