Well, an image of 16 rows, 16 columns would have 256 pixels. That would be the first consideration, after running your code you have the following:
Name Size Bytes Class Attributes
i 1x1 8 double
n 1x1 8 double
r 1x1 8 double
x 1x6144 49152 double
So, x has 6,144 elements. How would you go from there to 16x16? You may discard, average or many other techniques, but I guess that you need to sort out first the dimensions.