[Insight-users] Labeling an image and displaying results with distinguished levels of gray/colors

Luis Ibanez luis.ibanez at kitware.com
Thu Dec 3 21:51:52 EST 2009


Hi James,


There are three easy methods for coloring an image of labels.


Method A:

    Use the method illustrated in the example:

            Insight/Examples/Segmentation/WatershedSegmentation1.cxx

    namely:

  typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long>
    ColorMapFunctorType;
  typedef itk::UnaryFunctorImageFilter<LabeledImageType,
    RGBImageType, ColorMapFunctorType> ColorMapFilterType;
  ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();



Method B:

    Use the tkScalarToRGBColormapImageFilter.h class in the
    directory:

               Insight/Code/Review

     This filter is described in the following Insight Journal paper:

           http://www.insight-journal.org/browse/publication/285




Method C:

     Use the filter

              Insight/Code/Review/
                      itkLabelToRGBImageFilter.h

      that is described in the Insight Journal paper:

                http://www.insight-journal.org/browse/publication/176



If you are planning on doing extensive work with labeled images,
you may want to use Method C, and get familiar with the associated
Insight Journal paper, since it provides a very rich collection of classes
and filters for dealing with labeled images.


          Regards,


                Luis


--------------------------------------------------------------------------------------
On Thu, Dec 3, 2009 at 5:36 AM, Malsoaz James <jmalsoaz at yahoo.fr> wrote:

> Hello, I'm trying to label a binary image. For that, I have been using
> ConnectedComponentImageFilter and RelabelComponentImageFilter with no
> problem apparently.
>
> I'm able to get the number of objects and the size of them. But I can't
> figure out how to display the objects found in the image with different
> levels of gray (prefered solution) or different colors. Indeed, I'm getting
> an almost black image where I can difficultly distinguish the objects.
>
> I would really appreciate some help to solve this.
> Thank you.
> James
>
> By the way, here is my code:
>
> typedef unsigned char PixelType;
> typedef itk::Image<PixelType, 2> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::ImageFileWriter<ImageType> WriterType;
> typedef itk::ConnectedComponentImageFilter <ImageType, ImageType>
> LabelType;
> typedef itk::RelabelComponentImageFilter <ImageType, ImageType>
> RelabelType;
>
>
> int main(int argc, char *argv[])
> {
>     ReaderType::Pointer reader = ReaderType::New();
>     WriterType::Pointer writer = WriterType::New();
>     LabelType::Pointer labeler = LabelType::New();
>     RelabelType::Pointer relabeler = RelabelType::New();
>
>     reader->SetFileName("input.bmp");
>
>     labeler->SetInput(reader->GetOutput());
>     labeler->Update();
>
>     relabeler->SetInput(labeler->GetOutput());
>     relabeler->Update();
>
>     for (unsigned int i=0; i<relabeler->GetNumberOfObjects(); i++)
>     {
>         std::cout<<"Number of pixel for object "<<i<<":
> "<<relabeler->GetSizeOfObjectsInPixels()[i]<<std::endl;
>     }
>     writer->SetFileName("output.bmp");
>     writer->SetInput(relabeler->GetOutput());
>     writer->Update();
>     return EXIT_SUCCESS;
>
> }
>
>
> _____________________________________
> 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://www.kitware.com/products/protraining.html
>
> 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-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091203/77c03c5e/attachment.htm>


More information about the Insight-users mailing list