MEA3
Study nr. 20146419
Mini project - Shearing
The image used in the program.
1. Explanation of the algorithm
The program takes pixels and moves them a set amount. But the amount moved depends of where the pixel is located in the original picture. E.g. a pixel located at position 0.0 will be moved by a factor of 0.5 in the x direction, and a factor of 0 in the y direction. While a picture located in opposite corner of the corner will be moved by a factor of 0 in the x direction and a factor of 0 in the y direction. That’s the difference between simply moving all pixels the same amount, whereas shearing makes the image skewed.
2. The code
a. Forward mapping code:
1. #include
2. #include
3. #include
4. #include …show more content…
We also load our input image in line 13, as a grayscale image. Also Bx and By values are initialized, which are the factors which the image is sheared. The offset integers are used to make the frame of the picture larger, so the sheared part is visible.
The first two functions in the code r1Calc and c1Calc are used to map the pixels to their new position. This is the forward mapping equation. They then return a value (r1 and c1) which are used in the main function to map out the output image.
Frederik Homann Østergaard
MEA3
Study nr. 20146419
This is the main function of the code. First off we make a matrix for our output image, which is consisting of zeroes. We also make it wider with the offset integers. We then creates our for loops, which goes through each pixel in the source image. For each pixel the r1Calc and c1Calc functions are called, and the shearing equation is then run to determine their new position. This position is then saved to the out matrix, if the new pixel value is within the boundaries set up by the if statement. If not it returns the value as 0. We then display the source image, and the new sheared image.
The pictures so far shows the code for forward mapping.
This is the r1Calc and c1Calc functions with the backwards mapping equation.
Frederik Homann Østergaard