Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # In place of `if abs(back[i,j]-mask[i,j])<5`
- abs_diff = np.fabs(back - mask)
- diff_lt5 = abs_diff < 5
- # In place of `mask.itemset(i,j,0)` for the elements satisfying condition
- zeroed_mask = mask.copy()
- zeroed_mask[diff_lt5] = 0
- # To find offsets not satisfying `mask.item(i,j)==mask.item(i,j+1)`
- adj_diff = np.zeros_like(diff_lt5)
- adj_diff[:,:-1] = (zeroed_mask[:,:-1] != mask[:,1:])
- # Combine this with the previous condition (difference < 5)
- final_mask = np.logical_and(diff_lt5, adj_diff)
- # Get coordinates of all the pixels satisfying conditions...
- coords = np.transpose(np.nonzero(final_mask))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement