shift pixel for super-resolution with different scale factors Args: x: WxHxC or WxH sf: scale factor upper_left: shift direction
(x, sf, upper_left=True)
| 96 | |
| 97 | |
| 98 | def shift_pixel(x, sf, upper_left=True): |
| 99 | """shift pixel for super-resolution with different scale factors |
| 100 | Args: |
| 101 | x: WxHxC or WxH |
| 102 | sf: scale factor |
| 103 | upper_left: shift direction |
| 104 | """ |
| 105 | h, w = x.shape[:2] |
| 106 | shift = (sf - 1) * 0.5 |
| 107 | xv, yv = np.arange(0, w, 1.0), np.arange(0, h, 1.0) |
| 108 | if upper_left: |
| 109 | x1 = xv + shift |
| 110 | y1 = yv + shift |
| 111 | else: |
| 112 | x1 = xv - shift |
| 113 | y1 = yv - shift |
| 114 | |
| 115 | x1 = np.clip(x1, 0, w - 1) |
| 116 | y1 = np.clip(y1, 0, h - 1) |
| 117 | |
| 118 | if x.ndim == 2: |
| 119 | x = interp2d(xv, yv, x)(x1, y1) |
| 120 | if x.ndim == 3: |
| 121 | for i in range(x.shape[-1]): |
| 122 | x[:, :, i] = interp2d(xv, yv, x[:, :, i])(x1, y1) |
| 123 | |
| 124 | return x |
| 125 | |
| 126 | |
| 127 | def blur(x, k): |
no outgoing calls
no test coverage detected