Skewing an image based off a function

  • Thread starter Thread starter m1ke_
  • Start date Start date
  • Tags Tags
    Function Image
AI Thread Summary
The discussion focuses on implementing a function to translate pixel rows using the equation x = A*log(B*y), where A and B are constants, y represents the height of the pixel row, and x indicates the translation amount. The goal is to minimize distortion in the resulting images. The user shares their method for creating a transformation function, T(x,y) = (x + A*log(B*y), y), which involves defining a custom function (functf) to perform the mapping and an inverse function (functi) for the transformation. They emphasize the importance of correctly using the @ sign when creating the transformation object with maketform and applying it with imtransform to achieve the desired image manipulation without visible distortion or pixelation.
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);
 
Back
Top