MCPcopy Create free account
hub / github.com/chenfei-wu/TaskMatrix / blend_gt2pt

Function blend_gt2pt

visual_chatgpt.py:158–212  ·  view source on GitHub ↗
(old_image, new_image, sigma=0.15, steps=100)

Source from the content-addressed store, hash-verified

156
157
158def blend_gt2pt(old_image, new_image, sigma=0.15, steps=100):
159 new_size = new_image.size
160 old_size = old_image.size
161 easy_img = np.array(new_image)
162 gt_img_array = np.array(old_image)
163 pos_w = (new_size[0] - old_size[0]) // 2
164 pos_h = (new_size[1] - old_size[1]) // 2
165
166 kernel_h = cv2.getGaussianKernel(old_size[1], old_size[1] * sigma)
167 kernel_w = cv2.getGaussianKernel(old_size[0], old_size[0] * sigma)
168 kernel = np.multiply(kernel_h, np.transpose(kernel_w))
169
170 kernel[steps:-steps, steps:-steps] = 1
171 kernel[:steps, :steps] = kernel[:steps, :steps] / kernel[steps - 1, steps - 1]
172 kernel[:steps, -steps:] = kernel[:steps, -steps:] / kernel[steps - 1, -(steps)]
173 kernel[-steps:, :steps] = kernel[-steps:, :steps] / kernel[-steps, steps - 1]
174 kernel[-steps:, -steps:] = kernel[-steps:, -steps:] / kernel[-steps, -steps]
175 kernel = np.expand_dims(kernel, 2)
176 kernel = np.repeat(kernel, 3, 2)
177
178 weight = np.linspace(0, 1, steps)
179 top = np.expand_dims(weight, 1)
180 top = np.repeat(top, old_size[0] - 2 * steps, 1)
181 top = np.expand_dims(top, 2)
182 top = np.repeat(top, 3, 2)
183
184 weight = np.linspace(1, 0, steps)
185 down = np.expand_dims(weight, 1)
186 down = np.repeat(down, old_size[0] - 2 * steps, 1)
187 down = np.expand_dims(down, 2)
188 down = np.repeat(down, 3, 2)
189
190 weight = np.linspace(0, 1, steps)
191 left = np.expand_dims(weight, 0)
192 left = np.repeat(left, old_size[1] - 2 * steps, 0)
193 left = np.expand_dims(left, 2)
194 left = np.repeat(left, 3, 2)
195
196 weight = np.linspace(1, 0, steps)
197 right = np.expand_dims(weight, 0)
198 right = np.repeat(right, old_size[1] - 2 * steps, 0)
199 right = np.expand_dims(right, 2)
200 right = np.repeat(right, 3, 2)
201
202 kernel[:steps, steps:-steps] = top
203 kernel[-steps:, steps:-steps] = down
204 kernel[steps:-steps, :steps] = left
205 kernel[steps:-steps, -steps:] = right
206
207 pt_gt_img = easy_img[pos_h:pos_h + old_size[1], pos_w:pos_w + old_size[0]]
208 gaussian_gt_img = kernel * gt_img_array + (1 - kernel) * pt_gt_img # gt img with blur img
209 gaussian_gt_img = gaussian_gt_img.astype(np.int64)
210 easy_img[pos_h:pos_h + old_size[1], pos_w:pos_w + old_size[0]] = gaussian_gt_img
211 gaussian_img = Image.fromarray(easy_img)
212 return gaussian_img
213
214
215def cut_dialogue_history(history_memory, keep_last_n_words=500):

Callers 1

dowhileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected