So I have two PIL images of RGBA. What I want to do is find all locations where the RGB values are the same and alpha is 255. It looks like this:
from PIL import Image
import numpy as np
img1 = np.array(Image.open(/path/to/img1).convert('RGBA'), float).reshape(32,32,4)
img2 = np.array(Image.open(/path/to/img2).convert('RGBA'), float).reshape(32,32,4)
# Checks to see if RGB of img1 == RGB of img2 in all locations that A=255
np.where((img1[:,:,:-1] == img2[:,:,:-1]) &\ # RGB check
(img1[:,:,3] == 255)) # Alpha check
But this results in operands could not be broadcast together with shapes (32,32,3) (32,32).
I didn't think I was trying to broadcast them together, I just wanted to find the indeces, which I guess in turn broadcasts them in this statement. Is there another way to do this, or a way to not broadcast unequal shapes?
img1[:, :, :-1]results in an array of shape32, 32, 3.img1[:, :, 3]results in an array of shape32, 32.np.wherewould allow for multiple "where" statements, not broadcast them together\for line continuation is unnecessary here. Python concatenates lines that are in unenclosed braces, brackets or parenthesis (as is the case here). In fact, PEP 8 (the "official" style guide) recommends using parenthesis to continue lines and never using the\for line continuation.