Assume your image is of size h x w . Then the number of total patches with patch size a x b is calculated as [ h - a + 1 ] x [ w - b + 1].  So given the index of a patch (what you have), you can compute the location of the top-left corner of a patch according to the following formula:
x = idx % [h - a + 1]
y = idx // [h - a + 1]