Create hilbert curve from image Source: https://www.assembla.com/code/egortitov/subversion/nodes/37/trunk/HilbertCurve