[SciPy-User] Extract a segment from a 2D array

David Baddeley david_baddeley at yahoo.com.au
Sun Jan 23 19:31:36 EST 2011


I'd probably use scipy.ndimage.map_coordinates

eg: (assuming your array is called data)

#define the line parametrically
len = sqrt(32**2 + 30**2) #length of line
t = arange(0, len) #evenly spaced points along the line with unit spacing
x = 10 + 32*t/len 
y = 12 + 30*t/len

seg = scipy.ndimage.map_coordinates(data, array([x, y]).T)

this will interpolate between neighbouring pixels & give you an evenly spaced 
section through your data, rather than collecting all pixels - but 'all pixels' 
requires some notion of connectedness, and won't be evenly spaced.

cheers,
David


----- Original Message ----
From: Xavier Gnata <xavier.gnata at gmail.com>
To: scipy-user at scipy.org
Sent: Mon, 24 January, 2011 12:02:38 PM
Subject: [SciPy-User] Extract a segment from a 2D array

Hi,

Let's take an example:
I have a 100x100 2D array.
I want to extract all the values on a segment starting at (10,12) and 
ending at (42,42) and put them in a 1D array.
Of course I can code the type Bresenham's line algorithm but I think I 
reinventing the wheel.
What's the scipy way to deal with that? (If needed, I can use matplotlib)


@+,
Xavier

_______________________________________________
SciPy-User mailing list
SciPy-User at scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user



      



More information about the SciPy-User mailing list