Drawing a point.

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Drawing a point.

Carlos A. Silva
Hi,

I would like to draw scatter points over an image. I know that there is ScatterInspector and ScatterInspectorOverlay class for drawing points, but their size is fixed as I make a zoom on the image. Also I did not manage to obtain a dot with a dimension of one pixel.

Is it possible to configure ScatterInspector to obtain the effect I want ? There is any other alternative ?

I tried to write my own class using gc, but did not found a primitive to draw just a dot with a pixel.

Best regards,

Carlos Silva


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

bryce hendrix-2
On Wed, Oct 13, 2010 at 8:02 PM, Carlos A. Silva <[hidden email]> wrote:
Hi,

I would like to draw scatter points over an image. I know that there is ScatterInspector and ScatterInspectorOverlay class for drawing points, but their size is fixed as I make a zoom on the image. Also I did not manage to obtain a dot with a dimension of one pixel.


Carlos,

I think you're going down the wrong corner with the Scatter* tools, as it sounds like what you really want is just an overlay. Instead, have a look at the world_map.py example, which has 2 components, one is an image plot, and the other is a scatter plot. The scatter plot is overlayed on top of the image plot, which sounds exactly like what you're trying to do.

Another example worth looking at is xray_plot.py, which I wrote as a very simple example of how to make a plot, a custom tool, and a custom overlay all work together. Its about 160 lines long, including the code to generate the sample data.


Both of these allow for different markers, if you want a single pixel, use the 'pixel' marker instead of trying to get a 1 pixel dot.

Let me know if I misunderstood what you're trying to do so I can point you in the right direction.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

Carlos A. Silva
Hi Bryce,

Thank you for the directions. Yes, I agree that I must be in the wrong path and, from what I have learned so far from Chaco, that an overlay is the way to go. I considered a similar solution to world map, but did not know the option 'pixel' for the scatter plot; however, I have the same problem, when I zoom in the image, the resolution (probably this was not clear in my previous email) of a "pixel" in the image and the resolution in the scatter plot are not the same, namely, in the scatter plot the pixel keep the same screen size, while in the image it grows.

I should have said in the previous e-mail that my goal was to design a tool to mark a contour in an image pixel by pixel, so I need that the resolution of the pixels in both the image and the scatter plot be the same.

I think that Chaco is really a great tool, but it is not easy to learn.

Carlos.

On Thu, Oct 14, 2010 at 1:24 AM, bryce hendrix <[hidden email]> wrote:
On Wed, Oct 13, 2010 at 8:02 PM, Carlos A. Silva <[hidden email]> wrote:
Hi,

I would like to draw scatter points over an image. I know that there is ScatterInspector and ScatterInspectorOverlay class for drawing points, but their size is fixed as I make a zoom on the image. Also I did not manage to obtain a dot with a dimension of one pixel.


Carlos,

I think you're going down the wrong corner with the Scatter* tools, as it sounds like what you really want is just an overlay. Instead, have a look at the world_map.py example, which has 2 components, one is an image plot, and the other is a scatter plot. The scatter plot is overlayed on top of the image plot, which sounds exactly like what you're trying to do.

Another example worth looking at is xray_plot.py, which I wrote as a very simple example of how to make a plot, a custom tool, and a custom overlay all work together. Its about 160 lines long, including the code to generate the sample data.


Both of these allow for different markers, if you want a single pixel, use the 'pixel' marker instead of trying to get a 1 pixel dot.

Let me know if I misunderstood what you're trying to do so I can point you in the right direction.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

Robin Kraft
Carlos,

I may be misunderstanding what you're trying to do, but if your project specs are flexible enough to include matplotlib, imshow might be a useful alternate solution - includes nice pixel resampling. I'm using it to map global raster data, and draw performance + zooming are really nice.

I'm on my phone so this code is taken out of context from a simple GUI I've been working on, but hopefully it will point you towards something useful. The matplotlib image tutorial is really helpful by the way: 

http://matplotlib.sourceforge.net/users/image_tutorial.html

