[Insight-users] RGB Input to ImageFileReader defined with 'unsigned char' type ?

Bradley Lowekamp blowekamp at mail.nih.gov
Wed Jul 8 16:57:45 EDT 2009


Hello,

They do appear a bit different:

template<class T>
typename RGBPixel<T>::ComponentType
RGBPixel<T>
::GetLuminance() const
{
   const double luminance =
     0.30  * this->GetRed()   +
     0.59  * this->GetGreen() +
     0.11  * this->GetBlue();
   return static_cast<ComponentType>( luminance );
}

void
ConvertPixelBuffer<InputPixelType, OutputPixelType, OutputConvertTraits>
::ConvertRGBToGray(InputPixelType* inputData,
                    OutputPixelType* outputData , int size)
{
   // Weights convert from linear RGB to CIE luminance assuming a
   // modern monitor.  See Charles Pontyon's Colour FAQ
   // http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html
   // NOTE: The scale factors are converted to whole numbers for  
precision

   InputPixelType* endInput = inputData + size*3;
   while(inputData != endInput)
     {
     OutputComponentType val = static_cast<OutputComponentType>(
       (2125.0 * static_cast<OutputComponentType>(*inputData) +
        7154.0 * static_cast<OutputComponentType>(*(inputData+1)) +
        0721.0 * static_cast<OutputComponentType>(*(inputData+2))) /  
10000.0 );
     inputData += 3;
     OutputConvertTraits::SetNthComponent(0, *outputData++, val);
     }

}

As far as the "correct" method for converting RGB to Luminance, I am  
not sure either is completely correct. The problem is that input color  
RGB values are not profiled, that is we don't know if the color space  
of the pixels are in sRGB, Adobe RGB etc. For example sRGB does not  
have constant gamma value through it's space. Without these  
consideration a correct conversion from RGB to Luminance can not be  
made.

However for your particular problem, it most likely does not matter  
what is the correct Luminance. As you are performing registration,  
this conversion is merely needed for evaluating the registration  
metric. This is a more difficult problem, without a correct or best  
way to do it. For the Visible Human I have used just the Red channel  
before.

Brad


On Jul 8, 2009, at 3:58 PM, Sharath Venkatesha wrote:

> Hi Bradley,
>
> Thanks for the information.
>
> I got the doubt as my results change in the two cases (though by  
> very small amount, initially ), i.e with and without using   
> itkRGBToLuminanceImageFilter.
> I feed the input images to registration filter, and the output  
> parameters of registration change (in second decimal values) per  
> iteration.
>
> And over multiple iterations of the optimizer, I get a change of 2-3  
> pixels in translation parameters, and the angle also changes by 0.5  
> degrees, for a particular set of input images.  All the other  
> parameters involved remain constant in both the cases.
>
> I want to know the correct method to follow.
>
> Thanks,
> Sharath Venkatesha
>
> From: Bradley Lowekamp <blowekamp at mail.nih.gov>
> To: Sharath Venkatesha <sharath20284 at yahoo.com>
> Cc: Insight users <insight-users at itk.org>
> Sent: Wednesday, July 8, 2009 12:32:07 PM
> Subject: Re: [Insight-users] RGB Input to ImageFileReader defined  
> with 'unsigned char' type ?
>
> Hello Sharath,
>
> This conversion is done through with itk::ConvertPixelBuffer:
> http://www.itk.org/Doxygen/html/classitk_1_1ConvertPixelBuffer.html
>
> This class is responsible for doing all the conversions that occur  
> when reading an image from a file into your itk::Image. When the  
> types don't match it auto-magically converts the types. This enable  
> one to read a file of chars into an itk::Image of floats with out  
> any problems.
>
> For you particular case it computes the luminance based on the RGB  
> values to get "grey" pixels. The RGBToLuminance filter should give  
> simular results as well.
>
> Brad
>
> On Jul 8, 2009, at 3:19 PM, Sharath Venkatesha wrote:
>
>>
>> Hi,
>>
>> I observed that it works, if I give RGB input image to a  
>> ImageFileReader defined with 'unsigned char' type.
>> Is the behaviour defined?Are there many approximations involved?
>>
>> I generally use  itkRGBToLuminanceImageFilter to convert RGB input  
>> images to grayscale, before performing registration.
>>
>>
>> Thanks,
>> Sharath
>>
>>
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.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
>
> ========================================================
> Bradley Lowekamp
> Lockheed Martin Contractor for
> Office of High Performance Computing and Communications
> National Library of Medicine
> blowekamp at mail.nih.gov
>
>
>
>

========================================================
Bradley Lowekamp
Lockheed Martin Contractor for
Office of High Performance Computing and Communications
National Library of Medicine
blowekamp at mail.nih.gov


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090708/f4386ab5/attachment-0001.htm>


More information about the Insight-users mailing list