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