[Insight-users] Gatens Label Object Representation and Manipulation

Christian Werner christian.werner at rwth-aachen.de
Sun Feb 28 17:56:47 EST 2010


Yes, this RGBPixel Type makes sense... :)

Unfortunately I am still fighting to get the LabelMapToRGBImageFilter 
make its work. Now that I fiddled around with this without success I 
tried the LabelMapToLabelImageFilter for a change and voila: that worked 
with exactly the same style of code! I am getting a labeled image with 
my objects painted in all shades of grey. But when using the RGB 
labeling I get black void.

I attached my code, maybe I am blind or still misunderstand something, 
but I really don't know how to fix this.

Best regards,
Christian




Gaëtan Lehmann wrote:
>
> Hi Christian,
>
> The output pixel type must be a RGBPixel. See an example at
>
>   
> http://public.kitware.com/cgi-bin/viewcvs.cgi/Testing/Code/Review/itkLabelToRGBImageFilterTest.cxx?revision=1.3&root=Insight&view=markup 
>
>
> Regards,
>
> Gaëtan
>
>
> Le 28 févr. 10 à 15:38, Christian Werner a écrit :
>
>> Hello!
>>
>> Thanks for your reply. The itk:: prefix indeed helped me getting a 
>> few lines further. Now I get errors when I want to instantiate a 
>> LabelToRGBImageType. I have attached my little program. Its simple 
>> purpose is to do some thresholding and then display all ojects in 
>> color and save the resulting file. It would be nice if you could help 
>> me here.
>>
>> The following errors all come from the very last line in the code 
>> before everything else is commented out.
>>
>>
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h: In 
>> constructor ‘itk::Functor::LabelToRGBFunctor<TLabel, 
>> TRGBPixel>::LabelToRGBFunctor() [with TLabel = unsigned int, 
>> TRGBPixel = unsigned char]’:                           
>> /home/christian/programming/itk/labeling/itkLabelMapToRGBImageFilter.cxx:42:   
>> instantiated from ‘void itk::LabelMapToRGBImageFilter<TInputImage, 
>> TOutputImage>::BeforeThreadedGenerateData() [with TInputImage = 
>> itk::LabelMap<itk::ShapeLabelObject<unsigned int, 2u> >, TOutputImage 
>> = itk::Image<unsigned char, 
>> 2u>]’                                        
>> /home/christian/programming/itk/labeling/testITK.cxx:75:   
>> instantiated from here                                    
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:51: 
>> error: ‘unsigned char’ is not a class, struct, or union type
>> /home/christian/programming/itk/labeling/itkLabelMapToRGBImageFilter.cxx:42:   
>> instantiated from ‘void itk::LabelMapToRGBImageFilter<TInputImage, 
>> TOutputImage>::BeforeThreadedGenerateData() [with TInputImage = 
>> itk::LabelMap<itk::ShapeLabelObject<unsigned int, 2u> >, TOutputImage 
>> = itk::Image<unsigned char, 2u>]’
>> /home/christian/programming/itk/labeling/testITK.cxx:75:   
>> instantiated from here
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:98: 
>> error: request for member ‘Fill’ in 
>> ‘((itk::Functor::LabelToRGBFunctor<unsigned int, unsigned 
>> char>*)this)->itk::Functor::LabelToRGBFunctor<unsigned int, unsigned 
>> char>::m_BackgroundColor’, which is of non-class type ‘unsigned char’
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:98: 
>> error: ‘unsigned char’ is not a class, struct, or union type
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:50: 
>> warning: unused variable ‘rgbPixel’
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h: In 
>> member function ‘void itk::Functor::LabelToRGBFunctor<TLabel, 
>> TRGBPixel>::AddColor(unsigned char, unsigned char, unsigned char) 
>> [with TLabel = unsigned int, TRGBPixel = unsigned char]’:
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:65:   
>> instantiated from ‘itk::Functor::LabelToRGBFunctor<TLabel, 
>> TRGBPixel>::LabelToRGBFunctor() [with TLabel = unsigned int, 
>> TRGBPixel = unsigned char]’
>> /home/christian/programming/itk/labeling/itkLabelMapToRGBImageFilter.cxx:42:   
>> instantiated from ‘void itk::LabelMapToRGBImageFilter<TInputImage, 
>> TOutputImage>::BeforeThreadedGenerateData() [with TInputImage = 
>> itk::LabelMap<itk::ShapeLabelObject<unsigned int, 2u> >, TOutputImage 
>> = itk::Image<unsigned char, 2u>]’
>> /home/christian/programming/itk/labeling/testITK.cxx:75:   
>> instantiated from here
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:118: 
>> error: ‘unsigned char’ is not a class, struct, or union type
>> /opt/InsightToolkit-3.16.0/Code/Review/itkLabelToRGBFunctor.h:122: 
>> error: request for member ‘Set’ in ‘rgbPixel’, which is of non-class 
>> type ‘unsigned char’
>>
>>
>>
>>
>> Gaëtan Lehmann wrote:
>>>
>>> Le 27 févr. 10 à 22:59, Christian Werner a écrit :
>>>
>>>> Hi!
>>>>
>>>> Yes, USE_REVIEW is on I am sure about that since I already built 
>>>> some libraries. I am using Debian Lenny and gcc 4.4.3. But maybe it 
>>>> is only because I misunderstand something.
>>>>
>>>> I see that I need label objects anyway, so it does not harm if I 
>>>> include them in my own code. But I was really confused about 
>>>> getting errors when just including a single header. Shouldn't this 
>>>> header take care of his own dependencies?
>>>>
>>>> Anyway, these 3 lines are the very beginning of my labeling try and 
>>>> these already produce errors:
>>>>
>>>> typedef itk::Image< unsigned char,  2 >   InputImageType;
>>>> ...
>>>> 56  typedef ShapeLabelObject<unsigned char, 2> LabelObjectType;
>>>> 57  typedef LabelMap< LabelObjectType >        LabelMapType;
>>>
>>> shouldn't you add the itk:: prefix to those typedefs?
>>>
>>> typedef itk::ShapeLabelObject<unsigned char, 2> LabelObjectType;
>>> typedef LabelMap< LabelObjectType >        LabelMapType;
>>>
>>> a few other notes:
>>>
>>> * you may be careful about the type used to store the labels - 
>>> unsigned char is likely to become quickly unable to store all the 
>>> labels in your image
>>> * when using ShapeLabelObject, it is convenient to use 
>>> BinaryImageToShapeLabelMapFilter instead of 
>>> BinaryImageToLabelMapFilter: the attribute values are computed with 
>>> a single filter, and it can be declared simply as
>>>
>>>  typedef itk::BinaryImageToLabelMapFilter<InputImageType> 
>>> ImageToLabelType;
>>>
>>> without much type declaration.
>>>
>>> Gaëtan
>>>
>>>> 58  typedef itk::BinaryImageToLabelMapFilter<InputImageType, 
>>>> LabelMapType> ImageToLabelType;
>>>> 59  //2)
>>>> 60  ImageToLabelType::Pointer image2LabelMap = 
>>>> ImageToLabelType::New();
>>>>
>>>> Compiler Errors:
>>>> /home/christian/programming/itk/labeling/testITK.cxx: In function 
>>>> ‘int main(int, char**)’:
>>>> /home/christian/programming/itk/labeling/testITK.cxx:56: error: 
>>>> expected initializer before ‘<’ token
>>>> /home/christian/programming/itk/labeling/testITK.cxx:57: error: 
>>>> expected initializer before ‘<’ token
>>>> /home/christian/programming/itk/labeling/testITK.cxx:58: error: 
>>>> ‘LabelMapType’ was not declared in this scope
>>>> /home/christian/programming/itk/labeling/testITK.cxx:58: error: 
>>>> template argument 2 is invalid
>>>> /home/christian/programming/itk/labeling/testITK.cxx:58: error: 
>>>> invalid type in declaration before ‘;’ token
>>>> /home/christian/programming/itk/labeling/testITK.cxx:60: error: 
>>>> expected initializer before ‘image2LabelMap’
>>>>
>>>> Maybe I don't get this labeling right... ?
>>>>
>>>> This is what I include now:
>>>>
>>>> #include "itkImageToImageFilter.h"
>>>> #include "itkShapeLabelObject.h"
>>>> #include "itkLabelMap.h"
>>>> #include "itkBinaryImageToLabelMapFilter.h"
>>>> #include "itkLabelMapToRGBImageFilter.h"
>>>>
>>>>
>>>>
>>>> Bill Lorensen wrote:
>>>>> When you configured ITK did you build with USE_REVIEW ON?
>>>>>
>>>>> If so, what platform/compiler are you using?
>>>>>
>>>>> Bill
>>>>>
>>>>> On Sat, Feb 27, 2010 at 2:24 PM, Christian Werner
>>>>> <christian.werner at rwth-aachen.de> wrote:
>>>>>
>>>>>> Hello!
>>>>>>
>>>>>> I am off to make some serious object labling and manipulation. 
>>>>>> Unfortunately
>>>>>> some very basic code does not compile:
>>>>>>
>>>>>> #include "itkBinaryImageToLabelMapFilter.h"
>>>>>> int main( int argc, char * argv[] )
>>>>>> {
>>>>>> }
>>>>>>
>>>>>> christian at trinity:~/programming/itk/labeling/bin$ make -j2
>>>>>> Scanning dependencies of target testITK
>>>>>> [100%] Building CXX object CMakeFiles/testITK.dir/testITK.o
>>>>>> In file included from
>>>>>> /home/christian/programming/itk/labeling/testITK.cxx:2:
>>>>>> /opt/InsightToolkit-3.16.0/Code/Review/itkBinaryImageToLabelMapFilter.h:54: 
>>>>>>
>>>>>> error: expected type-specifier before ‘LabelMap’
>>>>>> /opt/InsightToolkit-3.16.0/Code/Review/itkBinaryImageToLabelMapFilter.h:54: 
>>>>>>
>>>>>> error: expected ‘>’ before ‘LabelMap’
>>>>>> make[2]: *** [CMakeFiles/testITK.dir/testITK.o] Error 1
>>>>>> make[1]: *** [CMakeFiles/testITK.dir/all] Error 2
>>>>>> make: *** [all] Error 2
>>>>>>
>>>>>> I can fix this, when I edit (and this already feels bad) the
>>>>>> itkBinaryImageToLabelMapFilter.h by adding
>>>>>>
>>>>>> #include "itkLabelMap.h"
>>>>>> #include "itkLabelObject.h"
>>>>>>
>>>>>> The above code compiles this way. However if I actually use some 
>>>>>> functions
>>>>>> out of the itkBinaryImageToLabelMapFilter.h I get errors over 
>>>>>> errors.
>>>>>>
>>>>>> My CMakeLists looks like this:
>>>>>>
>>>>>> cmake_minimum_required(VERSION 2.4)
>>>>>>
>>>>>> PROJECT(testITK)
>>>>>>
>>>>>> FIND_PACKAGE(ITK REQUIRED)
>>>>>> IF(ITK_FOUND)
>>>>>> INCLUDE(${ITK_USE_FILE})
>>>>>> ENDIF(ITK_FOUND)
>>>>>>
>>>>>> ADD_EXECUTABLE(testITK testITK.cxx)
>>>>>>
>>>>>> TARGET_LINK_LIBRARIES(testITK ITKCommon ITKIO ITKBasicFilters 
>>>>>> ITKStatistics)
>>>>>>
>>>>>>
>>>>>> General ITK programming works without trouble. I must be doing 
>>>>>> something
>>>>>> totally wrong, any suggestions?
>>>>>>
>>>>>>
>>>>>> Best regards,
>>>>>> Christian
>>>>>>
>>>>>>
>>>>>> _____________________________________
>>>>>> 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
>>>>>>
>>>>>>
>>>>
>>>> _____________________________________
>>>> 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
>>>
>>
>> #include "itkImage.h"
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>>
>> #include "itkBinaryThresholdImageFilter.h"
>>
>> #include "itkImageToImageFilter.h"
>> #include "itkShapeLabelObject.h"
>> #include "itkLabelMap.h"
>> #include "itkBinaryImageToLabelMapFilter.h"
>> #include "itkLabelMapToRGBImageFilter.h"
>>
>> int main( int argc, char * argv[] )
>> {
>>  if( argc < 5 )
>>    {
>>    std::cerr << "Usage: " << argv[0];
>>    std::cerr << " inputImageFile outputImageFile ";
>>    std::cerr << " lowerThreshold upperThreshold " << std::endl;
>>    //std::cerr << " outsideValue insideValue   "  << std::endl;
>>    return EXIT_FAILURE;
>>    }
>>
>>  typedef  unsigned char  InputPixelType;
>>  typedef  unsigned char  OutputPixelType;
>>  typedef itk::Image< InputPixelType,  2 >   InputImageType;
>>  typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
>>  typedef itk::BinaryThresholdImageFilter<
>>               InputImageType, OutputImageType >  FilterType;
>>  typedef itk::ImageFileReader< InputImageType >  ReaderType;
>>  typedef itk::ImageFileWriter< OutputImageType >  WriterType;
>>
>>  ReaderType::Pointer reader = ReaderType::New();
>>  FilterType::Pointer filter = FilterType::New();
>>
>>  reader->SetFileName( argv[1] );
>>
>>  /// filtering
>>  filter->SetInput( reader->GetOutput() );
>>  const OutputPixelType outsideValue = 0;
>>  const OutputPixelType insideValue  = 255;
>>  filter->SetOutsideValue( outsideValue );
>>  filter->SetInsideValue(  insideValue  );
>>  const InputPixelType lowerThreshold = atoi(argv[3]);
>>  const InputPixelType upperThreshold = atoi(argv[4]);
>>
>>  filter->SetLowerThreshold( lowerThreshold );
>>  filter->SetUpperThreshold( upperThreshold );
>>  // Software Guide : EndCodeSnippet
>>
>>  filter->Update();
>>
>>  /// labeling
>>  //1)
>>  typedef itk::ShapeLabelObject<unsigned int, 2> LabelObjectType;
>>  typedef itk::LabelMap< LabelObjectType >       LabelMapType;
>>  typedef itk::BinaryImageToLabelMapFilter<InputImageType, 
>> LabelMapType> ImageToLabelType;
>>  typedef itk::LabelMapToRGBImageFilter<LabelMapType, 
>> OutputImageType>   LabelToRGBImageType;
>>  //2)
>>  ImageToLabelType::Pointer image2LabelMap    = ImageToLabelType::New();
>>  LabelToRGBImageType::Pointer label2RGBImage = 
>> LabelToRGBImageType::New();
>>  //image2LabelMap->SetInput( filter->getOutput() );
>>  //label2RGBImage->SetInput( image2LabelMap->getOutput() );
>>
>>  ///save result image
>>  //WriterType::Pointer writer = WriterType::New();
>>  //writer->SetInput( label2RGBImage->GetOutput() );
>>  //writer->SetFileName( argv[2] );
>>  //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 --------------
A non-text attachment was scrubbed...
Name: testITK.cxx
Type: text/x-c++src
Size: 3350 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100228/ee45f6a3/attachment.cxx>


More information about the Insight-users mailing list