7
1
For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows:
Task description
Given square 2D image A
with side 2^^N
, (N>0
), with common Z-order, or row-major representation of pixels in RAM. I need to run a hilbert curve through this image (Like a digital camera, where photodiodes are soldered in a hilbert curve and numbered and accessed in a 1-d ordered manner). Then pixels along this curve just layed down as a regular scanline in image B. So now any consequent samples in output array B now should represent spatially close points in input array A.
Example for N=2
Input: array A (imagination of 2D image)
0 1 E F
3 2 D C
4 7 8 B
5 6 9 A
Input: array A (1D actual layout in memory)
0 1 E F 3 2 D C 4 7 8 B 5 6 9 A
Output: array B (answer)
0 1 2 3 4 5 6 7 8 9 A B C D E F
Note, that values inside arrays are "values". In this example, for array B accidentally they became same as indices. So basically I want index mapping function B[i]=A[?], e.g B2 = A[E]. Hope code golfing helps.
Example for N=9:
Taken popular 512*512 test image. Each pixel was threated as 32bit integer, in RGBA format and algorithm proceeded:
Input:
Output:
Reverse question:
Here is reversed-task question on codegolf.
In terms of that question, I want to do opposite transform: "I want to Reravel image A, then Unravel to image B". In terms of examples of that question: I want to take photo the lion on the camera with hilbert-curved-sensor (look Output array for lion photo) and get that long "scanline of spatially close pixels" (Input for lion photo, in that question)
Reference implementation:
If i take d2xy()
function from LGPL sources found here I may write a following program, which works, but maybe not its best way:
#include "hilbert_curve.h"
int main(){
int *A,*B,i,x,y;
for(i=0;i<(1<<(N<<1));++i){
d2xy(N,i,&x,&y);
B[i]=A[y*(1<<N)+x];
}
}
Related. – Arnauld – 2018-12-12T15:01:59.193
@Arnauld Yes, i saw it previously. I don't need to copy few identical symbols with rotation, but different bytes or arbitary 2D image, to "hilbertize" it. – xakepp35 – 2018-12-12T15:05:31.660
And BTW: welcome to PPCG! Although this site is dedicated to recreational programming challenges and not recommended for real world problems, this looks like a perfectly valid challenge nonetheless -- though it might currently be a bit under-specified. – Arnauld – 2018-12-12T15:13:42.123
So, what is the input and what is the output? One could e.g. assume an input of
– Felix Palmen – 2018-12-12T15:13:58.177N
and and a list of carthesian coordinates visited along the curve as ouptut? Also please see https://codegolf.meta.stackexchange.com/a/8078/714203Also a word of warning, your text reads as if you're looking for an actual solution to use it. Nothing wrong with that, as long as it's a good challenge, but code-golf solutions tend to be more or less useless for realworld coding ;) – Felix Palmen – 2018-12-12T15:14:54.543
1Welcome to ppcg and nice first challenge! Unfortunately it has already been asked here. Hope you stick around anyway! – Post Rock Garf Hunter – 2018-12-12T15:15:33.313
1@PostLeftGarfHunter Nope, this is NOT an answer, but a reverse task! I I need his OUTPUT, and to produce INPUT! – xakepp35 – 2018-12-13T08:44:13.800
@PostLeftGarfHunter I probably made an error initially, i corrected it now. – xakepp35 – 2018-12-13T09:18:31.930
You may want to provide another test case for $N>2$. – Arnauld – 2018-12-13T10:41:53.127
I would recommend adding a link to the Hilbert Curve wiki to the question, so that people may more easily read about it. – Kamil Drakari – 2018-12-13T14:30:03.860
2@xakepp35 Just to clarify my suggestion, the purpose of test cases is to check that a submitted program is working properly, not to help understand the challenge (although they may sometimes do -- but the challenge should not rely on that). – Arnauld – 2018-12-13T15:56:21.917
@KamilDrakari just did that, btw, ppl on this site usually have google as their best friend! – xakepp35 – 2018-12-13T20:51:21.107