The code you posted has a bug. Compare the height of the two images with the heigth of the original one. Then have a look at the pseudo-code I posted before.
If i want to split horizontally and vertically by passing the co ordinates at any position, how can i achieve this.
Not sure I understand what you're asking. If you know at which position you want to split the image, you can use appropriate parameters in the call to getSubimage.