I’m looking for a simple shearing algorithm. The image to be sheared is binary (0 – background pixels, 1 – foreground pixels), represented by a 2D array. It’s going to be used for handwritten digit slant correction so the shearing needs to be done on the x axis only.
I found some mathematical explanations, but not sure how to implement it correctly.
Thanks!
Just loop through the rows, starting with the bottom row, and keep track of the current pixelshift along the x-axis (as a floating- or fixed-point number). After every row you increase the shift by the desired constant slope. For drawing purposes you take the nearest integer of the corresponding pixelshift at every row.
In pseudocode this would be:
This is basically the Bresenham line drawing algorithm, so you should find plenty of implementation details for that.