import matplotlib.pyplot as plt

plt.imshow(img, cmap=color_map, norm=norm, interpolation="nearest", origin="upper")

-Robin


On Oct 14, 2010, at 5:05 AM, "Carlos A. Silva" <[hidden email]> wrote:

Hi Bryce,

Thank you for the directions. Yes, I agree that I must be in the wrong path and, from what I have learned so far from Chaco, that an overlay is the way to go. I considered a similar solution to world map, but did not know the option 'pixel' for the scatter plot; however, I have the same problem, when I zoom in the image, the resolution (probably this was not clear in my previous email) of a "pixel" in the image and the resolution in the scatter plot are not the same, namely, in the scatter plot the pixel keep the same screen size, while in the image it grows.

I should have said in the previous e-mail that my goal was to design a tool to mark a contour in an image pixel by pixel, so I need that the resolution of the pixels in both the image and the scatter plot be the same.

I think that Chaco is really a great tool, but it is not easy to learn.

Carlos.

On Thu, Oct 14, 2010 at 1:24 AM, bryce hendrix <[hidden email]> wrote:
On Wed, Oct 13, 2010 at 8:02 PM, Carlos A. Silva <[hidden email]> wrote:
Hi,

I would like to draw scatter points over an image. I know that there is ScatterInspector and ScatterInspectorOverlay class for drawing points, but their size is fixed as I make a zoom on the image. Also I did not manage to obtain a dot with a dimension of one pixel.


Carlos,

I think you're going down the wrong corner with the Scatter* tools, as it sounds like what you really want is just an overlay. Instead, have a look at the world_map.py example, which has 2 components, one is an image plot, and the other is a scatter plot. The scatter plot is overlayed on top of the image plot, which sounds exactly like what you're trying to do.

Another example worth looking at is xray_plot.py, which I wrote as a very simple example of how to make a plot, a custom tool, and a custom overlay all work together. Its about 160 lines long, including the code to generate the sample data.


Both of these allow for different markers, if you want a single pixel, use the 'pixel' marker instead of trying to get a 1 pixel dot.

Let me know if I misunderstood what you're trying to do so I can point you in the right direction.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

bryce hendrix-2
In reply to this post by Carlos A. Silva
Carlos, 

Unfortunately, the pixel marker doesn't support setting the size, otherwise the solution would be to set the size the same as the zoom amount. If you look at the overlay in the xray_plot.py example you should be able to see how overlays are done (in fact, you can re-use most of the code). The only thing you'll want to do differently is the following:

 * instead of getting the "selected" points, you want all of them within the visibile bounds, so change _get_selected_bounds to use the visible bounds instead of the selections key on the metadata

 * remove draw filled rectangles (or circle, or glyph) at each point's screen space based on the zoom size..

Let me know if you need more guidance, as this would probably make a good demo and I'm interested in making sure it works as you expect.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

Carlos A. Silva
In reply to this post by Robin Kraft
Hi Robin,

Thanks for the advice, but I would like to keep Chaco since I have other tools implemented with it that should interact with this one.

Carlos

On Thu, Oct 14, 2010 at 2:28 PM, Robin Kraft <[hidden email]> wrote:
Carlos,

I may be misunderstanding what you're trying to do, but if your project specs are flexible enough to include matplotlib, imshow might be a useful alternate solution - includes nice pixel resampling. I'm using it to map global raster data, and draw performance + zooming are really nice.

I'm on my phone so this code is taken out of context from a simple GUI I've been working on, but hopefully it will point you towards something useful. The matplotlib image tutorial is really helpful by the way: 

http://matplotlib.sourceforge.net/users/image_tutorial.html

import matplotlib.pyplot as plt

plt.imshow(img, cmap=color_map, norm=norm, interpolation="nearest", origin="upper")

-Robin


On Oct 14, 2010, at 5:05 AM, "Carlos A. Silva" <[hidden email]> wrote:

Hi Bryce,

