Add check for img.max() == 0
Fixed tests and stack.py for new version of mean