12,550,766 members (54,095 online)
Rate this:
See more:
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://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

Posted 12-Oct-12 5:08am
Updated 12-Oct-12 5:48am
v2
Santhosh_G 12-Oct-12 11:20am

What are the inputs for your application ?
For GradientMap.gif, you need distribution of Temperature, right ?
Arun Kumar K S 12-Oct-12 11:27am

Yes you are right
Santhosh_G 12-Oct-12 11:33am

What are the inputs to prepare these images ?
Do you have entire temperature distribution ?
Or temperature of one or two locations.
Sergey Alexandrovich Kryukov 12-Oct-12 12:09pm

Of course. I described the algorithm, it's easy enough.
--SA
Arun Kumar K S 12-Oct-12 11:33am

Arun Kumar K S 12-Oct-12 11:36am

I need the entire temperature distribution and the temperature will vary in each location(I will plot only some particular locations)
Arun Kumar K S 12-Oct-12 11:43am

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

Rate this:

Solution 1

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.

http://jmol.sourceforge.net/jscolors/[^]

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[^]
enhzflep 12-Oct-12 12:42pm

Rate this:

Solution 2

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

Top Experts
Last 24hrsThis month
 Suvendu Shekhar Giri 55 Dave Kreskowiak 50 Mehdi Gholam 35 ppolymorphe 35 Afzaal Ahmad Zeeshan 25
 OriginalGriff 3,901 Suvendu Shekhar Giri 1,743 John Simmons / outlaw programmer 1,687 ppolymorphe 1,571 Karthik Bangalore 1,210