MCPcopy Create free account
hub / github.com/CompVis/diff2flow / get_batch_scale_and_shift

Function get_batch_scale_and_shift

diff2flow/dataset/depth_utils.py:46–63  ·  view source on GitHub ↗

Returns the scale and shift between two images More precisely, we find (b1, b2) such that img1 = b1 + b2*img2 We model this problem as a least-squares problem: (b1*, b2*) = argmin_(b1, b2) ||img1 - b1 + b2*img2||_(L2)

(img1, img2, mask=None)

Source from the content-addressed store, hash-verified

44
45
46def get_batch_scale_and_shift(img1, img2, mask=None):
47 """
48 Returns the scale and shift between two images
49 More precisely, we find (b1, b2) such that img1 = b1 + b2*img2
50
51 We model this problem as a least-squares problem:
52 (b1*, b2*) = argmin_(b1, b2) ||img1 - b1 + b2*img2||_(L2)
53
54 """
55 assert len(img1.shape) == 4, "img1 must be of shape (batch_size, channels, height, width)"
56 shifts, scales = [], []
57 for i in range(img1.shape[0]):
58 shift, scale = get_scale_and_shift(img1[i], img2[i], None if mask is None else mask[i])
59 shifts.append(shift)
60 scales.append(scale)
61 shifts = torch.stack(shifts)
62 scales = torch.stack(scales)
63 return shifts, scales
64
65
66def apply_scale_and_shift(pred, gt, mask=None):

Callers 1

apply_scale_and_shiftFunction · 0.85

Calls 1

get_scale_and_shiftFunction · 0.85

Tested by

no test coverage detected