MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / shift_pixel

Function shift_pixel

ldm/modules/image_degradation/bsrgan_light.py:98–124  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

96
97
98def 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
127def blur(x, k):

Callers 2

degradation_bsrganFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected