[Insight-users] Still struggling with extracting information about objects resulting from a segmentation

Kishore Mosaliganti kishoreraom at gmail.com
Thu Mar 11 11:47:48 EST 2010


Hi Neal,

I am not sure if this is the problem, but can you insert and then try:

converter->SetBackgroundValue(0);
converter->Update();

Kishore


On Thu, Mar 11, 2010 at 11:27 AM, Neal R. Harvey <harve at lanl.gov> wrote:

> I am still struggling with getting the information I need about the various
> regions (objects) that
> I obtain from a segmentation.
> I am using ITK's watershed code to segment an image.
> Then, I want to calculate various attributes of each of the regions found
> in the segmentation.
> For attribute calculation, I am trying to use the ShapeLabelMapFilter, etc.
> as described in
> Lehmann's paper, entitled "Label Object Representation and Manipulation
> with ITK".
> Richard Beare offered some hints last time and I have been trying to use
> that, together with the
> information in the paper referred to above.
>
> Below is the snippet of code that I wrote that starts at the point where I
> have obtained a
> segmentation from the watershed algorithm. The code compiles with no
> problem.
> What I would expect that, if this was doing what I was hoping it would do,
> I would see
> the same number of objects being reported from the ShapeLabelMapFilter as
> the number
> of regions that is getting reported from the watershed segmentation.
> However, I get the
> number of objects reported from the ShapeLabelMapFilter as zero.
>
> Can anyone suggest a fix or has any idea as to what I am doing wrong?
>
> On a slightly different, but related (i.e. it isn't a problem at the
> moment, as the problem
> described above is not allowing the calculation of the object attributes,
> as it doesn't
> think there are any object), is if I include calls to GetFeretDiameter() or
> GetEquivalentRadius()
> the code won't even compile!
>
>  WatershedFilter->SetLevel( watershedLevel );
>  WatershedFilter->SetThreshold( watershedThreshold );
>  WatershedFilter->SetInput( TemporaryImage );
>  WatershedFilter->Update();
>
>  // The output of the watershed is an image of unsigned long int
>
>  typedef unsigned long       WatershedPixelType;
>
>  typedef itk::Image< WatershedPixelType, Dimension >
> WatershedImageType;
>
>  WatershedImageType::Pointer WatershedImage = WatershedFilter->GetOutput();
>
>  //  Below we instantiate the MinimumMaximumImageCalculator class
>
>  typedef itk::MinimumMaximumImageFilter< WatershedImageType >
> MinimumMaximumWatershedImageFilterType;
>
>  // A MinimumMaximumWatershedImageFilter object is constructed
>
>  MinimumMaximumWatershedImageFilterType::Pointer
> MinimumMaximumWatershedImageFilter =
> MinimumMaximumWatershedImageFilterType::New();
>
>  MinimumMaximumWatershedImageFilter->SetInput( WatershedImage );
>
>  MinimumMaximumWatershedImageFilter->Update();
>
>  WatershedPixelType outputMinVal =
> MinimumMaximumWatershedImageFilter->GetMinimum();
>  WatershedPixelType outputMaxVal =
> MinimumMaximumWatershedImageFilter->GetMaximum();
>
>  std::cerr << "Minimum Value from Segmented Image = " << (int)outputMinVal
> << std::endl;
>  std::cerr << "Maximum Value from Segmented Image = " << (int)outputMaxVal
> << std::endl;
>
>  // OK So, now we have a labeled image output from the watershed
>  // We now want to calculate various characteristics of the objects in the
>  // labeled image
>
>  typedef unsigned long LabelType;
>  typedef itk::ShapeLabelObject< LabelType, Dimension > LabelObjectType;
>  typedef itk::LabelMap< LabelObjectType > LabelMapType;
>
>  // First we need to convert the output from the watershed filter to a
>  // collection of label objects
>
>  typedef itk::LabelImageToShapeLabelMapFilter< WatershedImageType,
> LabelMapType > ConverterType;
>  ConverterType::Pointer converter = ConverterType::New();
>  converter->SetInput( WatershedImage );
>
>  // Then, can we evaluate the attributes with the dedicated filtr:
> ShapeLabelMapFilter?
>  typedef itk::ShapeLabelMapFilter< LabelMapType > ShapeFilterType;
>  ShapeFilterType::Pointer shape = ShapeFilterType::New();
>  shape->SetInput( converter->GetOutput() );
>
>  shape->Update();
>
>  LabelMapType::Pointer labelMap = converter->GetOutput();
>
>  unsigned int NumberOfLabelObjects = labelMap->GetNumberOfLabelObjects();
>
>  std::cout << "labelMap->GetNumberOfLabelObjects() = " <<
> NumberOfLabelObjects << std::endl;
>
>  if (NumberOfLabelObjects < 1) {
>
>   std::cerr << "Number of Label Objects is incorrect" << std::endl;
>
>   return EXIT_FAILURE;
>
>  } else {
>
>   for (unsigned int label = 1; label <= NumberOfLabelObjects; label++) {
>     const LabelObjectType * labelObject = labelMap->GetLabelObject( label
> );
>
>     //"; FeretDiameter = " << labelObject->GetFeretDiameter() << ";
> EquivalentRadius = " << labelObject->GetEquivalentRadius()  <<
>
>     std::cout << "Label #: " << label << "; Size = " <<
> labelObject->GetSize() << "; Perimeter = " << labelObject->GetPerimeter() <<
> std::endl;
>         return EXIT_SUCCESS;
>
>   }
>
>  }
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100311/473a5211/attachment.htm>


More information about the Insight-users mailing list