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

Function shift_pixel

ldm/modules/image_degradation/bsrgan.py:99–125  ·  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

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

Callers 2

degradation_bsrganFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected