GeekyGhost / ComfyUI-GeekyRemB

Custom Background Remover for ComfyUI to address some issues I've encountered with different background removers.
MIT License
34 stars 3 forks source link

GeekyRemB: Advanced Background Removal & Image Processing Node for ComfyUI

GeekyRemB Demo Video

GeekyRemB is a sophisticated image processing node that brings professional-grade background removal, blending, and animation capabilities to ComfyUI. It combines AI-powered processing with traditional image manipulation techniques to offer a comprehensive solution for complex image processing tasks.

Table of Contents

  1. User Guide
  2. Developer Documentation
  3. License
  4. Acknowledgements

User Guide

Installation

  1. Install ComfyUI if you haven't already. Follow the ComfyUI installation guide for detailed instructions.
  2. Clone the GeekyRemB repository into your ComfyUI custom nodes directory:
    git clone https://github.com/YourUsername/ComfyUI-GeekyRemB.git
  3. Install dependencies:
    pip install -r requirements.txt
  4. Restart ComfyUI to load the new node.

Features

Background Removal

Image Processing

Animation

Parameters Guide

Essential Settings

Advanced Settings

Optional Inputs


Developer Documentation

Technical Implementation

Blend Mode System

GeekyRemB features a sophisticated blending engine that handles complex image compositions with precision and efficiency.

class EnhancedBlendMode:
    @staticmethod
    def _ensure_rgba(img: np.ndarray) -> np.ndarray:
        # Ensures the image has an alpha channel
        ...

    @staticmethod
    def _apply_blend(target: np.ndarray, blend: np.ndarray, operation, opacity: float = 1.0) -> np.ndarray:
        # Core blending logic with alpha handling
        ...

    @classmethod
    def get_blend_modes(cls) -> Dict[str, Callable]:
        # Returns a dictionary of available blend modes
        ...

    @staticmethod
    def multiply(target: np.ndarray, blend: np.ndarray, opacity: float = 1.0) -> np.ndarray:
        # Implementation of Multiply blend mode
        ...

Key Features:

Animation Engine

The animation system provides smooth, configurable motion for dynamic image compositions.

class EnhancedAnimator:
    @staticmethod
    def animate_element(
        element: Image.Image,
        animation_type: str,
        animation_speed: float,
        frame_number: int,
        total_frames: int,
        x_start: int,
        y_start: int,
        canvas_width: int,
        canvas_height: int,
        scale: float,
        rotation: float,
        easing_func: Callable[[float], float],
        repeat: int,
        reverse: bool,
        delay: float,
        steps: int = 1,
        phase_shift: float = 0.0
    ) -> Tuple[Image.Image, int, int]:
        # Generates precise frame-by-frame animations
        ...

Features:

Background Removal

GeekyRemB supports multiple background removal strategies with sophisticated refinement techniques.

class EnhancedGeekyRemB:
    def remove_background_rembg(self, image: Image.Image) -> Tuple[Image.Image, Image.Image]:
        # AI-powered background removal using rembg
        ...

    def remove_background_chroma(self, image: Image.Image) -> Tuple[Image.Image, Image.Image]:
        # Color-based background removal using chroma key
        ...

Highlights:

Performance Optimizations

GeekyRemB incorporates several performance enhancements to ensure efficient processing:

Error Handling

Robust error management is implemented throughout GeekyRemB to ensure reliability:

try:
    result = self.process_frame(frame, background)
except Exception as e:
    logger.error(f"Processing error: {str(e)}")
    return self.fallback_process(frame)

Features:

Extending GeekyRemB

Developers can enhance and expand GeekyRemB by adding new features, optimizing existing ones, or integrating additional functionalities. Below are guidelines and best practices to assist in development:

Adding New Animation Types

To introduce a new animation type:

  1. Define the Animation in the AnimationType Enum:

    class AnimationType(Enum):
       NEW_ANIMATION = "new_animation"
       # Existing animations...
  2. Implement the Animation Logic in EnhancedAnimator.animate_element:

    elif animation_type == AnimationType.NEW_ANIMATION.value:
       # Define how the element should animate
       x += int(math.sin(progress * math.pi) * amplitude)
       y += int(math.cos(progress * math.pi) * amplitude)
       # Any additional transformations
  3. Update the INPUT_TYPES to Include the New Animation:

    "animation_type": ([anim.value for anim in AnimationType],),
  4. Document the New Animation in the User Guide under the Features and Parameters Guide sections.

Optimizing Blend Modes

To add or optimize a blend mode:

  1. Implement the Blend Mode Function in EnhancedBlendMode:

    @staticmethod
    def new_blend_mode(target: np.ndarray, blend: np.ndarray, opacity: float = 1.0) -> np.ndarray:
       # Define the blend operation
       def blend_op(t, b):
           return (t + b) / 2  # Example operation
       return EnhancedBlendMode._apply_blend(target, blend, blend_op, opacity)
  2. Register the Blend Mode in the get_blend_modes method:

    @classmethod
    def get_blend_modes(cls) -> Dict[str, Callable]:
       return {
           "new_blend_mode": cls.new_blend_mode,
           # Existing blend modes...
       }
  3. Update the INPUT_TYPES to include the new blend mode option.

  4. Document the Blend Mode in the User Guide.

Enhancing Mask Processing

To improve mask refinement techniques:

  1. Modify the EnhancedMaskProcessor.refine_mask Method to include new processing steps.
  2. Add Configuration Options in ProcessingConfig for any new parameters.
  3. Ensure Thread-Safety and Optimize Performance when adding new operations.

Notable Technical Achievements

  1. Seamless Handling of Images with Different Dimensions: Automatically adjusts images to ensure compatibility during processing and blending.
  2. Professional-Grade Blend Modes Matching Industry Standards: Implements a wide range of blend modes with accurate color and transparency handling.
  3. Efficient Batch Processing with Memory Optimization: Utilizes multi-threading and caching to process multiple frames efficiently.
  4. Sophisticated Alpha Channel Management: Maintains high-quality transparency handling across all operations.
  5. Frame-Accurate Animation System: Ensures that animations are smooth and precisely timed across all frames.
  6. Robust Error Recovery Mechanisms: Implements comprehensive error handling to maintain reliability during processing.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Note: Some included models may have separate licensing requirements for commercial use.


Acknowledgements

GeekyRemB builds upon several outstanding open-source projects:

Special thanks to:


For updates, issues, or contributions, please visit the GitHub repository. We welcome feedback and contributions from the community.