[Insight-users] problems with morphological close

Rohit Saboo rohit at cs.unc.edu
Mon Mar 1 19:04:05 EST 2010


Hello:

I'm trying to do a morphological close by dilating the input image and then
following it with the input image. However, it seems that I'm not using the
filters properly because the results don't look like the result of a close
operation. Can someone point out to me what I'm doing wrong.

Axial slices of the images (at the same position) are at the following
locations:
1. original image   -  http://www.cs.unc.edu/~rohit/stuff/original.png
2. (intermediate) dilated image   -
http://www.cs.unc.edu/~rohit/stuff/dilated.png
3. (final) closed image   -  http://www.cs.unc.edu/~rohit/stuff/closed.png

I'm including the parts of the code related to the close operation. The
function below is called with a radius of 1.

typedef unsigned short Pixel;
typedef Image<Pixel, 3> ImageType;
typedef ImageType::Pointer ImagePointer;

ImagePointer closeImage( ImagePointer image, const unsigned int radius )
{
    // The ball structuring element:
    typedef BinaryBallStructuringElement<Pixel, 3> Kernel;
    // The dilation filter
    typedef DilateObjectMorphologyImageFilter<ImageType, ImageType, Kernel>
DilateFilter;
    // The erosion filter
    typedef ErodeObjectMorphologyImageFilter<ImageType, ImageType, Kernel>
ErodeFilter;

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

    writeImage<ImageType>(image, "original.mhd");

    // Now do the close operation
    cout << "Dilating ... " << flush;
    DilateFilter::Pointer closeDilate   = DilateFilter::New();
    closeDilate->SetObjectValue(1);
    closeDilate->SetKernel(ball);
    closeDilate->SetInput(image);
    closeDilate->Update();
    cout << "done" << endl;
    writeImage<ImageType>(closeDilate->GetOutput(), "dilated.mhd");

    cout << "Eroding ... " << flush;
    ErodeFilter::Pointer closeErode = ErodeFilter::New();
    closeErode->SetObjectValue(1);
    closeErode->SetKernel(ball);
    closeErode->SetInput(closeDilate->GetOutput());
    closeErode->Update();
    cout << "done" << endl;
    writeImage<ImageType>(closeErode->GetOutput(), "closed.mhd");

    return closeErode->GetOutput();
}


Rohit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100301/3ef03678/attachment.htm>


More information about the Insight-users mailing list