28
3
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!
Is it okay to take an array of RGB values instead of an image as the input? What about output? – JungHwan Min – 2016-12-02T04:10:44.800
@JHM No you cannot. You can choose whatever image format you want though, so if your language doesn't have builtin image support you can use an uncompressed .ppm file which is very similar to an array of RGB values. – Post Rock Garf Hunter – 2016-12-02T17:33:12.503