Skewing an image based off a function

  • Thread starter Thread starter m1ke_
  • Start date Start date
  • Tags Tags
    Function Image
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
m1ke_
Messages
21
Reaction score
0
Hello,

Suppose I have the function x = A*log(B*y) where A and B are constants, y is the height of a row of pixels, and x is how much that row of pixels needs to be translate right or left. How would you recommend incorporating this into code as to minimize distortion?

I have tried writing my own programs, however the images come out with lines where you can see the shifting as well as pixelated in regions. I have also looked into polynomial version of cp2tform but have had little success (possibly from not understanding it fully, it seems like there are only a few examples of how to use it).
 
Physics news on Phys.org
I figured out how to do it, and figured I would post my method for those who are curious or may be struggling with the same experience.

You need to create a Tform that performs the mapping T(x,y) = (u,v). In my case T(x,y) = ( x + A*log(B*y), y).

You must create a function (lets says its called functf) that does this, it may look as follows:

function U = functf(X, unused)

x = X(:,1);
y = X(:,2);

d = @y A*log(B*y);

U(:,1) = x + d(y);
U(:,2) = y;

end

You must then make a second function that is the inverse mapping(lets say functi)

You now make a tform as follows:

>> tform = maketform( 'custom', 2, 2, @functf, @functi, []);

the tform should be created, if not make sure you have the @ sign (screwed me up for a bit). Then to apply it to the image is the same as normal.

>> imnew = imtransform(image, tform);