Advertisement
dan-masek

Untitled

Apr 13th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # In place of `if abs(back[i,j]-mask[i,j])<5`
  2. abs_diff = np.fabs(back - mask)
  3. diff_lt5 = abs_diff < 5
  4.  
  5. # In place of `mask.itemset(i,j,0)` for the elements satisfying condition
  6. zeroed_mask = mask.copy()
  7. zeroed_mask[diff_lt5] = 0
  8.  
  9. # To find offsets not satisfying `mask.item(i,j)==mask.item(i,j+1)`
  10. adj_diff = np.zeros_like(diff_lt5)
  11. adj_diff[:,:-1] = (zeroed_mask[:,:-1] != mask[:,1:])
  12.  
  13. # Combine this with the previous condition (difference < 5)
  14. final_mask = np.logical_and(diff_lt5, adj_diff)
  15.  
  16. # Get coordinates of all the pixels satisfying conditions...
  17. coords = np.transpose(np.nonzero(final_mask))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement