3.5 Selecting objects

Simple example

It possible to select objects on the displayed images, just with a mouse right-click. The following code shows how to select 2 points:

# -*- coding: iso_8859_1 -*-
from aspylib import astro

#--- loads image data ---
Image = ["C:\\Images\\Image-1.fit"]
data = astro.get_imagedata(Image)

#--- display image ---
fig, ax = astro.display(data)
xy = astro.select(fig, ax, 2)
print xy


The image is displayed:


To perform the selection, the user places the mouse cursor on an object, and makes a right-click. Then the (x,y) image coordinates are copied to the console window, and stored in the list xy returned by the function astro.select(). When selecting two objects, the text below is displayed in the console:

--- loading FITS image ---
x= 252 y= 56
x= 228 y= 198
[[252, 56], [228, 198]]


It is possible to mark the position of the selected locations by using:

xy = astro.select(fig, ax, 2, color='r')

The color must be specified as in Matplotlib (see for instance here). Then the selection gives:


Selecting an unspecified number of objects

When the user doesn’t know in advance how many objects he wants to select, the following instruction must be used:

xy = astro.select(fig, ax, -1)

Then the user selects the objects one by one, by moving the mouse cursor over the objects to be selected and right-clicking. When the last object has been selected, then the selection process can be terminated by right-clicking outside of the image.

Table Of Contents

Previous topic

3.4 Geometrical transformations

Next topic

3.6 Fitting stars

This Page