Issue
I want to find an RGB pixel in a numpy tri-dimensional array (X/Y/RGB) created with Pillow
conditions = np.logical_and(np.logical_and(array[:,:,0]==rgb[0],array[:,:,1]==rgb[1]),array[:,:,2]==rgb[2])
res = np.flip(np.transpose(np.where(conditions))).tolist()
It works like a charm.
However, I'd like to add a tolerance, so I just changed the conditions by:
abs(array[:,:,i]-rgb[i]) <= tolerance
But this does not work as expected, it returns zeros instead of pixels in the tolerated range. How can I add tolerance to my upper snippet?
Solution
Problem was calling np.array()
on a PIL Image automatically create a dtype=uint8
. During my logical tests value can go higher than 255, thus the unexpected behaviour
Logic can be changed to make it work, but array = np.array(im,dtype=np.int16)
also does the trick (even if it's less optimized)
Answered By - Turbolay
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.