Fastest Way To Iterate Over All Pixels Of An Image In Python
i have already read an image as an array : import numpy as np from scipy import misc face1=misc.imread('face1.jpg') face1 dimensions are (288, 352, 3) i need to iterate over every
Solution 1:
You can use broadcasting
to perform broadcasted comparison against the white pixel : [255, 255, 255]
and ALL
reduce each row with .all(axis=-1)
and finally convert to int
dtype. This would give us the output you would have right after exiting the loop.
Thus, one implementation would be -
(~((face1 == [255,255,255]).all(-1).ravel())).astype(int)
Alternatively, a bit more compact version -
1-(face1 == [255,255,255]).all(-1).ravel()
Post a Comment for "Fastest Way To Iterate Over All Pixels Of An Image In Python"