-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
94 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,25 @@ | ||
# ComfyUI Diffusion Color Grading | ||
This is an Extension for [ComfyUI](https://github.com/comfyanonymous/ComfyUI), which is the joint research between me and <ins>TimothyAlexisVass</ins>. | ||
|
||
For more information, check out the original [Extension](https://github.com/Haoming02/sd-webui-diffusion-cg) for **Automatic1111**. | ||
For more information, check out the original [Extension](https://github.com/Haoming02/sd-webui-diffusion-cg) for **Automatic1111** Webui. | ||
|
||
## How to Use | ||
> Example workflows are included~ | ||
> An example workflow is included~ | ||
- Attach the **Recenter** or **RecenterXL** node between `Empty Latent` and `KSampler` nodes | ||
- Adjust the **strength** and **color** sliders as needed | ||
- Attach the **Normalization** or **NormalizationXL** node between `KSampler` and `VAE Decode` nodes | ||
- Attach the **Normalization** node between `KSampler` and `VAE Decode` nodes | ||
|
||
### Important: | ||
- The **Recenter** is "global." If you want to disable it during later part of the workflow *(**eg.** during `Hires. Fix`)*, you have to add another **Recenter** node and set its `strength` to `0.0`. | ||
- The **Recenter** effect is "global." If you want to disable it during other parts of the workflow *(**eg.** during `Hires. Fix`)*, you have to add another **Recenter** node with its `strength` set to `0.0`. | ||
|
||
## Examples | ||
|
||
<p align="center"> | ||
<b>SD 1.5</b><br> | ||
<img src="examples/1.5_off.jpg" width=384> | ||
<img src="examples/1.5_on.png" width=384> | ||
<br><code>Off | On</code> | ||
</p> | ||
|
||
<p align="center"> | ||
<b>SDXL</b><br> | ||
<img src="examples/xl_off.jpg" width=384> | ||
<img src="examples/xl_on.png" width=384> | ||
<br><code>Off | On</code> | ||
<img src="examples/off.jpg" width=384> | ||
<img src="examples/on.png" width=384><br> | ||
<code>Off | On</code> | ||
</p> | ||
|
||
## Known Issue | ||
- Doesn't work with some of the Samplers | ||
- Does not work with certain Samplers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,43 @@ | ||
DYNAMIC_RANGE = [18, 14, 14, 14] | ||
DYNAMIC_RANGE_XL = [20, 16, 16] | ||
import torch | ||
|
||
DYNAMIC_RANGE: float = 1.0 / 0.18215 / 0.13025 | ||
|
||
def normalize_tensor(x, r): | ||
|
||
def normalize_tensor(x: torch.Tensor, r: float) -> torch.Tensor: | ||
ratio = r / max(abs(float(x.min())), abs(float(x.max()))) | ||
return x * max(ratio, 0.99) | ||
return x * max(ratio, 1.0) | ||
|
||
|
||
def clone_latent(latent): | ||
def clone_latent(latent: dict) -> dict: | ||
return {"samples": latent["samples"].detach().clone()} | ||
|
||
|
||
class Normalization: | ||
|
||
@classmethod | ||
def INPUT_TYPES(s): | ||
return {"required": {"latent": ("LATENT",)}} | ||
return { | ||
"required": { | ||
"latent": ("LATENT",), | ||
"sdxl": ("BOOLEAN",), | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("LATENT",) | ||
FUNCTION = "normalize" | ||
CATEGORY = "latent" | ||
|
||
def normalize(self, latent): | ||
@torch.inference_mode() | ||
def normalize(self, latent: dict, sdxl: bool): | ||
norm_latent = clone_latent(latent) | ||
batches = latent["samples"].size(0) | ||
for b in range(batches): | ||
for c in range(4): | ||
norm_latent["samples"][b][c] = normalize_tensor( | ||
norm_latent["samples"][b][c], DYNAMIC_RANGE[c] | ||
) | ||
|
||
return (norm_latent,) | ||
|
||
|
||
class NormalizationXL: | ||
@classmethod | ||
def INPUT_TYPES(s): | ||
return {"required": {"latent": ("LATENT",)}} | ||
batchSize: int = latent["samples"].size(0) | ||
channels: int = 3 if sdxl else 4 | ||
|
||
RETURN_TYPES = ("LATENT",) | ||
FUNCTION = "normalize" | ||
CATEGORY = "latent" | ||
|
||
def normalize(self, latent): | ||
norm_latent = clone_latent(latent) | ||
batches = latent["samples"].size(0) | ||
for b in range(batches): | ||
for c in range(3): | ||
for b in range(batchSize): | ||
for c in range(channels): | ||
norm_latent["samples"][b][c] = normalize_tensor( | ||
norm_latent["samples"][b][c], DYNAMIC_RANGE_XL[c] | ||
norm_latent["samples"][b][c], DYNAMIC_RANGE / 2.5 | ||
) | ||
|
||
return (norm_latent,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters