I like the Hilbert Curve.
Your task for this challenge is to take an image (strictly a square image where all the sides are a power of two pixels wide) and unravel it line by line in a zig-zagging fashion and ravel it back up in a pseudo-Hilbert curve.
Unraveling
To unravel you will start with the pixel in the upper left hand corner and travel right until you arrive at the edge of the image. Once you have hit the edge of the image you will move down to the next row and begin traveling left until you hit the edge again. You will continue unraveling row by row switching the direction each time so you get one continuous curve. This should look like a well played game of snake
The result of unraveling should be an order of pixels that includes every pixel exactly once
Reraveling
Once you have an order for the pixels you will rearrange them on a new equally sized canvas following the path of a pseudo-Hilbert curve. For a 2**n
sized square image you should use the nth iteration of the pseudo-hilbert curve. Each pixel will be placed in exactly one spot on the new canvas. You should reravel the image so that the point originally in the top left (the start of our snake curve) will remain there and point in the bottom right (the end of our snake curve) will be placed in the top right.
I/O
Your program or function should take in an image of specified constraints via standard methods and output another image via standard methods.
Scoring
This is code-golf program with the fewest bytes wins.
Examples
Input
Output
Input
Output
Input
Output
I also recommend testing on a blank white or solid color image to make sure you are not missing any pixels.
Feel free to include your own results in your answers!