[Insight-developers] Question regarding itkColorTable

Luis Ibanez luis.ibanez at kitware.com
Thu Jan 14 13:41:13 EST 2010


Hi James,

Thanks for pointing this out.

You are right this looks like a bug.


It was probably thought for the case of "unsigned char"
types, where "max()" will make sense.


The following couple of options
come to mind for fixing this issue:

1) Have member variables
     * m_ComponentMinimum
     * m_ComponentMaximum

   that will be initialized by default in the constructor
   to the values

       NumericTraits<TPixel>::NonpositiveMin(),
       NumericTraits<TPixel>::max())

   respectively,

    and that could also be set by the user via
    SetMacro()  methods.


OR


2)  Provide specialized ColorTraits<> classes
     that will define the proper Min and Max values
     for every type.



The advantage of the first method is that it is
more flexible.

The advantage of the second method is that
it will choose the "best" values by default.


 What do you think of these two options ?



        Thanks



             Luis



-----------------------------------------------------------
On Wed, Dec 23, 2009 at 11:00 AM, James Ross <jross at bwh.harvard.edu> wrote:
> Greetings,
>
> I have recently been working with itkColorTable and have a question about
> the UseRandomColors method. When I attempt the following:
>
> typedef itk::ColorTable< float > ColorType;
>
> ColorType::Pointer colorTable = ColorType::New();
> colorTable->UseRandomColors( 5000 );
>
> my program crashes.
>
> However, if I alter the body of ::UseRandomColors from:
>
>   r = static_cast<TPixel>(vnl_sample_uniform(NumericTraits<TPixel>
>                          ::NonpositiveMin(), NumericTraits<TPixel>::max()));
>   m_Color[i].SetRed( r );
>   g = static_cast<TPixel>(vnl_sample_uniform(NumericTraits<TPixel>
>                          ::NonpositiveMin(), NumericTraits<TPixel>::max()));
>   m_Color[i].SetGreen( g );
>   b = static_cast<TPixel>(vnl_sample_uniform(NumericTraits<TPixel>
>                          ::NonpositiveMin(), NumericTraits<TPixel>::max()));
>   m_Color[i].SetBlue( b );
>
> to:
>
>   r = static_cast<TPixel>( vnl_sample_uniform( 0.0, 1.0 ) );
>   m_Color[i].SetRed( r );
>   g = static_cast<TPixel>( vnl_sample_uniform( 0.0, 1.0 ) );
>   m_Color[i].SetGreen( g );
>   b = static_cast<TPixel>( vnl_sample_uniform( 0.0, 1.0 ) );
>   m_Color[i].SetBlue( b );
>
> my program runs, and I get expected behavior. Why are the color components
> randomly chosen in the interval from non-positive min to max in the
> original? Isn't the floating point color component convention associated
> with the interval [0.0, 1.0]?  If the original is a logical bug, I'd be
> happy to fix and commit. If I'm doing something incorrectly, please let me
> know.
>
> Many thanks,
>
> -James
> _______________________________________________
> 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.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-developers
>


More information about the Insight-developers mailing list