Skewing an image based off a function

In summary, the conversation discusses how to incorporate a function into code in order to minimize distortion in images. The function mentioned is x = A*log(B*y) and it is used to translate pixels left or right. The speaker has tried writing their own programs and using a polynomial version of cp2tform, but has had little success. They then share their method of creating a Tform and inverse mapping to apply the function to images.
  • #1
m1ke_
21
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
  • #2
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);
 

What is image skewing?

Image skewing is a process of altering the shape or angle of an image using a mathematical function. This can be done to stretch, compress, or distort the image in a desired way.

How does image skewing work?

Image skewing uses a function to transform the coordinates of each pixel in the image. The function determines how much the pixel's position will change, resulting in a distorted image.

What is the purpose of image skewing?

The purpose of image skewing is to manipulate the visual appearance of an image. It can be used for creative purposes, such as creating abstract or surreal images, or for practical purposes, such as correcting perspective distortion in architectural photography.

What are some common functions used for image skewing?

Some common functions used for image skewing include linear functions, quadratic functions, and trigonometric functions. These functions can be combined and modified to achieve different types of skewing effects.

What are the potential drawbacks of image skewing?

One potential drawback of image skewing is that it can result in loss of image quality or pixelation if not done carefully. It can also be a time-consuming process, especially for complex functions or high-resolution images.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
1
Views
844
  • Astronomy and Astrophysics
7
Replies
226
Views
11K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
651
  • Programming and Computer Science
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top