python - Return row/column values from array underneath lines -
what i'm trying generate multiple lines on binary image based on length , angle. return of row/column values along pixel values underneath lines , place them python list. generate lines wrote function outputs start , end coordinates of each line. using these coordinates want generate lines , extract values.
to extract values horizontal line pixel (0,1) (3,1) can do:
a = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) pixels = a[1, 0:3]
or vertical:
pixels = a[0:3, 1]
which returns array of pixel values underneath line:
array([3, 4, 5]) array([1, 4, 7])
how apply method on lines angle? x1,y1 , x2,y2? these return (syntax) errors:
a([0,0], [2,2]) a([0,0]:[2,2]) a[0,0:2,2]
i'm looking similiar 'improfile' in matlab. many help!
you can use scikits-image's draw
module , draw.line method:
>>> skimage.draw import line >>> y0 = 1; x0 = 1; y1 = 10; x1 = 10; >>> rr, cc = line(y0, x0, y1, x1)
rr
, cc
contain row , column indexes of values line passes. can access values as:
>>> values = img[rr, cc]
assuming img
name of image.
note implementation not offer interpolation or subpixel accuracy angles different 45 degree intervals. create discrete stepped line between points , b passes through whole pixels.
Comments
Post a Comment