2

I have image numpy array (640,480,3) where X,Y is coordinates and (255 255 255) is a color mask for point

I try to get new 2d array(x,y), where X and Y is coordinates for point when color > zero..

I try this code and it works, but it takes too much processor time

enter code here
for x in range(edges.shape[0]):
     for y in range(edges.shape[1]):
          if edges[[x],[y],[0]]!=0:
             new.append([x,y])

1 Answer 1

2

You could slice the first element of last axis, compare it against 0 and then use np.argwhere to get those indices, which would be the x, y coordinates in a (N,2) shaped array.

Thus, the implementation would be simply -

new = np.argwhere( edges[...,0]!=0 )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.