Thank you for the directions. Yes, I agree that I must be in the wrong path and, from what I have learned so far from Chaco, that an overlay is the way to go. I considered a similar solution to world map, but did not know the option 'pixel' for the scatter plot; however, I have the same problem, when I zoom in the image, the resolution (probably this was not clear in my previous email) of a "pixel" in the image and the resolution in the scatter plot are not the same, namely, in the scatter plot the pixel keep the same screen size, while in the image it grows.

I should have said in the previous e-mail that my goal was to design a tool to mark a contour in an image pixel by pixel, so I need that the resolution of the pixels in both the image and the scatter plot be the same.

I think that Chaco is really a great tool, but it is not easy to learn.

Carlos.

On Thu, Oct 14, 2010 at 1:24 AM, bryce hendrix <[hidden email][hidden email]> wrote:
On Wed, Oct 13, 2010 at 8:02 PM, Carlos A. Silva <[hidden email][hidden email]> wrote:
Hi,

I would like to draw scatter points over an image. I know that there is ScatterInspector and ScatterInspectorOverlay class for drawing points, but their size is fixed as I make a zoom on the image. Also I did not manage to obtain a dot with a dimension of one pixel.


Carlos,

I think you're going down the wrong corner with the Scatter* tools, as it sounds like what you really want is just an overlay. Instead, have a look at the world_map.py example, which has 2 components, one is an image plot, and the other is a scatter plot. The scatter plot is overlayed on top of the image plot, which sounds exactly like what you're trying to do.

Another example worth looking at is xray_plot.py, which I wrote as a very simple example of how to make a plot, a custom tool, and a custom overlay all work together. Its about 160 lines long, including the code to generate the sample data.


Both of these allow for different markers, if you want a single pixel, use the 'pixel' marker instead of trying to get a 1 pixel dot.

Let me know if I misunderstood what you're trying to do so I can point you in the right direction.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email][hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

Carlos A. Silva
In reply to this post by bryce hendrix-2
Bryce,

Thanks again. The examples you suggested had important information for my problem. Also the code in the module markers helped to understand how the markers are created.

I changed the code of 'world_map' to allow to draw a path dot by dot that keeps the actual scale. In my solution I used an overlay as suggested by the 'x_ray_plot'.

The example 'x_ray_plot' generated two exceptions. One in the 'with gc:' statement and the other in the call 'gc.draw_marker_at_points(screen_pts, 3, DOT_MARKER)'. I think it has to do with my graphical back_end. I manage to solve both problems.

I am sending as an attach the modification to both examples in case it may help another person, but the code is not polished.

Carlos.

On Fri, Oct 15, 2010 at 12:13 AM, bryce hendrix <[hidden email]> wrote:
Carlos, 

Unfortunately, the pixel marker doesn't support setting the size, otherwise the solution would be to set the size the same as the zoom amount. If you look at the overlay in the xray_plot.py example you should be able to see how overlays are done (in fact, you can re-use most of the code). The only thing you'll want to do differently is the following:

 * instead of getting the "selected" points, you want all of them within the visibile bounds, so change _get_selected_bounds to use the visible bounds instead of the selections key on the metadata

 * remove draw filled rectangles (or circle, or glyph) at each point's screen space based on the zoom size..

Let me know if you need more guidance, as this would probably make a good demo and I'm interested in making sure it works as you expect.

Bryce

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev




_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

exp_world_map.py (12K) Download Attachment
x_ray_plot.py (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Drawing a point.

Peter Wang
On Fri, Oct 15, 2010 at 10:38 AM, Carlos A. Silva <[hidden email]> wrote:
> The example 'x_ray_plot' generated two exceptions. One in the 'with gc:'
> statement and the other in the call 'gc.draw_marker_at_points(screen_pts, 3,
> DOT_MARKER)'. I think it has to do with my graphical back_end. I manage to
> solve both problems.

Carlos,

Thanks for your marker suggestions - the original code had a problem
on Mac with WX.  I have made parallel changes in the xray_plot.py
example in the trunk.


Thanks,
Peter
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev