You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Tutorials/Applying transform function on images.md
+88-72Lines changed: 88 additions & 72 deletions
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,24 @@
1
-
## Synopsis
2
-
3
1
Image transformations are fundamental operations in computer graphics and image processing that allow you to manipulate the position, size, shape, and perspective of images. This tutorial covers both affine and projective transformations, providing practical examples and clear explanations of how each parameter affects your image.
-**Matrix size**: 2×3(the bottom row [0, 0, 1] is implied)
12
+
-**Matrix size**: 2×3(the bottom row [0, 0, 1] is implied)
17
13
18
14
### Projective Transformations
19
15
20
16
-**Preserve**: Only collinearity (straight lines remain straight)
21
17
-**Properties**: Parallel lines may converge, creates perspective effects
22
18
-**Use cases**: Perspective correction, 3D projections, keystone correction
23
19
-**Matrix size**: 3×3 (full matrix required)
24
-
-**The key difference**: affine transformations might stretch, rotate, or shift a rectangle, but parallel lines remain parallel. Projective transformations can make a rectangle appear tilted or receding into the distance, with parallel lines converging to vanishing points.
20
+
21
+
**The key difference** is that affine transformations might stretch, rotate, or shift a rectangle, but parallel lines remain parallel. Projective transformations can make a rectangle appear tilted or receding into the distance, with parallel lines converging to vanishing points.
25
22
26
23
## The Transformation Matrix
27
24
@@ -43,21 +40,13 @@ Each parameter controls specific aspects of the transformation:
Image-js has functions `rotate()` and `transformRotate()`. `rotate()` function allows rotating an image by multiple of 90 degrees.
182
-
`transformRotate()` allows rotating an image by any degree. It also allows choosing the axe of rotation. So, for rotation, you have other functions that allow you to perform it.
183
-
Current tutorial just demonstrates the basic principle behind transformation of such kind.
184
-
:::
185
-
186
-

187
-
188
152
### Shearing
189
153
190
-
Shearing skews the image, making rectangles appear as parallelograms. Parameters b and d control shearing.
154
+
Shearing skews the image, making rectangles appear as parallelograms. Parameters `b` and `d` control shearing.

220
+
221
+
:::note
222
+
Image-js has functions `rotate()` and `transformRotate()`. `rotate()` function allows rotating an image by multiple of 90 degrees.
223
+
`transformRotate()` allows rotating an image by any degree. It also allows choosing the axe of rotation. So, for rotation, you have other functions that allow you to perform it.
224
+
Current tutorial just demonstrates the basic principle behind transformation of such kind.
225
+
:::
226
+
241
227
## Projective Transformations
242
228
243
229
Projective transformations use the full 3×3 matrix, including the bottom row parameters `g`, `h`, and `i`. These create perspective effects and can map rectangular images onto quadrilaterals.
244
230
245
231
### Understanding Perspective Parameters
246
232
247
-
`g`, `h`: Control perspective distortion
248
-
`i`: Normalization factor (typically 1)
233
+
-`g`, `h`: control horizontal and vertical perspective distortion.
234
+
-`i`: Normalization factor (typically 1). It simulates what happens in real vision:
235
+
236
+
1.`i` < 1: Objects farther away appear smaller
237
+
2.`i` > 1: Objects closer appear larger
238
+
3. The division by w' mathematically recreates this effect
239
+
240
+
The normalization factor is essentially artificial depth - it makes flat 2D coordinates behave as if they exist in 3D space with varying distances from the viewer.
241
+
The distortion allows modifying the angle under which you look at the image.
A common problem when taking photos of tall buildings is that they can look as if they're leaning backwards. This is known as the "keystone effect" (or the "tombstone effect"), and it can be a very distracting form of distortion in your images.
303
+
A common problem when taking photos of tall buildings is that they can look as if they're leaning backwards. This is known as the "[keystone effect](https://en.wikipedia.org/wiki/Keystone_effect)" (or the "tombstone effect"), and it can be a very distracting form of distortion in your images.
300
304
301
305
```ts
302
-
// Correct keystone effect - make trapezoid into rectangle
303
-
const keystoneMatrix = [
304
-
[1.2, 0.1, -50],
305
-
[0.05, 1.1, -20],
306
-
[0.0002, 0.0001, 1],
307
-
];
306
+
// Correcting keystone effect - make trapezoid into rectangle. These points work for an image with
307
+
//buildings. For more automatic approach you need to use something more advanced.
0 commit comments