[Insight-users] Multilabel dilation

Richard Beare richard.beare at gmail.com
Wed Feb 13 04:34:04 EST 2013


The parallel classes for this are now on InsightJournal. Article
includes some comparisons - hope it helps:

http://hdl.handle.net/10380/3399


On Tue, Feb 12, 2013 at 8:20 AM, Dženan Zukić <dzenanz at gmail.com> wrote:
> 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)
>>
>>
>


More information about the Insight-users mailing list