How to get all pixel coordinates in an area specified in an image in python?
问题 The area in image is defined by 4 coordinates x1,y1,x2,y2,x3,y3,x4,y4 and I want to retrieve all the pixel coordinates x,y inside that area. 回答1: Assuming a rectangular shape, you can use np.mgrid to generate a coordinate matrix for the points between your top left and bottom right corners. X, Y = np.mgrid[xmin:xmax, ymin:ymax] and convert them to a bidimensional array of coordinates with np.vstack((X.ravel(), Y.ravel())) EDIT: arbitrary shapes As Mark Setchell pointed out, there is nothing