使用代码的渐变图(算法) [英] Gradiant Map Using Code(Algorithm)

查看:79
本文介绍了使用代码的渐变图(算法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在创建一个软件,该软件将基于该点上的某些值来显示图像的渐变地图.如何创建平滑的颜色渐变以显示像这样的完美地图

http://ftp.goldensoftware.com/products/mapviewer/images_m6product/GradientMap.gif [ ^ ]
http://www.georeference.org/doc/images/sc_surf_data_14.gif [ ^ ]


请向我建议任何示例代码或任何算法,以使值更改看起来像这样....,这将对其他开发此类应用程序的人有所帮助.
我需要这样
http://i.imgur.com/GJAEp.png

我仅在该点上绘图,其余区域将填充适当的颜色


在此先感谢...

Hello,

I am creating a software that will show a gradiant map for an image based on some value in that points. How I can create a smooth color gradiant to show a perfect map like this images

http://ftp.goldensoftware.com/products/mapviewer/images_m6product/GradientMap.gif[^]
http://www.georeference.org/doc/images/sc_surf_data_14.gif[^]


please suggest me any sample code or any algorithms to make the value changes look smooth like this...., This will helpful to others they developing such applications..

I need like this
http://i.imgur.com/GJAEp.png

I am plotting only to that point and the remaining area will fill with appropritate color


Thanks in advance...

推荐答案

最初,您必须将可用的温度分布插值到整个输出图像.
您可以使用任何插值方法来创建插值.
根据新的温度(插值)值,您必须应用颜色图.


最后,您必须准备从黑色(0)->蓝色(49)->绿色(69)->黄色(68)->红色(107)开始的映射(每个温度RGB查找).
该贴图应具有从一种颜色到另一种颜色的平滑过渡.即,地图的索引59应该指示从蓝色到绿色的过渡.


以下库将有助于创建此类渐变.
http://jmol.sourceforge.net/jscolors/ [ http://jmol.sourceforge.net/jscolors/gradients.png [ http://en.wikipedia.org/wiki/Bicubic_interpolation [
Initially, you have to interpolate the available temperature distribution to the entire output image.
You can use any of the interpolation methods to create the interpolated values.
Based on the new temperature(interpolated) values, you have to apply a color map.


You have to prepare a map(RGB lookuptable for each temperature ) starting from black(0)->blue(49)->green(69)->yellow(68)->red(107) at last.
This map should have a smooth transition from one color to other. ie, Index 59 of the map should indicate a transitaion from blue to green.


The following library will be helpful to create such gradients.
http://jmol.sourceforge.net/jscolors/[^]

Gradient Image:http://jmol.sourceforge.net/jscolors/gradients.png[^]

I''m not sure which is the good method for interpoaltion, Bi-Cubic interpolation or any other interpolation can be used to create the temperature distribution of the entire image from less number of inputs.
http://en.wikipedia.org/wiki/Bicubic_interpolation[^]


我不知道任何现成的C ++代码,但是如果您只需要它的所谓的颜色渐变外观,则该算法非常简单,除非您还需要这些水平线,否则难度会更大.因此,您有一个包含两个坐标变量的函数,这些函数返回函数的值.首先,您需要找出所需范围内的最小值和最大值.由于这可能是一个问题,因此您可以在计算颜色图所需的所有点时找到这两个值,然后调整像素的颜色.另外,以RGB为地图定义最大"和最小"颜色.无论您的色彩空间是什么,在RGB中执行计算都更好.

现在,通过一些步骤将要显示的坐标空间的域分解为矩形网格.在最简单的情况下,该步骤将对应于像素的侧面.使用函数计算网格的所有点(到那时,您将知道最大值和最小值).假设您预定义了与最大值和最小值对应的像素的RGB颜色,请使用线性插值查找网格的所有其他点的像素颜色(这就是为什么我建议使用RGB的原因:RGB值的线性级数看起来是线性"的)肉眼可见;但是,您可以尝试其他颜色空间和非线性映射.

如果网格步长超过一个像素,则使图片由相同颜色的小方块(矩形)组成.在某种程度上,每个乡绅将代表一种大像素".映射到单个像素始终看起来会更好,但可能需要更多时间.如今,除非您使用非常慢的"GetPixel/SetPixel"之类的方法,否则它永远都不会太长.您应该始终使用指针或数组算术直接访问视频数据数组.这取决于您使用的图形库.

就这样.

顺便说一句,尝试改为创建3D视图.这不是很困难,但是会花费很多精力.使图片由用户自由旋转;只有这样才能提供真正的3D体验.

祝你好运,
—SA
I don''t know any ready-to-use C++ code, but if you only need so called color gradient look of it, the algorithm is pretty simple, unless you also need those level line, which is way more difficult. So, you have a function of two coordinate variables returning the value of function. First, you need to find out the minimal and maximum value withing the required range. As this along can be a problem, you can find those two values as you calculate all the points needed for a color map, and than adjust the color of the pixels. Also, define a "maximum" and "minimum" color for the map, in RGB. Whatever your color space is, the calculations is better to perform in RGB.

Now, you break the domain of the coordinate space to be presented into rectangular mesh with some step. In simplest case, the step will correspond to the side of the pixel. Calculate all point of the mesh using your function (by that moment you will know maximum and minimum). Assuming you predefined the RGB color of the pixels corresponding to maximum and minimum values, find pixel colors for all other points of the mesh using linear interpolation (that''s why I advised using RGB: the linear progression of RGB values looks "linear" to human eye; however, you can experiment with other color spaces and non-linear mapping).

If your mesh step is more than one pixel, make the picture composed of small squares (rectangles) of the same color. In a way, each squire will represent a kind of a "big pixel". Mapping to individual pixels will always look better, but may require more time. These days, it should never be too long, anyway, unless you use something like very slow "GetPixel/SetPixel". You should always use direct access to video data array, using pointer or array arithmetic. It depends on the graphics library you use.

That''s it.

By the way, try to create a 3D view instead. It''s not extremely difficult, but would take considerable effort. Make the picture freely rotating by the user; only then it will give a real 3D experience.

Good luck,
—SA


这篇关于使用代码的渐变图(算法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