[Date Index]
[Thread Index]
[Author Index]
Re: Plot Points over an image
*To*: mathgroup at smc.vnet.net
*Subject*: [mg129169] Re: Plot Points over an image
*From*: "Alexey Popkov" <lehin.p at gmail.com>
*Date*: Wed, 19 Dec 2012 04:58:30 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-newout@smc.vnet.net
*Delivered-to*: mathgroup-newsend@smc.vnet.net
*References*: <kap6d7$46t$1@smc.vnet.net>
Hi Pablo,
For removing the white edges you could use the combination of options
AspectRatio -> Full, PlotRangePadding -> 0, ImagePadding -> 0
or as an alternative the undocumented option
Method -> {"ShrinkWrap" -> True}
Here are examples:
t = Table[
Evaluate[
Sum[Sin[RandomReal[1.7] x]*Cos[RandomReal[1.5] y], {10}]], {x, 0,
8, .02}, {y, 0, 8, 0.02}];
gr1 = Show[ReliefPlot[t], ImageSize -> {640, 640}, Frame -> False,
Method -> {"ShrinkWrap" -> True}]
gr2 = Show[ReliefPlot[t], ImageSize -> {640, 640}, Frame -> False,
AspectRatio -> Full, PlotRangePadding -> 0, ImagePadding -> 0]
You wish to generate a 640x640 image and the above code will do it for you.
But you should realize that the real dimensions of the image generated by
ReliefPlot will always be the same as of the array 't' passed to ReliefPlot.
Let us check:
reliefPlotData =
Cases[gr1, x_Raster :> First@x, {0, \[Infinity]}][[1]];
reliefPlotData // Dimensions
t
gives {401, 401, 3} and {401, 401}.
So when you export your image with ImageSize {640, 640} you get resized
version of the graphics generated by ReliefPlot. And in this cases you have
no control over resizing algoritm used. I recommend to use ImageResize
instead or (much better) increase the dimensions of the input array 't'.
Further, you say that you "needed the image as a matrix of 640x640 integers
values". This means that you need ither binary or grayscale image. You could
use the ColorFunction option of ReliefPlot to generate a grayscale image:
gr2 = Show[ReliefPlot[t, ColorFunction -> GrayLevel],
ImageSize -> {640, 640}, Frame -> False, AspectRatio -> Full,
PlotRangePadding -> 0, ImagePadding -> 0];
To get the 2D matrix generated by ReliefPlot you could then take only the
first element of each RGB triplet (they are the equal in the case of
grayscale images):
reliefPlotData =
Cases[gr1, x_Raster :> x[[1, All, All, 1]], {0, \[Infinity]}][[1]];
This will give a 2D matrix of real values. If you wish to convert it to
integers, you could multiply them by 255:
reliefPlotDataIntegers = Round[255*reliefPlotData];
You can display it:
Image@Reverse@reliefPlotData
Image[Reverse@reliefPlotDataIntegers, "Byte"]
(the images will be 401x401 in size)
To get 640x640 matrix you should increase the dimensions of the input array
't' or resize the image.
Now you need to add the points. At first, you should check the coordinate
system of your image:
Show[gr2, Frame -> True, FrameTicks -> Automatic,
ImagePadding -> Automatic]
You see that values go from 0 to 401. This is probably why the points are
shifted. You can use the DataRange option of ReliefPlot to specify the
target range of values. Assuming that it is from 0 to 640:
gr2 = Show[
ReliefPlot[t, ColorFunction -> GrayLevel,
DataRange -> {{0, 640}, {0, 640}}], ImageSize -> {640, 640},
Frame -> False, AspectRatio -> Full, PlotRangePadding -> 0,
ImagePadding -> 0];
Show[gr2, Frame -> True, FrameTicks -> Automatic,
ImagePadding -> Automatic]
Visualization of the set of points
Graphics[{Red, Opacity[.5], PointSize[.02], Point[puntos]},
ImageSize -> {640, 640}]
It does not look like the points on your attached image "imageanother system.tiff".
HTH,
Alexey
>Hi,
>
>
>Thank you very much for the help.
>
>
>The problem is related with the image.
>I generate the image with Mathematica and I made an Export[] command to
>save it as TIFF.
>
>
>Show[ReliefPlot[
> Table[Evaluate[
> Sum[Sin[RandomReal[1.7] x ]*Cos[RandomReal[1.5] y], {10}]], {x, 0,
> 8, .02}, {y, 0, 8, 0.02}]], ImageSize -> {640, 640}, AspectRatio ->
> Full,
> Frame -> False]
>Export["figura1.tiff", %];
>
>
>
>
>
>
>--------------------------------------------------------------------------------
>
>
>
>
>
>
>figure1.tiff has two blank ranges at the left and right.
>
>
>I needed the image as a matrix of 640x640 integers values and as I did not
>know how to get it with Mathematica I changed to mode->indexed with GIMP
>program. The darker the higher value.
>I had a program in another system that get coordinates of zones (circular areas) to
>capture the maximum value over the image.
>This program returns a list of coordinate points i.e. index (i,j) over de
>matrix of values.
>After that the program generates an image with such a points over the
>indexed image generated with Gimp.
>
>
>
>
>
>
>--------------------------------------------------------------------------------
>
>
>
>
>This figure also has the two left-right vertical blank spaces and the
>program even place point at those zones (see left region).
>
>
>Since I have the list of matrix indexes (with {0,0} at the left uppermost
>point of the image ~ matrix) I would like to fix the image in Mathematica
>removing the two blank zones and draw the solution (list of points) to
>rebuild correctly the image.
>
>
>I have made different approaches to address the problem but I haven't found
>a solution that give me the same situation of the points shown in the
>figure of another system.
>
>
>The list of points is:
>
>
>--------------------------------------------------------------------------------
>
>
>
>
>
>
>puntos = Import["02_coordNodosXeY-0.5.txt", "Table"];
>puntosRed = Round[puntos];
>puntosRedMath = ({#[[2]], 640 - #[[1]]}) & /@ puntosRed
>Show[image, Graphics[{Red, Opacity[.5], PointSize[.005], Point[puntos]}]]
>
>
>does not generates the same positions for points shown with another system
>
>
>i = ImageAdjust[ImageResize[image, {640, 640}], {-0.1, -0.1}];
>HighlightImage[i, puntosRedMath, Method -> {"DiskMarkers", 2}];
>
>
>neither works.
>
>
>I would appreciate very much any kind of help to rebuild the solution with
>Mathematica.
>
>
>Regards
>
>
>Pablo
Prev by Date:
**Plot[] will not plot functions when one of the functions in list**
Next by Date:
**Re: Terrible unit trouble in Mathematic 9**
Previous by thread:
**Re: Plot Points over an image**
Next by thread:
**Applying "Replace" to subsets of lists**
| |