Should this be
```
ymax = ymin + shape[1] - 1
```
?