CenterPadCrop node (#3861)

* add centerpadcrop node

- Allows users to add padding to or crop images from the center
- Also outputs a white mask with the dimensions of the output image for use with outpainting

* add CenterPadCrop to NODES.md

Updates NODES.md with CenterPadCrop entry.

* remove mask & output class

- Remove "ImageMaskOutput" where both image and mask are output
- Remove ability to output mask from node

---------

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
This commit is contained in:
ymgenesis 2023-11-30 11:15:59 +01:00 committed by GitHub
parent 0beb08686c
commit 3e01c396e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 229 additions and 117 deletions

View File

@ -1,104 +1,106 @@
# List of Default Nodes # List of Default Nodes
The table below contains a list of the default nodes shipped with InvokeAI and their descriptions. The table below contains a list of the default nodes shipped with InvokeAI and
their descriptions.
| Node <img width=160 align="right"> | Function | | Node <img width=160 align="right"> | Function |
|: ---------------------------------- | :--------------------------------------------------------------------------------------| | :------------------------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------- |
|Add Integers | Adds two numbers| | Add Integers | Adds two numbers |
|Boolean Primitive Collection | A collection of boolean primitive values| | Boolean Primitive Collection | A collection of boolean primitive values |
|Boolean Primitive | A boolean primitive value| | Boolean Primitive | A boolean primitive value |
|Canny Processor | Canny edge detection for ControlNet| | Canny Processor | Canny edge detection for ControlNet |
|CLIP Skip | Skip layers in clip text_encoder model.| | CenterPadCrop | Pad or crop an image's sides from the center by specified pixels. Positive values are outside of the image. |
|Collect | Collects values into a collection| | CLIP Skip | Skip layers in clip text_encoder model. |
|Color Correct | Shifts the colors of a target image to match the reference image, optionally using a mask to only color-correct certain regions of the target image.| | Collect | Collects values into a collection |
|Color Primitive | A color primitive value| | Color Correct | Shifts the colors of a target image to match the reference image, optionally using a mask to only color-correct certain regions of the target image. |
|Compel Prompt | Parse prompt using compel package to conditioning.| | Color Primitive | A color primitive value |
|Conditioning Primitive Collection | A collection of conditioning tensor primitive values| | Compel Prompt | Parse prompt using compel package to conditioning. |
|Conditioning Primitive | A conditioning tensor primitive value| | Conditioning Primitive Collection | A collection of conditioning tensor primitive values |
|Content Shuffle Processor | Applies content shuffle processing to image| | Conditioning Primitive | A conditioning tensor primitive value |
|ControlNet | Collects ControlNet info to pass to other nodes| | Content Shuffle Processor | Applies content shuffle processing to image |
|Denoise Latents | Denoises noisy latents to decodable images| | ControlNet | Collects ControlNet info to pass to other nodes |
|Divide Integers | Divides two numbers| | Denoise Latents | Denoises noisy latents to decodable images |
|Dynamic Prompt | Parses a prompt using adieyal/dynamicprompts' random or combinatorial generator| | Divide Integers | Divides two numbers |
|[FaceMask](./detailedNodes/faceTools.md#facemask) | Generates masks for faces in an image to use with Inpainting| | Dynamic Prompt | Parses a prompt using adieyal/dynamicprompts' random or combinatorial generator |
|[FaceIdentifier](./detailedNodes/faceTools.md#faceidentifier) | Identifies and labels faces in an image| | [FaceMask](./detailedNodes/faceTools.md#facemask) | Generates masks for faces in an image to use with Inpainting |
|[FaceOff](./detailedNodes/faceTools.md#faceoff) | Creates a new image that is a scaled bounding box with a mask on the face for Inpainting| | [FaceIdentifier](./detailedNodes/faceTools.md#faceidentifier) | Identifies and labels faces in an image |
|Float Math | Perform basic math operations on two floats| | [FaceOff](./detailedNodes/faceTools.md#faceoff) | Creates a new image that is a scaled bounding box with a mask on the face for Inpainting |
|Float Primitive Collection | A collection of float primitive values| | Float Math | Perform basic math operations on two floats |
|Float Primitive | A float primitive value| | Float Primitive Collection | A collection of float primitive values |
|Float Range | Creates a range| | Float Primitive | A float primitive value |
|HED (softedge) Processor | Applies HED edge detection to image| | Float Range | Creates a range |
|Blur Image | Blurs an image| | HED (softedge) Processor | Applies HED edge detection to image |
|Extract Image Channel | Gets a channel from an image.| | Blur Image | Blurs an image |
|Image Primitive Collection | A collection of image primitive values| | Extract Image Channel | Gets a channel from an image. |
|Integer Math | Perform basic math operations on two integers| | Image Primitive Collection | A collection of image primitive values |
|Convert Image Mode | Converts an image to a different mode.| | Integer Math | Perform basic math operations on two integers |
|Crop Image | Crops an image to a specified box. The box can be outside of the image.| | Convert Image Mode | Converts an image to a different mode. |
|Image Hue Adjustment | Adjusts the Hue of an image.| | Crop Image | Crops an image to a specified box. The box can be outside of the image. |
|Inverse Lerp Image | Inverse linear interpolation of all pixels of an image| | Image Hue Adjustment | Adjusts the Hue of an image. |
|Image Primitive | An image primitive value| | Inverse Lerp Image | Inverse linear interpolation of all pixels of an image |
|Lerp Image | Linear interpolation of all pixels of an image| | Image Primitive | An image primitive value |
|Offset Image Channel | Add to or subtract from an image color channel by a uniform value.| | Lerp Image | Linear interpolation of all pixels of an image |
|Multiply Image Channel | Multiply or Invert an image color channel by a scalar value.| | Offset Image Channel | Add to or subtract from an image color channel by a uniform value. |
|Multiply Images | Multiplies two images together using `PIL.ImageChops.multiply()`.| | Multiply Image Channel | Multiply or Invert an image color channel by a scalar value. |
|Blur NSFW Image | Add blur to NSFW-flagged images| | Multiply Images | Multiplies two images together using `PIL.ImageChops.multiply()`. |
|Paste Image | Pastes an image into another image.| | Blur NSFW Image | Add blur to NSFW-flagged images |
|ImageProcessor | Base class for invocations that preprocess images for ControlNet| | Paste Image | Pastes an image into another image. |
|Resize Image | Resizes an image to specific dimensions| | ImageProcessor | Base class for invocations that preprocess images for ControlNet |
|Round Float | Rounds a float to a specified number of decimal places| | Resize Image | Resizes an image to specific dimensions |
|Float to Integer | Converts a float to an integer. Optionally rounds to an even multiple of a input number.| | Round Float | Rounds a float to a specified number of decimal places |
|Scale Image | Scales an image by a factor| | Float to Integer | Converts a float to an integer. Optionally rounds to an even multiple of a input number. |
|Image to Latents | Encodes an image into latents.| | Scale Image | Scales an image by a factor |
|Add Invisible Watermark | Add an invisible watermark to an image| | Image to Latents | Encodes an image into latents. |
|Solid Color Infill | Infills transparent areas of an image with a solid color| | Add Invisible Watermark | Add an invisible watermark to an image |
|PatchMatch Infill | Infills transparent areas of an image using the PatchMatch algorithm| | Solid Color Infill | Infills transparent areas of an image with a solid color |
|Tile Infill | Infills transparent areas of an image with tiles of the image| | PatchMatch Infill | Infills transparent areas of an image using the PatchMatch algorithm |
|Integer Primitive Collection | A collection of integer primitive values| | Tile Infill | Infills transparent areas of an image with tiles of the image |
|Integer Primitive | An integer primitive value| | Integer Primitive Collection | A collection of integer primitive values |
|Iterate | Iterates over a list of items| | Integer Primitive | An integer primitive value |
|Latents Primitive Collection | A collection of latents tensor primitive values| | Iterate | Iterates over a list of items |
|Latents Primitive | A latents tensor primitive value| | Latents Primitive Collection | A collection of latents tensor primitive values |
|Latents to Image | Generates an image from latents.| | Latents Primitive | A latents tensor primitive value |
|Leres (Depth) Processor | Applies leres processing to image| | Latents to Image | Generates an image from latents. |
|Lineart Anime Processor | Applies line art anime processing to image| | Leres (Depth) Processor | Applies leres processing to image |
|Lineart Processor | Applies line art processing to image| | Lineart Anime Processor | Applies line art anime processing to image |
|LoRA Loader | Apply selected lora to unet and text_encoder.| | Lineart Processor | Applies line art processing to image |
|Main Model Loader | Loads a main model, outputting its submodels.| | LoRA Loader | Apply selected lora to unet and text_encoder. |
|Combine Mask | Combine two masks together by multiplying them using `PIL.ImageChops.multiply()`.| | Main Model Loader | Loads a main model, outputting its submodels. |
|Mask Edge | Applies an edge mask to an image| | Combine Mask | Combine two masks together by multiplying them using `PIL.ImageChops.multiply()`. |
|Mask from Alpha | Extracts the alpha channel of an image as a mask.| | Mask Edge | Applies an edge mask to an image |
|Mediapipe Face Processor | Applies mediapipe face processing to image| | Mask from Alpha | Extracts the alpha channel of an image as a mask. |
|Midas (Depth) Processor | Applies Midas depth processing to image| | Mediapipe Face Processor | Applies mediapipe face processing to image |
|MLSD Processor | Applies MLSD processing to image| | Midas (Depth) Processor | Applies Midas depth processing to image |
|Multiply Integers | Multiplies two numbers| | MLSD Processor | Applies MLSD processing to image |
|Noise | Generates latent noise.| | Multiply Integers | Multiplies two numbers |
|Normal BAE Processor | Applies NormalBae processing to image| | Noise | Generates latent noise. |
|ONNX Latents to Image | Generates an image from latents.| | Normal BAE Processor | Applies NormalBae processing to image |
|ONNX Prompt (Raw) | A node to process inputs and produce outputs. May use dependency injection in __init__ to receive providers.| | ONNX Latents to Image | Generates an image from latents. |
|ONNX Text to Latents | Generates latents from conditionings.| | ONNX Prompt (Raw) | A node to process inputs and produce outputs. May use dependency injection in **init** to receive providers. |
|ONNX Model Loader | Loads a main model, outputting its submodels.| | ONNX Text to Latents | Generates latents from conditionings. |
|OpenCV Inpaint | Simple inpaint using opencv.| | ONNX Model Loader | Loads a main model, outputting its submodels. |
|Openpose Processor | Applies Openpose processing to image| | OpenCV Inpaint | Simple inpaint using opencv. |
|PIDI Processor | Applies PIDI processing to image| | Openpose Processor | Applies Openpose processing to image |
|Prompts from File | Loads prompts from a text file| | PIDI Processor | Applies PIDI processing to image |
|Random Integer | Outputs a single random integer.| | Prompts from File | Loads prompts from a text file |
|Random Range | Creates a collection of random numbers| | Random Integer | Outputs a single random integer. |
|Integer Range | Creates a range of numbers from start to stop with step| | Random Range | Creates a collection of random numbers |
|Integer Range of Size | Creates a range from start to start + size with step| | Integer Range | Creates a range of numbers from start to stop with step |
|Resize Latents | Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8.| | Integer Range of Size | Creates a range from start to start + size with step |
|SDXL Compel Prompt | Parse prompt using compel package to conditioning.| | Resize Latents | Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8. |
|SDXL LoRA Loader | Apply selected lora to unet and text_encoder.| | SDXL Compel Prompt | Parse prompt using compel package to conditioning. |
|SDXL Main Model Loader | Loads an sdxl base model, outputting its submodels.| | SDXL LoRA Loader | Apply selected lora to unet and text_encoder. |
|SDXL Refiner Compel Prompt | Parse prompt using compel package to conditioning.| | SDXL Main Model Loader | Loads an sdxl base model, outputting its submodels. |
|SDXL Refiner Model Loader | Loads an sdxl refiner model, outputting its submodels.| | SDXL Refiner Compel Prompt | Parse prompt using compel package to conditioning. |
|Scale Latents | Scales latents by a given factor.| | SDXL Refiner Model Loader | Loads an sdxl refiner model, outputting its submodels. |
|Segment Anything Processor | Applies segment anything processing to image| | Scale Latents | Scales latents by a given factor. |
|Show Image | Displays a provided image, and passes it forward in the pipeline.| | Segment Anything Processor | Applies segment anything processing to image |
|Step Param Easing | Experimental per-step parameter easing for denoising steps| | Show Image | Displays a provided image, and passes it forward in the pipeline. |
|String Primitive Collection | A collection of string primitive values| | Step Param Easing | Experimental per-step parameter easing for denoising steps |
|String Primitive | A string primitive value| | String Primitive Collection | A collection of string primitive values |
|Subtract Integers | Subtracts two numbers| | String Primitive | A string primitive value |
|Tile Resample Processor | Tile resampler processor| | Subtract Integers | Subtracts two numbers |
|Upscale (RealESRGAN) | Upscales an image using RealESRGAN.| | Tile Resample Processor | Tile resampler processor |
|VAE Loader | Loads a VAE model, outputting a VaeLoaderOutput| | Upscale (RealESRGAN) | Upscales an image using RealESRGAN. |
|Zoe (Depth) Processor | Applies Zoe depth processing to image| | VAE Loader | Loads a VAE model, outputting a VaeLoaderOutput |
| Zoe (Depth) Processor | Applies Zoe depth processing to image |

View File

@ -100,6 +100,61 @@ class ImageCropInvocation(BaseInvocation, WithWorkflow, WithMetadata):
) )
@invocation(
invocation_type="img_pad_crop",
title="Center Pad or Crop Image",
category="image",
tags=["image", "pad", "crop"],
version="1.0.0",
)
class CenterPadCropInvocation(BaseInvocation):
"""Pad or crop an image's sides from the center by specified pixels. Positive values are outside of the image."""
image: ImageField = InputField(description="The image to crop")
left: int = InputField(
default=0,
description="Number of pixels to pad/crop from the left (negative values crop inwards, positive values pad outwards)",
)
right: int = InputField(
default=0,
description="Number of pixels to pad/crop from the right (negative values crop inwards, positive values pad outwards)",
)
top: int = InputField(
default=0,
description="Number of pixels to pad/crop from the top (negative values crop inwards, positive values pad outwards)",
)
bottom: int = InputField(
default=0,
description="Number of pixels to pad/crop from the bottom (negative values crop inwards, positive values pad outwards)",
)
def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get_pil_image(self.image.image_name)
# Calculate and create new image dimensions
new_width = image.width + self.right + self.left
new_height = image.height + self.top + self.bottom
image_crop = Image.new(mode="RGBA", size=(new_width, new_height), color=(0, 0, 0, 0))
# Paste new image onto input
image_crop.paste(image, (self.left, self.top))
image_dto = context.services.images.create(
image=image_crop,
image_origin=ResourceOrigin.INTERNAL,
image_category=ImageCategory.GENERAL,
node_id=self.id,
session_id=context.graph_execution_state_id,
is_intermediate=self.is_intermediate,
)
return ImageOutput(
image=ImageField(image_name=image_dto.image_name),
width=image_dto.width,
height=image_dto.height,
)
@invocation("img_paste", title="Paste Image", tags=["image", "paste"], category="image", version="1.1.0") @invocation("img_paste", title="Paste Image", tags=["image", "paste"], category="image", version="1.1.0")
class ImagePasteInvocation(BaseInvocation, WithWorkflow, WithMetadata): class ImagePasteInvocation(BaseInvocation, WithWorkflow, WithMetadata):
"""Pastes an image into another image.""" """Pastes an image into another image."""

File diff suppressed because one or more lines are too long