AppendImage vs {wave0,wave1}

Hello Igor Support!

My current task is to distort an image with 20x20 pixels.
For the distortion I use an algebraic function.

What I do up to this day:
I transform every original pixel one-by-one to its new position and define its new rectangular borders.
Function DistortImage()
    Make/O/N=(20,20) image //the original image as 2d-Wave
    WAVE image = image
    image= mod(x+y,2)//checker's board
    Variable rows = DimSize(image,0)
    Variable columns = DimSize(image,1)
    Display/K=1
    Variable i,j
    for(j=0;j=rows-1;j+=1)
    for(i=0;i=columns-1;i+=1)
        String pixel = "color_" + num2str(i) + "_" + num2str(j)
        String borderx = "borderx" + num2str(i) + "_" + num2str(j)
        String bordery = "bordery" + num2str(i) + "_" + num2str(j)
        Make/O/N=(1,1) $pixel //represents one pixel as a single image
        Make/O/N=2 $borderx
        Make/O/N=2 $bordery
        WAVE color = $pixel
        WAVE border_x = $borderx
        WAVE border_y = $bordery
        color = image[i][j]
        border_x[0]=squared(i-0.5,j,0)
        border_x[1]=squared(i+0.5,j,0)
            border_y[0]=squared(i,j-0.5,1)
        border_y[1]=squared(i,j+0.5,1)
        AppendImage $pixel vs {$borderx, $bordery}
        ModifyImage $pixel ctab= {0.8,1.1,Grays,0}
    endfor
    endfor
End


Function squared(x,y,bit) // some "random" function to scatter the pixels in a non-linear way
    Variable x
    Variable y
    Variable bit
     if (bit==0)
        Variable x_out = (x+2)^2-(y+2)
        return x_out
    endif
    if (bit==1)
        Variable y_out= (((y+2)^2)/(x+30))+x/2
        return y_out
    endif
End

This approach is inefficient. The math behind the distortion only accounts to less than 1% of the computing time. For every single pixel, IGOR creates three waves. These waves are tiny, they only contain two elements. Yet, they fill up one "slot" in the Databrowser. For a 100x100 image, this sums up to 30,000 seperate waves. The effect is, that IGOR is progressively slowed down with every new additionally created wave.
The cause of all this trouble is this line:

AppendImage wave0 vs {wave1, wave2}

This command only works with seperate waves. It neither accepts subsets of bigger 1D-Waves, nor the columns of a matrix.

So, is there any workaround to this restriction?

If not, which other techniques may I look out for in order to distort an image ?
You are trying to solve the problem the hard way. Instead, use the ImageInterpolate operation with the method "Warp". To see the details of the implementation check out the corresponding demo experiment. You can find it under File Menu->Example Experiments->Imaging->Image Warping Demo.

I hope this helps,

A.G.
WaveMetrics, Inc.

Alright. Your suggestion works fast and is superior in quite a few ways, and can still realise almost any distortion I can think of. I have switched to this method now.

Thanks, Igor!