<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>They do appear a bit different:</div><div><br></div><div><div>template&lt;class T&gt;</div><div>typename RGBPixel&lt;T&gt;::ComponentType</div><div>RGBPixel&lt;T&gt;</div><div>::GetLuminance() const</div><div>{</div><div>&nbsp;&nbsp;const double luminance =&nbsp;</div><div>&nbsp;&nbsp; &nbsp;0.30 &nbsp;* this-&gt;GetRed() &nbsp; +</div><div>&nbsp;&nbsp; &nbsp;0.59 &nbsp;* this-&gt;GetGreen() +</div><div>&nbsp;&nbsp; &nbsp;0.11 &nbsp;* this-&gt;GetBlue();</div><div>&nbsp;&nbsp;return static_cast&lt;ComponentType&gt;( luminance );</div><div>}</div><div><br></div><div><div>void</div><div>ConvertPixelBuffer&lt;InputPixelType, OutputPixelType, OutputConvertTraits&gt;</div><div>::ConvertRGBToGray(InputPixelType* inputData,&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OutputPixelType* outputData , int size)</div><div>{ &nbsp;&nbsp;</div><div>&nbsp;&nbsp;// Weights convert from linear RGB to CIE luminance assuming a</div><div>&nbsp;&nbsp;// modern monitor. &nbsp;See Charles Pontyon's Colour FAQ</div><div>&nbsp;&nbsp;// <a href="http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html">http://www.inforamp.net/~poynton/notes/colour_and_gamma/ColorFAQ.html</a></div><div>&nbsp;&nbsp;// NOTE: The scale factors are converted to whole numbers for precision</div><div><br></div><div>&nbsp;&nbsp;InputPixelType* endInput = inputData + size*3;</div><div>&nbsp;&nbsp;while(inputData != endInput)</div><div>&nbsp;&nbsp; &nbsp;{</div><div>&nbsp;&nbsp; &nbsp;OutputComponentType val = static_cast&lt;OutputComponentType&gt;(&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;(2125.0 * static_cast&lt;OutputComponentType&gt;(*inputData) +</div><div>&nbsp;&nbsp; &nbsp; &nbsp; 7154.0 * static_cast&lt;OutputComponentType&gt;(*(inputData+1)) +</div><div>&nbsp;&nbsp; &nbsp; &nbsp; 0721.0 * static_cast&lt;OutputComponentType&gt;(*(inputData+2))) / 10000.0 );</div><div>&nbsp;&nbsp; &nbsp;inputData += 3;</div><div>&nbsp;&nbsp; &nbsp;OutputConvertTraits::SetNthComponent(0, *outputData++, val);</div><div>&nbsp;&nbsp; &nbsp;}</div><div>&nbsp;&nbsp;</div><div>}</div><div><br></div><div>As far as the "correct"&nbsp;method for converting RGB to Luminance,&nbsp;I&nbsp;am&nbsp;not&nbsp;sure&nbsp;either&nbsp;is&nbsp;completely&nbsp;correct.&nbsp;The&nbsp;problem&nbsp;is&nbsp;that&nbsp;input&nbsp;color RGB values&nbsp;are&nbsp;not&nbsp;profiled,&nbsp;that&nbsp;is&nbsp;we&nbsp;don't&nbsp;know&nbsp;if&nbsp;the color space of the pixels are&nbsp;in&nbsp;sRGB,&nbsp;Adobe&nbsp;RGB&nbsp;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.</div><div><br></div><div>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.&nbsp;</div><div><br></div><div>Brad</div><div><br></div></div></div><div><br><div><div>On Jul 8, 2009, at 3:58 PM, Sharath Venkatesha wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: arial, helvetica, sans-serif; font-size: 10pt; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hi Bradley,<br><br>Thanks for the information.<br><br>I got the doubt as my results change in the two cases (though by very small amount, initially ), i.e with and without using&nbsp; itkRGBToLuminanceImageFilter.<br>I feed the input images to registration filter, and the output parameters of registration change (in second decimal values) per iteration.<br><br>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.&nbsp; All the other parameters involved remain constant in both the cases.<br><br>I want to know the correct method to follow.<br><br>Thanks,<br>Sharath Venkatesha<br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: arial, helvetica, sans-serif; font-size: 10pt; "><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><font size="2" face="Tahoma"><hr size="1"><b><span style="font-weight: bold; ">From:</span></b><span class="Apple-converted-space">&nbsp;</span>Bradley Lowekamp &lt;<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>&gt;<br><b><span style="font-weight: bold; ">To:</span></b><span class="Apple-converted-space">&nbsp;</span>Sharath Venkatesha &lt;<a href="mailto:sharath20284@yahoo.com">sharath20284@yahoo.com</a>&gt;<br><b><span style="font-weight: bold; ">Cc:</span></b><span class="Apple-converted-space">&nbsp;</span>Insight users &lt;<a href="mailto:insight-users@itk.org">insight-users@itk.org</a>&gt;<br><b><span style="font-weight: bold; ">Sent:</span></b><span class="Apple-converted-space">&nbsp;</span>Wednesday, July 8, 2009 12:32:07 PM<br><b><span style="font-weight: bold; ">Subject:</span></b><span class="Apple-converted-space">&nbsp;</span>Re: [Insight-users] RGB Input to ImageFileReader defined with 'unsigned char' type ?<br></font><br>Hello Sharath,<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This conversion is done through with itk::ConvertPixelBuffer:</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span><a target="_blank" href="http://www.itk.org/Doxygen/html/classitk_1_1ConvertPixelBuffer.html">http://www.itk.org/Doxygen/html/classitk_1_1ConvertPixelBuffer.html</a></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">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.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">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.&nbsp;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Brad</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Jul 8, 2009, at 3:19 PM, Sharath Venkatesha wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><br>Hi,<br><br>I observed that it works, if I give RGB input image to a ImageFileReader defined with 'unsigned char' type.<span class="Apple-converted-space">&nbsp;</span><br>Is the behaviour defined?Are there many approximations involved?<br><br>I generally use &nbsp;itkRGBToLuminanceImageFilter to convert RGB input images to grayscale, before performing registration.<br><br><br>Thanks,<br>Sharath<br><br><br><br><br>_____________________________________<br>Powered by<span class="Apple-converted-space">&nbsp;</span><a rel="nofollow" target="_blank" href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><span><a target="_blank" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a></span><br><br><span>Please keep messages on-topic and check the ITK FAQ at:<span class="Apple-converted-space">&nbsp;</span><a target="_blank" href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</a></span><br><br>Follow this link to subscribe/unsubscribe:<br><span><a target="_blank" href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users</a></span><br></div></blockquote></div><br><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-style-span" style="font-size: 12px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; ">========================================================</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; ">Bradley Lowekamp<span class="Apple-converted-space">&nbsp;</span><span class="Apple-converted-space">&nbsp;</span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-family: Arial; "><span class="Apple-style-span" style="font-family: Arial; ">Lockheed Martin&nbsp;</span></span></font><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; ">Contractor for</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; ">Office of High Performance Computing and Communications</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; ">National Library of Medicine<span class="Apple-converted-space">&nbsp;</span></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font size="3" face="Helvetica" style="font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; "><a rel="nofollow" ymailto="mailto:blowekamp@mail.nih.gov" target="_blank" href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></div><br class="Apple-interchange-newline"></span></div></span></div><br></div></div></div></div><br></div><br class="Apple-interchange-newline"></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">========================================================</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Bradley Lowekamp<span class="Apple-converted-space">&nbsp;</span><span class="Apple-converted-space">&nbsp;</span></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-family: Arial; "><span class="Apple-style-span" style="font-family: Arial; ">Lockheed Martin&nbsp;</span></span></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Contractor for</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Office of High Performance Computing and Communications</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">National Library of Medicine<span class="Apple-converted-space">&nbsp;</span></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></p><br class="Apple-interchange-newline"></span></div></span> </div><br></div></body></html>