From: SeekUp on 21 Oct 2009 06:49 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.
From: Mark McClure on 22 Oct 2009 02:25 On Wed, Oct 21, 2009 at 6:27 AM, SeekUp <seek.up.girl(a)gmail.com> wrote: > 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? I'm not quite clear what you mean when you say that the "grayscale range is from 0-255". In fact, all arguments to the ColorFunction will automatically be scaled to be between 0 and 1. This is good, since that's what GrayLevel expects. Do you want to darken your picture so that the lightest region has shade GrayLevel[200/255]? If so, try this: cf[c_] = GrayLevel[200*c/255]; DensityPlot[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2}, ColorFunction -> cf] Hope that helps, Mark McClure
From: David Park on 22 Oct 2009 02:25 Most Mathematica color gradients go from 0 to 1 and not 0 to 255. And in plots like DensityPlot Mathematica automatically scales the color parameter to go from 0 to 1 over the plot. So you could use something like the following: A function that goes from 0 to 200: f[x_, y_] := 200 Abs[Sin[x y]] DensityPlot[f[x, y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}, ColorFunction -> GrayLevel ] But if you want to key the color to the actual value of the function you can turn off the automatic scaling with ColorFunctionScaling and use ColorFunction with Rescale to rescale 0 to 200 to 0 to 1. DensityPlot[f[x, y], {x, -\[Pi]/2, \[Pi]/2}, {y, -\[Pi]/2, \[Pi]/2}, ColorFunctionScaling -> False, ColorFunction -> Function[z, GrayLevel[Rescale[z, {0, 200}, {0, 1}]]] ] David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: SeekUp [mailto:seek.up.girl(a)gmail.com] 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.
From: Nasser M. Abbasi on 22 Oct 2009 02:40 "SeekUp" <seek.up.girl(a)gmail.com> wrote in message news:hbmovm$k9b$1(a)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
|
Pages: 1 Prev: options for VectorPlot in version 7 vs VectorFieldPlot in version Next: Mathematica blogs |