To calculate y coordinate of `imageData`, we should divide the index with `canvas.width` not with `canvas.height`. The current code works because the shape of canvas is square.