Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
flex image contrast
  • Loading branch information
ryanontheinstide committed Sep 24, 2024
1 parent 16e1360 commit 50d6f9a
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def get_description(cls):
FlexImageColorGrade,
FlexImageTiltShift,
FlexImageParallax,
FlexImageContrast,

)

Expand Down Expand Up @@ -313,6 +314,7 @@ def get_description(cls):
"FlexImageColorGrade": FlexImageColorGrade,
"FlexImageTiltShift": FlexImageTiltShift,
"FlexImageParallax": FlexImageParallax,
"FlexImageContrast": FlexImageContrast,
#opacity xp
# "FlexDepthBasedMaskOpacity": FlexDepthBasedMaskOpacity,
# "DepthBasedMaskOpacity": DepthBasedMaskOpacity,
Expand Down
22 changes: 22 additions & 0 deletions node_configs/node_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,28 @@ def add_node_config(node_name, config):
"""
}

add_node_config("FlexImageContrast", {
"TOP_DESCRIPTION": "Adjusts the contrast and brightness of the image, with an option to preserve luminosity.",
"ADDITIONAL_INFO": """
- `contrast`: Controls the amount of contrast adjustment (0.0 to 3.0). Values greater than 1.0 increase contrast, while values less than 1.0 decrease it.
- `brightness`: Adjusts the overall brightness of the image (-1.0 to 1.0). Positive values brighten the image, negative values darken it.
- `preserve_luminosity`: When enabled, maintains the overall luminosity of the image after applying contrast and brightness adjustments (True/False).
- `feature_param`: Parameter to modulate based on the feature. Options are "contrast", "brightness", "preserve_luminosity", "None".
This node allows for dynamic adjustment of image contrast and brightness, with the ability to preserve the overall luminosity of the image. It's useful for enhancing image details, adjusting exposure, or creating dramatic lighting effects.
The contrast adjustment is applied around the mean value of the image, which helps maintain the overall balance of the image. The brightness adjustment is applied uniformly across the image.
When 'preserve_luminosity' is enabled, the node calculates and adjusts the final luminosity to match the original image, which can help prevent over-brightening or over-darkening when applying strong contrast adjustments.
Use cases include:
1. Enhancing low-contrast images
2. Creating high-contrast, dramatic effects
3. Correcting under or overexposed images
4. Dynamically adjusting image tone based on audio or other features
"""
})

add_node_config("FlexImageEdgeDetect", {
"TOP_DESCRIPTION": "Applies edge detection to the image using the Canny algorithm.",
"ADDITIONAL_INFO": """
Expand Down
40 changes: 39 additions & 1 deletion nodes/images/flex_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,42 @@ def apply_effect_internal(self, image: np.ndarray, shift_x: float, shift_y: floa

result = image[new_y, new_x]

return np.clip(result, 0, 1)
return np.clip(result, 0, 1)

class FlexImageContrast(FlexImageBase):
@classmethod
def INPUT_TYPES(cls):
return {
**super().INPUT_TYPES(),
"required": {
**super().INPUT_TYPES()["required"],
"contrast": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 3.0, "step": 0.01}),
"brightness": ("FLOAT", {"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01}),
"preserve_luminosity": ("BOOLEAN", {"default": True}),
}
}

@classmethod
def get_modifiable_params(cls):
return ["contrast", "brightness", "preserve_luminosity", "None"]

def apply_effect_internal(self, image: np.ndarray, contrast: float, brightness: float, preserve_luminosity: bool, **kwargs) -> np.ndarray:
# Convert to float32 if not already
image = image.astype(np.float32)

# Apply brightness adjustment
result = image + brightness

# Apply contrast adjustment
mean = np.mean(result, axis=(0, 1), keepdims=True)
result = (result - mean) * contrast + mean

if preserve_luminosity:
# Calculate current and original luminosity
current_luminosity = np.mean(result)
original_luminosity = np.mean(image)

# Adjust to preserve original luminosity
result *= original_luminosity / current_luminosity

return np.clip(result, 0, 1)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui_ryanonyheinside"
description = "Custom nodes introducing particle simulations, optical flow, audio manipulation & reactivity, and temporal masks"
version = "1.8.2"
version = "1.8.3"
license = {file = "LICENSE"}
dependencies = ["opencv-python==4.10.0","scipy","torchaudio", "pillow","librosa","pymunk==6.8.1","matplotlib","openunmix","mido"]

Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*Examples showcasing various effects using particle emitters, vortices, and other node features*

##### 🆕 Recent Updates
-9/25/24 - **FlexImageContrast**: Adds contrast and brightness to images, with an option to preserve luminosity.
-9/15/24 - **alot** Depth From Shape, Audio Pitch Feature, Pitch Range filters, new MIDI keybord for Pitch Range specification, Image from audio, mask from audio, Improved depth chamber, wave propagation, emanating rings, and a lot more
- 9/8/24 - **Area Feature**: Adds area as a driving reactivity feature!
- 9/7/24 - **Proximity Feature**: Adds proximity as a driving reactivity feature! Allows for the distince of objects from one another to control other nodes.
Expand Down

0 comments on commit 50d6f9a

Please sign in to comment.