[Insight-users] Error when repeatedly calling BinaryImageToLabelMapFilter
Jagir Hussan
r.jagir at auckland.ac.nz
Wed Feb 8 23:32:25 EST 2012
Hi,
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!!
terminate called after throwing an instance of 'itk::ExceptionObject'
what():
/home/rjag008/usr/include/ITK-4.0/itkBinaryThresholdImageFilter.hxx:273:
itk::ERROR: BinaryThresholdImageFilter(0x1979790): Lower threshold
cannot be greater than upper threshold.
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.
Thanks and Regards
Jagir
ImageType::Pointer getLargestComponent( ImageType::Pointer image) {
BinaryImageToLabelMapFilterType::Pointer
binaryImageToLabelMapFilter =
BinaryImageToLabelMapFilterType::New();
binaryImageToLabelMapFilter->SetInput(image);
binaryImageToLabelMapFilter->Update();
LabelMapToLabelImageFilterType::Pointer
labelMapToLabelImageFilter =
LabelMapToLabelImageFilterType::New();
labelMapToLabelImageFilter->SetInput(
binaryImageToLabelMapFilter->GetOutput());
labelMapToLabelImageFilter->Update();
LabelGeometryImageFilterType::Pointer labelGeometryImageFilter =
LabelGeometryImageFilterType::New();
labelGeometryImageFilter->SetInput(
labelMapToLabelImageFilter->GetOutput());
labelGeometryImageFilter->SetIntensityInput(image);
labelGeometryImageFilter->CalculatePixelIndicesOn();
labelGeometryImageFilter->CalculateOrientedBoundingBoxOn();
labelGeometryImageFilter->CalculateOrientedLabelRegionsOn();
labelGeometryImageFilter->Update();
LabelGeometryImageFilterType::LabelsType allLabels =
labelGeometryImageFilter->GetLabels();
LabelGeometryImageFilterType::LabelsType::iterator allLabelsIt;
//Find the largest component's (has the maximum Integrated
intensity) pixel Index
LabelGeometryImageFilterType::LabelPixelType maxVolLabel =
*(allLabels.begin());
double max_val = labelGeometryImageFilter->GetIntegratedIntensity(
maxVolLabel);
for (allLabelsIt = allLabels.begin(); allLabelsIt !=
allLabels.end();
allLabelsIt++) {
LabelGeometryImageFilterType::LabelPixelType labelValue =
*allLabelsIt;
if (labelGeometryImageFilter->GetVolume(labelValue) >
max_val) {
maxVolLabel = labelValue;
max_val =
labelGeometryImageFilter->GetIntegratedIntensity(
labelValue);
}
}
//Find the boundary points
const LabelGeometryImageFilterType::LabelIndicesType
pixelIndices =
labelGeometryImageFilter->GetPixelIndices(maxVolLabel);
ImageType::Pointer mImage = ImageType::New();
ImageType::IndexType start;
start.Fill(0);
ImageType::SizeType size =
image->GetLargestPossibleRegion().GetSize();
ImageType::RegionType region(start, size);
mImage->SetRegions(region);
mImage->Allocate();
mImage->FillBuffer(255);
int numpixels = pixelIndices.size();
for (int i = 0; i < numpixels; i++) {
//Set the pixels to black in masked Image
mImage->SetPixel(pixelIndices[i], 0);
}
return mImage;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120209/c621e258/attachment.htm>
More information about the Insight-users
mailing list