Click here to Skip to main content
12,550,766 members (54,095 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ C C# Java

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[^][^]

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

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

Thanks in advance...
Posted 12-Oct-12 5:08am
Updated 12-Oct-12 5:48am
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 about the sc_surf_data_14.gif,
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.
Arun Kumar K S 12-Oct-12 11:33am
please help me to make such an application. If possible with an example
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

I am plotting only to that point and the remaining area will fill with appropritate color
Rate this: bad
Please Sign up or sign in to vote.

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.

The following library will be helpful to create such gradients.[^]

Gradient Image:[^]

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.[^]
enhzflep 12-Oct-12 12:42pm
My 5. Succinct answer.
Rate this: bad
Please Sign up or sign in to vote.

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,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100