Skip to content

Commit 436769c

Browse files
author
Marc Rasi
committed
address fan comments
1 parent cd2d1c2 commit 436769c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Sources/SwiftFusion/Image/Patch.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ extension Tensor where Scalar == Double {
3232
= bilinear
3333
) -> Tensor<Scalar> {
3434
precondition(self.shape.count == 3, "image must have shape height x width x channelCount")
35-
let patchShape: TensorShape = [Int(region.rows), Int(region.cols), self.shape[2]]
35+
let patchShape: TensorShape = [region.rows, region.cols, self.shape[2]]
3636
var patch = Tensor<Scalar>(zeros: patchShape)
3737
for i in 0..<region.rows {
3838
for j in 0..<region.cols {
39-
let vDest = Vector2(Double(j) + 0.5, Double(i) + 0.5)
40-
- 0.5 * Vector2(Double(region.cols), Double(region.rows))
41-
patch.differentiableUpdate(i, j, to: resample(self, region.center * vDest))
39+
// The position of the destination pixel in the destination image, in `(u, v)` coordinates.
40+
let uvDest = Vector2(Double(j) + 0.5, Double(i) + 0.5)
41+
42+
// The position of the destination pixel in the destination image, in coordinates where the
43+
// center of the destination image is `(0, 0)`.
44+
let xyDest = uvDest - 0.5 * Vector2(Double(region.cols), Double(region.rows))
45+
46+
patch.differentiableUpdate(i, j, to: resample(self, region.center * xyDest))
4247
}
4348
}
4449
return patch

doc/ImageOperations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ We have three coordinate systems for images:
88
and column in a matrix. The origin is `(i=0, j=0)` in the top-left.
99
- `(u, v)` are *float* coordinates, `u` is horizontal (associated with `j`) and
1010
`v` is vertical (associated with `i`).
11-
- (x, y) are *float* coordinates, like `(u, v)`, but are "calibrated": `(x=0.0,
11+
- `(x, y)` are *float* coordinates, like `(u, v)`, but are "calibrated": `(x=0.0,
1212
y=0.0)` is the optical axis.
1313

1414
Pixel `(i, j)` is the square bounded by the corners with coordinates

0 commit comments

Comments
 (0)