Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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://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...
Posted
Updated 12-Oct-12 5:48am
v2
Comments
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.
--SA
Arun Kumar K S 12-Oct-12 11:33am    
please help me to make such an application. If possible with an example

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[^]
 
Share this answer
 
Comments
enhzflep 12-Oct-12 12:42pm    
My 5. Succinct answer.
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900