334
334
function array_max! (a, b)
335
335
a .= max .(a, b)
336
336
end
337
- function window (k, h= 1 )
338
- r = k ÷ 2
339
- w = collect (- (k - 1 - r): 1.0 : r)
340
- w .= h .* (1 .- (abs .(w) ./ r) .^ 2 )
337
+ function gausswin (n, h= 1 )
338
+ g (x, σ) = exp (- 0.5 * (x / σ)^ 2 )
339
+ h * g .(range (- 0.5 , 0.5 , n), 0.5 / 2.5 )
341
340
end
342
341
function randommaskcolor (colors)
343
342
colors = ascolor .(unique (colors))
@@ -349,9 +348,9 @@ function randommaskcolor(colors)
349
348
rh = 30
350
349
h_slots = zeros (360 ) .+ 0.05
351
350
s2max = 0.6
352
- win_l = window (2 rl + 1 )
353
- win_l2 = window (2 rl2 + 1 )
354
- win_h = window (2 rh + 1 )
351
+ win_l = gausswin (2 rl + 1 )
352
+ win_l2 = gausswin (2 rl2 + 1 )
353
+ win_h = gausswin (2 rh + 1 )
355
354
for c in colors
356
355
li = clamp (round (Int, c[3 ] * 255 ), 0 , 255 ) + 1
357
356
array_max! (@view (l_slots[li- rl+ rl2: li+ rl+ rl2]), win_l) # 明度避让以保证对比度
@@ -387,7 +386,7 @@ function randommaskcolor(colors)
387
386
end
388
387
l_slots = l_slots[1 + rl2: 256 + rl2]
389
388
w = ones (length (l_slots))
390
- w[51 : end - 51 ] .+ = window (256 - 101 , 7 ) # 中间调回避
389
+ w[51 : end - 51 ] .+ = gausswin (256 - 101 , 7 ) # 中间调回避
391
390
array_max! (@view (w[1 : end ÷ 2 ]), 3 ) # 高亮偏好
392
391
l_slots .*= w
393
392
l2 = rand_argmin (l_slots) / 255
0 commit comments