<div dir="ltr">I managed to get decent results using the following formula. So, 16bit grayscale to RGBA:<div><br></div><div><span class="" style="white-space:pre"> </span><i>vtkSmartPointer<vtkLookupTable> lookupTable= vtkSmartPointer<vtkLookupTable>::New();<br>
</i></div><div><div><i><span class="" style="white-space:pre"> </span>lookupTable->SetNumberOfTableValues(VTK_UNSIGNED_CHAR_MAX + 1); </i></div><div><i><span class="" style="white-space:pre"> </span>lookupTable->SetRange(0.0, VTK_UNSIGNED_CHAR_MAX);</i></div>
<div><i> </i></div><div><i><span class="" style="white-space:pre"> </span>// Iterate through every scalar value from 0-255</i></div><div><i><span class="" style="white-space:pre"> </span>// and fill RGB tables with scalar=R=G=B values</i></div>
<div><i><span class="" style="white-space:pre"> </span>for (int i = 0; i <= VTK_UNSIGNED_CHAR_MAX; i++)</i></div><div><i><span class="" style="white-space:pre"> </span>{<span class="" style="white-space:pre"> </span></i></div>
<div><i><span class="" style="white-space:pre"> </span>double doubleIndex = static_cast<double>(i);<span class="" style="white-space:pre"> </span></i></div><div><i><span class="" style="white-space:pre"> </span>lookupTable->SetTableValue(i, </i></div>
<div><i><span class="" style="white-space:pre"> </span>VTK_UNSIGNED_CHAR_MAX - doubleIndex, </i></div><div><i><span class="" style="white-space:pre"> </span>VTK_UNSIGNED_CHAR_MAX - doubleIndex, </i></div><div><i><span class="" style="white-space:pre"> </span>VTK_UNSIGNED_CHAR_MAX - doubleIndex, </i></div>
<div><i><span class="" style="white-space:pre"> </span>1.0); </i></div><div><i><span class="" style="white-space:pre"> </span>}</i></div><div><i><br></i></div><div><i><span class="" style="white-space:pre"> </span>lookupTable->Build();</i></div>
</div><div><i><br></i></div><div><i> vtkImageData* imageData <= 16bit grayscale</i></div><div><div><i><span class="" style="white-space:pre"> </span>imageData->AllocateScalars(VTK_UNSIGNED_SHORT, 1);</i></div>
<div><span class="" style="white-space:pre"><i> </i></span></div><div><i><span class="" style="white-space:pre"> </span>// Cast 16bit grayscale image to 8bit and rescale</i></div><div><i><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkImageShiftScale> rescaler = vtkSmartPointer<vtkImageShiftScale>::New(); </i></div>
<div><i><span class="" style="white-space:pre"> </span>rescaler->SetOutputScalarTypeToUnsignedChar();<span class="" style="white-space:pre"> </span></i></div><div><i><span class="" style="white-space:pre"> </span>rescaler->SetScale(1.0 / (VTK_UNSIGNED_CHAR_MAX + 1));<span class="" style="white-space:pre"> </span></i></div>
<div><i><span class="" style="white-space:pre"> </span>rescaler->SetShift(0);</i></div><div><i><span class="" style="white-space:pre"> </span>rescaler->SetInputData(imageData);</i></div><div><i><br></i></div><div>
<i><span class="" style="white-space:pre"> </span>// Map the input image using RGBA lookup-table</i></div><div><i><span class="" style="white-space:pre"> </span>vtkSmartPointer<vtkImageMapToColors> imageColorMapper= vtkSmartPointer<vtkImageMapToColors>::New(); <br>
</i></div><div><i><span class="" style="white-space:pre"> </span>imageColorMapper->PassAlphaToOutputOn(); </i></div><div><i><span class="" style="white-space:pre"> </span>imageColorMapper->SetLookupTable(lookupTable); </i></div>
<div><i><span class="" style="white-space:pre"> </span>imageColorMapper->SetInputConnection(rescaler->GetOutputPort());</i></div></div><div><i><br></i></div><div><i> imageColorMapper->GetOutput() => 8bit RGBA</i></div>
<div><br></div><div>There might have been a more elegant solution, but this is what worked for me.</div><div><br></div><div>Thanks to all!</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 4, 2014 at 1:34 PM, David Cole <span dir="ltr"><<a href="mailto:dlrdave@aol.com" target="_blank">dlrdave@aol.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">> Hi David. Thank you very much for the example, it did push me a bit<br>
> further. Another thing, I have a number of<br>
> 16bit grayscale images that also need converting. In what way should<br>
> I modify the lookup table to accommodate these files?<br>
<br>
</div>See the updated example which I've put on the wiki now:<br>
<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageMapToColors" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageMapToColors</a><br>
<br>
You can use any of the classes that derive from vtkScalarsToColors as<br>
the lookup table.<br>
<br>
<a href="http://www.vtk.org/doc/nightly/html/classvtkScalarsToColors.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkScalarsToColors.html</a><br>
<br>
If you just use vtkLookupTable as in the example, you can just modify<br>
the arguments to the SetRange call to cover whatever range of grayscale<br>
values you want to map to color. Anything lower than the lower arg will<br>
map to the lowest color, and anything higher than the higher arg will<br>
map to the highest color... in between values get interpolated.<br>
<br>
<a href="http://www.vtk.org/doc/nightly/html/classvtkLookupTable.html" target="_blank">http://www.vtk.org/doc/nightly/html/classvtkLookupTable.html</a><br>
<br>
Please keep replies on the list so others may also benefit from the<br>
discussion.<br>
<br>
<br>
Thanks,<br>
David C.<br>
<br>
<br>
</blockquote></div><br></div>