[Insight-users] Multilabel dilation

Dženan Zukić dzenanz at gmail.com
Mon Feb 11 16:20:30 EST 2013


Today I finally managed to try it myself, and it works. Below is
implementation in ITK, if anyone needs it.

typedef itk::Image<unsigned char, 3> VisualizingImageType;
typedef itk::Image<float, 3> InternalImageType;

//function call example
std::vector<VisualizingImageType::IndexType> centers;
for (int i=0; i<vertebra.size(); i++)
centers.push_back(vertebra[i]->centerIndex);
VisualizingImageType::Pointer vInfluence=multilabelDilation(region, 50,
centers);


VisualizingImageType::Pointer multilabelDilation(itk::ImageRegion<3>
region, float radius, std::vector<VisualizingImageType::IndexType> points)
{
    typedef
itk::BinaryBallStructuringElement<VisualizingImageType::PixelType,3>
BallType;
    BallType ball;
    ball.SetRadius(radius);
    ball.CreateStructuringElement();
    typedef itk::BinaryDilateImageFilter<VisualizingImageType,
VisualizingImageType, BallType> growType;
    growType::Pointer grow=growType::New();
    grow->SetKernel(ball); //grow->SetRadius(radius);

    VisualizingImageType::Pointer image=VisualizingImageType::New();
    image->SetRegions(region);
    image->Allocate();
    image->FillBuffer(0);
    for (int i=0; i<points.size(); i++)
        image->SetPixel(points[i], grow->GetDilateValue());

    grow->SetInput(image);
    grow->Update();
    writeImage(grow->GetOutput(), "1dilate.nrrd"); //debug

    typedef itk::SignedMaurerDistanceMapImageFilter<VisualizingImageType,
InternalImageType> DistanceMapType;
    DistanceMapType::Pointer dm=DistanceMapType::New();
    dm->SetInput(image);
    dm->SetUseImageSpacing(true);
    dm->InsideIsPositiveOff();
    dm->Update();
    writeImage(dm->GetOutput(), "2distanceMap.nrrd"); //debug

    for (int i=0; i<points.size(); i++)
        image->SetPixel(points[i], i+1); //now set index+1

    typedef
itk::MorphologicalWatershedFromMarkersImageFilter<InternalImageType,
VisualizingImageType> morphoWSfMType;
    morphoWSfMType::Pointer ws=morphoWSfMType::New();
    ws->SetInput1(dm->GetOutput());
    ws->SetInput2(image);
    ws->Update();
    writeImage(ws->GetOutput(), "3watershed.nrrd"); //debug

    typedef itk::AndImageFilter<VisualizingImageType> AndType;
    AndType::Pointer and=AndType::New();
    and->SetInput1(ws->GetOutput());
    and->SetInput2(grow->GetOutput());
    and->Update();
    writeImage(and->GetOutput(), "4multiplied.nrrd"); //debug

    return and->GetOutput();
}


On Fri, Feb 8, 2013 at 11:36 AM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:

> Unfortunately, my helpful e-mail was too big to make it to the list. So
> here is the important bit, which defines a function in Python with
> SimpleITK:
>
> def MultilabelDilation(img, radius=1,kernel=sitk.BinaryDilateImageFilter.Ball):
>
>
>     distImg = sitk.SignedMaurerDistanceMap(img != 0, insideIsPositive=False, squaredDistance=False, useImageSpacing=False)
>
>
>     dilatImg = sitk.BinaryDilate(img!=0, radius, kernel)
>
>
>     wsImg = sitk.MorphologicalWatershedFromMarkers(distImg, img)
>
>
>     return dilatImg*wsImg
>
>
>
>
> On Feb 8, 2013, at 9:42 AM, Dženan Zukić <dzenanz at gmail.com> wrote:
>
> Thanks for the interest and the provided code Brad. Hopefully I will get
> to work today to try it out myself :D (Blizzard warning in Boston, where I
> am for a couple months)
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130211/9a080dff/attachment.htm>


More information about the Insight-users mailing list