Let's look at the relevant bits of your code, shall we?
For your reshape call to make sense, x must have N*N elements.
Does it? That imresize call implies it will have 128*128 elements (or perhaps 128*128*3.)
How do you fit 16,384 elements into a 4,096 element grid?