MantisBT - ITK
View Issue Details
0010398ITKpublic2010-03-09 23:392010-10-25 16:17
Rohit Saboo 
Gaetan Lehmann 
normalminoralways
assignedopen 
ITK-3-16 
 
0010398: At least one of ErodeObjectMorphologyImageFilter and DilateObjectMorphologyImageFilter not behaving as expected
A closed image should contain the original image. However the result of applying DilateObjectMorphologyImageFilter followed by ErodeObjectMorphologyImageFilter results in an image which is shrunk compared to the original image.

This error is not observed when one uses BinaryDilateImageFilter and BinaryErodeImageFilter

I've uploaded a sample file and attached the code for a program that will read in an input file, perform the close, and save the result back. You can comment out and uncomment the appropriate lines to change the filter being used.

You may call it with
close_filter mandible.mha closed_mandible.mha 3
The error will be most clearly visible near axial slices 24 and 25 of the closed image.
#include <iostream>

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkBinaryDilateImageFilter.h"
#include "itkDilateObjectMorphologyImageFilter.h"
#include "itkErodeObjectMorphologyImageFilter.h"
#include "itkBinaryDilateImageFilter.h"
#include "itkBinaryErodeImageFilter.h"

using namespace std;

int main(int argc, char* argv[])
{
    typedef unsigned short Pixel;
    typedef itk::Image<Pixel,3> ImageType;

    // Binary Morphology filters
    typedef itk::BinaryBallStructuringElement< Pixel, 3 > Kernel;
    typedef itk::DilateObjectMorphologyImageFilter<ImageType,ImageType,Kernel> Dilater;
    //typedef itk::BinaryDilateImageFilter<ImageType,ImageType,Kernel> Dilater;
    typedef itk::ErodeObjectMorphologyImageFilter<ImageType,ImageType,Kernel> Eroder;
    //typedef itk::BinaryErodeImageFilter<ImageType,ImageType,Kernel> Eroder;

    typedef itk::ImageFileReader<ImageType> Reader;
    typedef itk::ImageFileWriter<ImageType> Writer;

    if(argc != 4) {
        cerr << "Incorrect number of arguments" << endl
             << "Usage: close_filter <infile> <outfile> <radius (in voxels)>" << endl;
        return 1;
    }
    const char* infile = argv[1];
    const char* outfile = argv[2];
    const int radius = atoi(argv[3]);

    try {
        // Setup input
        cout << "Reading input file <" << infile << "> ... " << flush;
        Reader::Pointer reader = Reader::New();
        reader->SetFileName(infile);
        reader->Update();
        cout << "done" << endl;

        // Create the structuring element:
        cout << "Creating structuring element ... " << flush;
        Kernel ball;
        ball.SetRadius(radius);
        ball.CreateStructuringElement();
        cout << "done" << endl;

        // Now do the close
        cout << "Dilating ... " << flush;
        Dilater::Pointer closeDilate = Dilater::New();
        closeDilate->SetObjectValue(1);
        //closeDilate->SetForegroundValue(1);
        closeDilate->SetKernel(ball);
        closeDilate->SetInput(reader->GetOutput());
        closeDilate->Update();
        cout << "done" << endl;

        cout << "Eroding ... " << flush;
        Eroder::Pointer closeErode = Eroder::New();
        closeErode->SetObjectValue(1);
        //closeErode->SetForegroundValue(1);
        closeErode->SetKernel(ball);
        closeErode->SetInput(closeDilate->GetOutput());
        closeErode->Update();
        cout << "done" << endl;

        // Now write the output
        cout << "Writing output file <" << outfile << "> ... " << flush;
        Writer::Pointer writer = Writer::New();
        writer->SetFileName(outfile);
        writer->SetInput(closeErode->GetOutput());
        writer->Update();
        cout << "done" << endl;
    }
    catch (itk::ExceptionObject & exc) {
        // Show the error
        cerr << "Error processing image: " << exc.GetDescription () << endl;
    }

    return 0;
}
No tags attached.
? mandible.mha (58,329) 2010-03-09 23:39
https://public.kitware.com/Bug/file/2949/mandible.mha
Issue History
2010-03-09 23:39Rohit SabooNew Issue
2010-03-09 23:39Rohit SabooFile Added: mandible.mha
2010-10-25 16:17Gaetan LehmannStatusnew => assigned
2010-10-25 16:17Gaetan LehmannAssigned To => Gaetan Lehmann

There are no notes attached to this issue.