[Insight-developers] select an item from a binary image

elhadj meljane elhadj.meljane at gmail.com
Tue Nov 12 13:43:03 EST 2013


Hi all,
I am trying to use itk to select a component from a binary image. The
binary image contains several items and I want to separate them in
different images.

I used the code below but it doesn't work. I got an error message at the
run time. It looks from the debugger that the line

labelerAttribute->Update()

causes the error. I gave a valid file as input and  checked that ITK reads
correctly this file.  I would appreciate your help to fix this!


#include "itkAttributeImageLabelObject.h"

const      unsigned int    Dimension = 2;
typedef  unsigned char LabelPixelType;
typedef  itk::Image< LabelPixelType, Dimension >  LabelImageType;
typedef  unsigned char                           OutputPixelType;
typedef  itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef   itk::ImageFileReader< OutputImageType > ReaderType;
typedef   itk::ImageFileWriter<  OutputImageType  > WriterType;
typedef  itk::AttributeImageLabelObject< LabelPixelType, Dimension,
OutputImageType > LabelObjectAttributeType;
typedef  itk::LabelMap<LabelObjectAttributeType> LabelMapAttributeType;
typedef  itk::BinaryImageToShapeLabelMapFilter
   <OutputImageType, LabelMapAttributeType>  LabelMapperAttributeType;
typedef  itk::LabelMapToLabelImageFilter<LabelMapAttributeType,
OutputImageType> LabelMapToLabelImageFilterType;
typedef  itk::BoundingBoxImageLabelMapFilter<LabelMapAttributeType>
BBILabelMapFilter;
typedef   itk::ImageFileWriter<  OutputImageType  > WriterType;

ReaderType::Pointer reader = ReaderType::New();

reader->SetFileName( argv[1] );

LabelMapperAttributeType::Pointer labelerAttribute =
LabelMapperAttributeType::New();

labelerAttribute->SetInput( reader->GetOutput() );
labelerAttribute->SetComputePerimeter( false );
labelerAttribute->SetOutputBackgroundValue(0);
labelerAttribute->Update();


//select the item with the label 1

const LabelObjectAttributeType* labelObjectAttribute =
toBBILabelMap->GetOutput()->GetLabelObject(1);

BBILabelMapFilter::Pointer toBBILabelMap =  BBILabelMapFilter::New();
toBBILabelMap->SetInput(labelMapAttribute);
toBBILabelMap->Update();


Thanks.
Best
EM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20131112/913469f5/attachment.htm>


More information about the Insight-developers mailing list