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)
| 44 | |
| 45 | |
| 46 | def 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 | |
| 66 | def apply_scale_and_shift(pred, gt, mask=None): |
no test coverage detected