Can a neural network learn to predict a number given a binarized image of a rectangle?
It can definitely be learned, the question is the approach. It would be expensive and difficult from a modeling directive to do this Densely, so usually convolutions are the way to go. An issue with convolutions is that is generally focuses on equivariant and relative features, so if you need specific location within the approach might be worth the simple alteration of CoordConv. Regardless of approach, that type of input to output is possible, you just have to consider it when modeling.