[Insight-users] using itkLabelOverlayImageFilter

john smith mkitkinsightuser at gmail.com
Thu Jun 30 09:07:48 EDT 2011


Well I have found the solution to my problem. When I have an initial image
in 2D and a labek image as a result of the segmentaion. In order to add the
contour of the label image in the initial image, I type the followings....


/////////  code /////////////
 typedef itk::Image<unsigned char, 2>  ImageType;
   ImageType::Pointer image1 = ImageType::New();
   ImageType::Pointer image_label = ImageType::New();

   typedef   unsigned char           InternalPixelType_add;
   const     unsigned int    Dimension = 2;
   typedef itk::Image< InternalPixelType_add, Dimension >
InternalImageType_add;
   typedef  itk::ImageFileReader< InternalImageType_add > ReaderType_add;

    ReaderType_add::Pointer reader1 = ReaderType_add::New();
    reader1->SetFileName( fileName.toStdString()  );
    reader1->Update();
    image1 = reader1->GetOutput();

    ReaderType_add::Pointer reader2 = ReaderType_add::New();
    reader2->SetFileName( "result.png"  );
    reader2->Update();
    image_label = reader2->GetOutput();


  typedef itk::RGBPixel<unsigned char> RGBPixelType;
  typedef itk::Image<RGBPixelType> RGBImageType;

  typedef itk::LabelOverlayImageFilter<ImageType, ImageType, RGBImageType>
                                       LabelOverlayImageFilterType;
  LabelOverlayImageFilterType::Pointer labelOverlayImageFilter =
LabelOverlayImageFilterType::New();
  labelOverlayImageFilter->SetInput(image1);
  labelOverlayImageFilter->SetLabelImage(image_label);
 // labelOverlayImageFilter->SetOpacity(.5);
  labelOverlayImageFilter->SetOpacity(1.0);
  labelOverlayImageFilter->ResetColors(); // reset color map
  labelOverlayImageFilter->AddColor(0, 0, 255); // fill color map with blue
  labelOverlayImageFilter->SetBackgroundValue(0); // don't overlay the
background, i.e., label 0
  labelOverlayImageFilter->Update();

  typedef  itk::ImageFileWriter< RGBImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("output.png");
  writer->SetInput(labelOverlayImageFilter->GetOutput());
  writer->Update();

   destroyed(ui->graphicsView_resultImage);
    ui->graphicsView_resultImage->setScene(scene_result=new Canvas());
    QPixmap tmpmap (QPixmap("output.png"));
    pixmapItem_result = scene_result->addPixmap (tmpmap.scaled
(ui->graphicsView_resultImage->width(),ui->graphicsView_resultImage->height()));
    ui->graphicsView_resultImage->setScene(scene_result);

2011/6/29 john smith <mkitkinsightuser at gmail.com>

> Could somebody explain what exactly do itkLabelOverlayImageFilter?  I have
> written the following code but still I get this error
> * error C2296: '%' : illegal, left operand has type 'const float'
> *
> I hope somebody could help.
> Thanks*
>
> ////////////////code/////////////////////
> *
> *  typedef   float           InternalPixelType;
>   const     unsigned int    Dimension = 2;
>   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
>   typedef  itk::ImageFileReader< InternalImageType > ReaderType;*
> *
>  ReaderType::Pointer reader1 = ReaderType::New();
>     reader1->SetFileName( fileName.toStdString()  );
>     reader1->Update();
>
>    InternalImageType::Pointer image1 = reader1->GetOutput();
>
>
>    ReaderType::Pointer reader2 = ReaderType::New();
>    reader2->SetFileName( "result.png"  );
>    reader2->Update();
>
>    InternalImageType::Pointer image2 = reader2->GetOutput();
>
>    typedef itk::RGBPixel<unsigned char> RGBPixelType;
>   typedef itk::Image<RGBPixelType> RGBImageType;
>
>  typedef itk::LabelOverlayImageFilter<InternalImageType, InternalImageType,
> RGBImageType> LabelOverlayFilterType;
>   LabelOverlayFilterType::Pointer labelOverlayFilter =
> LabelOverlayFilterType::New();
>   labelOverlayFilter->SetInput(image1);
>   labelOverlayFilter->SetLabelImage(image2);
>   labelOverlayFilter->SetOpacity(1.0);
>   labelOverlayFilter->ResetColors(); // reset color map
>   labelOverlayFilter->AddColor(0, 0, 255); // fill color map with blue
>   labelOverlayFilter->SetBackgroundValue(0); // don't overlay the
> background, i.e., label 0
>   labelOverlayFilter->Update();
>
>   typedef  itk::ImageFileWriter< RGBImageType  > WriterType_RGB;
>   WriterType_RGB::Pointer writer_RGB = WriterType_RGB::New();
>   writer_RGB->SetFileName("addImage.png");
>   writer_RGB->SetInput(labelOverlayFilter->GetOutput());
>   writer_RGB->Update();*
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110630/538db11e/attachment.htm>


More information about the Insight-users mailing list