dikdimon commited on
Commit
bd26012
·
verified ·
1 Parent(s): c798f8e

Update asymmetric-tiling-sd-webui-3.0/scripts/improved_tiling_functions.py

Browse files
asymmetric-tiling-sd-webui-3.0/scripts/improved_tiling_functions.py CHANGED
@@ -328,4 +328,63 @@ def validate_multires_params(params):
328
  'transition_start': float(params.get('multires_start', 0.0)),
329
  'transition_end': float(params.get('multires_end', 0.3)),
330
  'sharpness': float(params.get('multires_sharpness', 1.0))
331
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  'transition_start': float(params.get('multires_start', 0.0)),
329
  'transition_end': float(params.get('multires_end', 0.3)),
330
  'sharpness': float(params.get('multires_sharpness', 1.0))
331
+ }
332
+
333
+ # =======================================================================
334
+ # 4. ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ (Возвращены для совместимости с тестами)
335
+ # =======================================================================
336
+
337
+ def create_circular_mask(h, w, center_x=0.5, center_y=0.5, radius=0.5, device='cpu'):
338
+ """
339
+ Создает круговую маску (белый круг на черном фоне).
340
+ Используется для BlendMode.CIRCULAR_REFLECT и тестов.
341
+ """
342
+ # Создаем сетку координат
343
+ y, x = torch.meshgrid(
344
+ torch.linspace(-1, 1, h, device=device),
345
+ torch.linspace(-1, 1, w, device=device),
346
+ indexing='ij'
347
+ )
348
+
349
+ # Сдвигаем центр
350
+ # Координаты от -1 до 1. Если центр 0.5, то смещение 0.
351
+ # center_x=0.5 -> offset=0.0
352
+ x = x - (center_x - 0.5) * 2
353
+ y = y - (center_y - 0.5) * 2
354
+
355
+ # Считаем расстояние от центра
356
+ dist = torch.sqrt(x*x + y*y)
357
+
358
+ # Создаем мягкую маску (сглаживание краев 0.1)
359
+ # 1.0 внутри радиуса, 0.0 снаружи
360
+ mask = 1.0 - torch.clamp((dist - (radius - 0.1)) / 0.2, 0, 1)
361
+
362
+ # Добавляем размерность каналов и батча (1, 1, H, W) для совместимости
363
+ if len(mask.shape) == 2:
364
+ mask = mask.unsqueeze(0).unsqueeze(0)
365
+
366
+ return mask
367
+
368
+ def create_fade_to_black_mask(h, w, strength=0.1, device='cpu'):
369
+ """
370
+ Создает виньетку (затемнение к краям).
371
+ """
372
+ y, x = torch.meshgrid(
373
+ torch.linspace(-1, 1, h, device=device),
374
+ torch.linspace(-1, 1, w, device=device),
375
+ indexing='ij'
376
+ )
377
+ dist = torch.sqrt(x*x + y*y)
378
+
379
+ # Нормализуем, чтобы углы были 1.0 (максимальное расстояние ~1.41)
380
+ dist = dist / 1.4142
381
+
382
+ # Инвертируем: центр белый (1), края черные (0)
383
+ # strength регулирует, как быстро начинается затемнение
384
+ threshold = 1.0 - strength
385
+ mask = 1.0 - torch.clamp((dist - threshold) / strength, 0, 1)
386
+
387
+ if len(mask.shape) == 2:
388
+ mask = mask.unsqueeze(0).unsqueeze(0)
389
+
390
+ return mask