I actually figured it out, I had inputed the images as RGB when they were actually greyscale. I fixed this and the code is working now.