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

elhadj meljane elhadj.meljane at gmail.com
Tue Nov 12 14:26:18 EST 2013


Hello!
I am using your github extension (I included the files manually in my
project)... and wrote the main method below. The code compile but at the
run time I got the error:

"program.exe has stopped working. A problem caused the program to stop
working correctly. Windows will close the program and notify you if a
solution is available. "
When I click to debug with MS Visual Studio, I got the warning:
Unhandled exception at 0x01... in program.exe: 0xC00000005: Acces violation
reading location 0x18...

Here's the code:


#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "itkBoundingBoxImageLabelMapFilter.h"

#include "itkAttributeImageLabelObject.h"

#include "itkBinaryImageToShapeLabelMapFilter.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;

  int main( int argc, char *argv[] )

{

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

typedef itk::ImageFileWriter< OutputImageType > WriterType;

 //input

reader->SetFileName( argv[1] );

 //label image

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

labelerAttribute->SetInput( reader->GetOutput() );

labelerAttribute->SetComputePerimeter( false );

labelerAttribute->SetOutputBackgroundValue(0);

labelerAttribute->Update();

LabelMapAttributeType::Pointer labelMapAttribute =
labelerAttribute->GetOutput();

 //extract the component with the label 1

BBILabelMapFilter::Pointer toBBILabelMap = BBILabelMapFilter::New();

toBBILabelMap->SetInput(labelMapAttribute);

toBBILabelMap->Update();

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

 //write

WriterType::Pointer writer = WriterType::New();

writer->SetFileName( "copy_input.jpg" );

writer->SetInput( reader->GetOutput());

writer->Update();

 return 0;

}






On Tue, Nov 12, 2013 at 1:53 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:

> Hello,
>
> It appears that you are trying to use some code from my github extension:
>
> https://github.com/blowekamp/itkOBBLabelMap
>
> I am not sure where to begin helping you. You didn't include the run-time
> error message, and your code fragment is missing key parts. Can you post a
> minimal compilable example which illustrates the problem? Sometime just
> narrowing down you code to this part help you figure out your issue.
>
> Do the tests for the extension pass for you?
>
> Are you able to run the example?
>
>
> https://github.com/blowekamp/itkOBBLabelMap/blob/master/test/itkOBBExample.cxx
>
> Brad
>
>
> On Nov 12, 2013, at 1:43 PM, elhadj meljane <elhadj.meljane at gmail.com>
> wrote:
>
> 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
> _______________________________________________
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20131112/c1c422b1/attachment.htm>


More information about the Insight-developers mailing list