More tests for image.py and stack.py and corresponding fixes to functions