I have loaded image as a numpy array using pillow and the dimensions of the resulting numpy array is (184, 184, 4), i.e it's a 184x184 pixel image with each pixel having RGBA dimensions.
For all practical purposes my application just needs to know if a pixel is black or not and hence I just need a 184x184 np array with 0, 1's.
I am new to numpy and particularly image manipulation, wanted to know if there is a faster method to do it.
I tried the naive implementation of checking each pixel in a loop, which appears to be too costly.
If I understand correctly, you have an array with shape (184,184,4) and you want to get a boolean array with shape (184,184) depending on whether the final dimension is equal to [0,0,0,0]
>>> image = np.random.randint(0,255,size=(184,184,4)) #Generate random image >>> isBlack = np.int64(np.all(image[:,:,:3]==0,axis=2))
But how does it work? It seems like magic! Numpy is kind of magical. That's why we like it. In this case: