[ITK Community] [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://public.kitware.com/pipermail/community/attachments/20131112/913469f5/attachment.html>
-------------- next part --------------
_______________________________________________
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://kitware.com/products/protraining.php
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-developers
    
    
More information about the Community
mailing list