There is no way in your code for col1 or col2 to ever decrease once they have increased.
You start col1 at 1, and you start col2 at 64, and you increase both col1 and col2 by 64 each until col2 becomes 3072 (48*64). As you increase both at the same time, col1 is going to be 63 less than col2, so when col2 is 3072, col1 will be 3009. And then you loop back over j=col1:col2 so j is going to become 3009, which is past the end of the matrix.
I recognize the code as having to do with steganography.