mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-09 04:44:30 +08:00
Add random noise option to InjectNoiseToLatent -node
This commit is contained in:
parent
f6a65e32d3
commit
f9563afd7b
7
nodes.py
7
nodes.py
@ -2825,6 +2825,7 @@ class InjectNoiseToLatent:
|
||||
},
|
||||
"optional":{
|
||||
"mask": ("MASK", ),
|
||||
"mix_randn_amount": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1000.0, "step": 0.001}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2833,7 +2834,7 @@ class InjectNoiseToLatent:
|
||||
|
||||
CATEGORY = "KJNodes/noise"
|
||||
|
||||
def injectnoise(self, latents, strength, noise, normalize, average, mask=None):
|
||||
def injectnoise(self, latents, strength, noise, normalize, average, mix_randn_amount=0, mask=None):
|
||||
samples = latents.copy()
|
||||
if latents["samples"].shape != noise["samples"].shape:
|
||||
raise ValueError("InjectNoiseToLatent: Latent and noise must have the same shape")
|
||||
@ -2849,6 +2850,10 @@ class InjectNoiseToLatent:
|
||||
if mask.shape[0] < noised.shape[0]:
|
||||
mask = mask.repeat((noised.shape[0] -1) // mask.shape[0] + 1, 1, 1, 1)[:noised.shape[0]]
|
||||
noised = mask * noised + (1-mask) * latents["samples"]
|
||||
if mix_randn_amount > 0:
|
||||
rand_noise = torch.randn_like(noised)
|
||||
noised = ((1 - mix_randn_amount) * noised + mix_randn_amount *
|
||||
rand_noise) / ((mix_randn_amount**2 + (1-mix_randn_amount)**2) ** 0.5)
|
||||
samples["samples"] = noised
|
||||
return (samples,)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user