<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 13px;" lang="x-western">Hi,
<br>
I call the following routine to determine the largest
component in an image. I get the following exception when I call
the routine the 16th time!!
<br>
<br>
terminate called after throwing an instance of
'itk::ExceptionObject'
<br>
what():
/home/rjag008/usr/include/ITK-4.0/itkBinaryThresholdImageFilter.hxx:273:
<br>
itk::ERROR: BinaryThresholdImageFilter(0x1979790): Lower threshold
cannot be greater than upper threshold.
<br>
<br>
I have passed different images and also tried passing the same
image 16 times. The exception is consistently thrown the 16 time.
I would be extremely grateful if any one could give me some
insight into this issue.
<br>
<br>
Thanks and Regards
<br>
Jagir
<br>
<br>
<br>
ImageType::Pointer getLargestComponent( ImageType::Pointer image)
{
<br>
<br>
BinaryImageToLabelMapFilterType::Pointer
binaryImageToLabelMapFilter =
<br>
BinaryImageToLabelMapFilterType::New();
<br>
<br>
binaryImageToLabelMapFilter->SetInput(image);
<br>
binaryImageToLabelMapFilter->Update();
<br>
<br>
LabelMapToLabelImageFilterType::Pointer
labelMapToLabelImageFilter =
<br>
LabelMapToLabelImageFilterType::New();
<br>
labelMapToLabelImageFilter->SetInput(
<br>
binaryImageToLabelMapFilter->GetOutput());
<br>
labelMapToLabelImageFilter->Update();
<br>
<br>
LabelGeometryImageFilterType::Pointer
labelGeometryImageFilter =
<br>
LabelGeometryImageFilterType::New();
<br>
labelGeometryImageFilter->SetInput(
<br>
labelMapToLabelImageFilter->GetOutput());
<br>
<br>
labelGeometryImageFilter->SetIntensityInput(image);
<br>
<br>
labelGeometryImageFilter->CalculatePixelIndicesOn();
<br>
labelGeometryImageFilter->CalculateOrientedBoundingBoxOn();
<br>
labelGeometryImageFilter->CalculateOrientedLabelRegionsOn();
<br>
<br>
labelGeometryImageFilter->Update();
<br>
<br>
LabelGeometryImageFilterType::LabelsType allLabels =
<br>
labelGeometryImageFilter->GetLabels();
<br>
LabelGeometryImageFilterType::LabelsType::iterator
allLabelsIt;
<br>
<br>
//Find the largest component's (has the maximum Integrated
intensity) pixel Index
<br>
LabelGeometryImageFilterType::LabelPixelType maxVolLabel =
<br>
*(allLabels.begin());
<br>
<br>
double max_val =
labelGeometryImageFilter->GetIntegratedIntensity(
<br>
maxVolLabel);
<br>
<br>
for (allLabelsIt = allLabels.begin(); allLabelsIt !=
allLabels.end();
<br>
allLabelsIt++) {
<br>
LabelGeometryImageFilterType::LabelPixelType
labelValue =
<br>
*allLabelsIt;
<br>
if (labelGeometryImageFilter->GetVolume(labelValue)
> max_val) {
<br>
maxVolLabel = labelValue;
<br>
max_val =
labelGeometryImageFilter->GetIntegratedIntensity(
<br>
labelValue);
<br>
}
<br>
<br>
}
<br>
<br>
//Find the boundary points
<br>
const LabelGeometryImageFilterType::LabelIndicesType
pixelIndices =
<br>
labelGeometryImageFilter->GetPixelIndices(maxVolLabel);
<br>
<br>
<br>
ImageType::Pointer mImage = ImageType::New();
<br>
<br>
ImageType::IndexType start;
<br>
start.Fill(0);
<br>
<br>
ImageType::SizeType size =
image->GetLargestPossibleRegion().GetSize();
<br>
<br>
ImageType::RegionType region(start, size);
<br>
mImage->SetRegions(region);
<br>
mImage->Allocate();
<br>
mImage->FillBuffer(255);
<br>
<br>
<br>
int numpixels = pixelIndices.size();
<br>
for (int i = 0; i < numpixels; i++) {
<br>
//Set the pixels to black in masked Image
<br>
mImage->SetPixel(pixelIndices[i], 0);
<br>
}
<br>
<br>
return mImage;
<br>
}
<br>
<br>
</div>
</body>
</html>