Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12847 > unrolled thread

Plot Points over an image

Started bylopez.matencio@gmail.com
First post2012-12-18 07:36 +0000
Last post2012-12-19 09:55 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Plot Points over an image lopez.matencio@gmail.com - 2012-12-18 07:36 +0000
    Re: Plot Points over an image "Alexey Popkov" <lehin.p@gmail.com> - 2012-12-19 09:55 +0000
    Re: Plot Points over an image "Alexey Popkov" <lehin.p@gmail.com> - 2012-12-19 09:55 +0000

#12847 — Plot Points over an image

Fromlopez.matencio@gmail.com
Date2012-12-18 07:36 +0000
SubjectPlot Points over an image
Message-ID<kap6d7$46t$1@smc.vnet.net>
Hello,

I have a TIFF image of 640x640 pixels, over which I would like to plot a list of points or disks with small radius.
I have been testing different alternatives and I found ImageCompose command.

ImageCompose[image, {Graphics[{PointSize[.009], Black, Point[{0, 0}]}
   ], .6}, {600, 600}]

This place a point at pixels {600,600} from left-bottom, but if I set a point close to e.g. right edge of the image {635,600} the point is into the frame bat there is not image at background. Namely, the image does not show all the pixels. First, let say 20-25 first x-pixels of the image, and the last 20-25 x-pixels of the image are invisibles.

When I tick the image it shows the image at the center of the frame and two blank vertical spaces at right and left of the image.

Two questions:
- There exist any option or command I could use to show the full image, i.e. the 640 x 640 pixels?
- How could I display over imposed a list of points (e.g. 40 points) at pixel coordinates and all on the same image.

Thank you very much for your help and time.

Pablo

[toc] | [next] | [standalone]


#12858

From"Alexey Popkov" <lehin.p@gmail.com>
Date2012-12-19 09:55 +0000
Message-ID<kas2ug$cho$1@smc.vnet.net>
In reply to#12847
Hi Pablo,

On my machine your code gives expected result with random image:

image = Image[RandomReal[1, {640, 640, 3}]];
ImageCompose[image, {Graphics[{PointSize[.009], Black,
Point[{0, 0}]}], .6}, {635, 600}]

Alexey


<lopez.matencio@gmail.com> wrote: news:kap6d7$46t$1@smc.vnet.net...
> Hello,
>
> I have a TIFF image of 640x640 pixels, over which I would like to plot a 
> list of points or disks with small radius.
> I have been testing different alternatives and I found ImageCompose 
> command.
>
> ImageCompose[image, {Graphics[{PointSize[.009], Black, Point[{0, 0}]}
>   ], .6}, {600, 600}]
>
> This place a point at pixels {600,600} from left-bottom, but if I set a 
> point close to e.g. right edge of the image {635,600} the point is into 
> the frame bat there is not image at background. Namely, the image does not 
> show all the pixels. First, let say 20-25 first x-pixels of the image, and 
> the last 20-25 x-pixels of the image are invisibles.
>
> When I tick the image it shows the image at the center of the frame and 
> two blank vertical spaces at right and left of the image.
>
> Two questions:
> - There exist any option or command I could use to show the full image, 
> i.e. the 640 x 640 pixels?
> - How could I display over imposed a list of points (e.g. 40 points) at 
> pixel coordinates and all on the same image.
>
> Thank you very much for your help and time.
>
> Pablo
> 


[toc] | [prev] | [next] | [standalone]


#12861

From"Alexey Popkov" <lehin.p@gmail.com>
Date2012-12-19 09:55 +0000
Message-ID<kas2v0$chu$1@smc.vnet.net>
In reply to#12847
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


[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web