1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crateImage;
/// Compute the L1 loss between two images.
///
/// The L1 loss is defined as the sum of the absolute differences between the two images.
///
/// The L1 loss is defined as:
///
/// $ L1(a, b) = \frac{1}{N} \sum_{i=1}^{N} |a_i - b_i| $
///
/// where `a` and `b` are the two images and `N` is the number of pixels.
///
/// # Arguments
///
/// * `image1` - The first input image with shape (H, W, C).
/// * `image2` - The second input image with shape (H, W, C).
///
/// # Returns
///
/// The L1 loss between the two images.
///
/// # Example
///
/// ```
/// use kornia_rs::image::{Image, ImageSize};
///
/// let image1 = Image::<f32, 1>::new(
/// ImageSize {
/// width: 2,
/// height: 3,
/// },
/// vec![0f32, 1f32, 2f32, 3f32, 4f32, 5f32],
/// )
/// .unwrap();
///
/// let image2 = Image::<f32, 1>::new(
/// ImageSize {
/// width: 2,
/// height: 3,
/// },
/// vec![5f32, 4f32, 3f32, 2f32, 1f32, 0f32],
/// )
/// .unwrap();
///
/// let l1_loss = kornia_rs::metrics::l1_loss(&image1, &image2);
/// assert_eq!(l1_loss, 3.0);
/// ```
///
/// # Panics
///
/// Panics if the two images have different shapes.
///
/// # References
///
/// [Wikipedia - L1 loss](https://en.wikipedia.org/wiki/Huber_loss)