Re: Mapping colours in DensityPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg104181] Re: Mapping colours in DensityPlot
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Thu, 22 Oct 2009 02:18:26 -0400 (EDT)
- References: <hbmovm$k9b$1@smc.vnet.net>
"SeekUp" <seek.up.girl at gmail.com> wrote in message news:hbmovm$k9b$1 at smc.vnet.net... >I am using the following command to do a DensityPlot in grayscale. The > grayscale range is from 0-255, but I need to map my function to a > grey-level > maximum of 200. How do I define a new GrayLevel with a max gray level of > 200? (Or alternately change the mapping so make the max level 200?) > > > > DensityPlot[Mod[elementphase[x, y], 2 \[Pi]], {x, -0.008, 0.008}, > {y, -0.006, 0.006}, PlotRange -> All, PlotPoints -> 120, ColorFunction -> > GrayLevel, Frame -> False, ImageSize -> {{0, 800}, {0, 600}}, > AspectRatio -> > 600/800] > > > > Any suggestions will be appreciated, although I'm a Mathematica newbie, so > an example of what to do rather than a broad instruction would be > invaluable. > If I understand you correctly, you want simply a linear mapping from 0-255 to 0-200 ? If so, define a simple function to do it: This below will map "x" which is a value between 0-255 to value which is between 0-200 Let A = 255; B = 0; a = 200; b = 0; map[A_, B_, a_, b_, x_] := a - ((A - x)*(a - b))/(A - B) so to map 240 write map[A, B, a, b, 240] So, if you have the original image and want to convert it to the new scale, do (on the ImageData) the following image = {{0, 240, 210}, {90, 100, 50}, {3, 213, 255}}; (*some data*) {row, col} = Dimensions[image]; newImage = Table[map[A, B, a, b, image[[i,j]]], {i, row}, {j, col}]; N[newImage] Out[86]= {{0., 188.23529411764707, 164.7058823529412}, {70.58823529411765, 78.43137254901961, 39.21568627450981}, {2.3529411764705883, 167.05882352941177, 200.}} Now you can do the DensityPlot on the new scaled image? --Nasser