16bit greyscale image to heatmap

久未见 提交于 2019-12-24 05:36:08

问题


I'm working on a scientific imaging software for my university, and I've encountered a major problem. Scientific camera (Apogee Alta U57) at my lab provides images as 16bpp array - it's 0-65535 values per pixel! We want to keep this range, but in fact we can't display them on monitor (0-255 grayscale range). So I found a way to resolve this problem - simply to make use of colors, and to display whole image as a heatmap (from black, blue, through green and red, to pure white).

I mean something like this - Example heatmap image I want to achieve

My only question is: How to efficiently convert 16bpp array of pixel values to complete heatmap bitmap in c#? Are there any libraries for doing that? If not, how do I achieve that using .NET resources?

My idea was to create function that maps 65536 values into (255 R, 255G, 255B), but it's a tough job - especially without using HSV model.

I would be much obliged for any help provided!


回答1:


Your question consist of several parts:

  • reading in the 16 bit pixel data values
  • mapping them to 24 bit rgb colors
  • writing them out to an image file

I'll skip part one and three and give you a few ideas about part 2.

It is in fact harder than it seems. A unique mapping that doesn't lose any information is simple, in fact trivial, just a little bit shifting will do.

But you also want the result to work visually, meaning not so much is should be visually appealing but should make sense to a human eye. so we need a mapping that has a credible yet large enough gradient.

For this you should experiment a little. I suggest to make use of the LinearGradientBrush, as I show here. Have a look at the interpolateColors function! It uses only 6 colors in the example, way to few for your case!

You should pick many more; you may need to go through the color space in a spiral..

The trick for you will be to choose both nice and enough stop colors to create a 64k large set of unique colors, best going from blueish to reddish..

You will need to test the result for uniqueness; in fact you may want to create a pair of Dictionary and Dictionary for the mappings..



来源:https://stackoverflow.com/questions/31231972/16bit-greyscale-image-to-heatmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!