mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Add image multiplication.
This commit is contained in:
parent
3573d39860
commit
bead83a8bc
@ -12,7 +12,7 @@
|
|||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"import cv2\n",
|
"import cv2\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from invokeai.backend.vto_workflow.overlay_pattern import generate_dress_mask\n",
|
"from invokeai.backend.vto_workflow.overlay_pattern import generate_dress_mask, multiply_images\n",
|
||||||
"from invokeai.backend.vto_workflow.extract_channel import extract_channel, ImageChannel\n",
|
"from invokeai.backend.vto_workflow.extract_channel import extract_channel, ImageChannel\n",
|
||||||
"from invokeai.backend.vto_workflow.seamless_mapping import map_seamless_tiles\n",
|
"from invokeai.backend.vto_workflow.seamless_mapping import map_seamless_tiles\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -87,19 +87,8 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"expanded_pattern = map_seamless_tiles(seamless_tile=pattern_image, target_hw=(model_image.height, model_image.width), num_repeats_h=5.0)\n",
|
"# Tile the pattern.\n",
|
||||||
"expanded_pattern"
|
"expanded_pattern = map_seamless_tiles(seamless_tile=pattern_image, target_hw=(model_image.height, model_image.width), num_repeats_h=10.0)\n"
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "2a12c166",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"expanded_pattern = map_seamless_tiles(seamless_tile=pattern_image, target_hw=(model_image.height, model_image.width), num_repeats_h=1.0)\n",
|
|
||||||
"expanded_pattern"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -108,6 +97,40 @@
|
|||||||
"id": "f4f22d02",
|
"id": "f4f22d02",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Multiply the pattern by the shadows.\n",
|
||||||
|
"pattern_with_shadows = multiply_images(expanded_pattern, shadows)\n",
|
||||||
|
"pattern_with_shadows"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "97db42b0",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "de32f7e3",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Merge the pattern with the model image.\n",
|
||||||
|
"pattern_with_shadows_np = np.array(pattern_with_shadows)\n",
|
||||||
|
"merged_image = np.where(mask[:, :, None], pattern_with_shadows_np,model_image_np)\n",
|
||||||
|
"merged_image = Image.fromarray(merged_image)\n",
|
||||||
|
"merged_image"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "ff1d4044",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
"source": []
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -29,6 +29,30 @@ def generate_dress_mask(model_image):
|
|||||||
return binary_mask
|
return binary_mask
|
||||||
|
|
||||||
|
|
||||||
|
def multiply_images(image_1: Image.Image, image_2: Image.Image) -> Image.Image:
|
||||||
|
"""Multiply two images together.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
image_1 (Image.Image): The first image.
|
||||||
|
image_2 (Image.Image): The second image.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Image.Image: The product of the two images.
|
||||||
|
"""
|
||||||
|
image_1_np = np.array(image_1, dtype=np.float32)
|
||||||
|
if image_1_np.ndim == 2:
|
||||||
|
# If the image is greyscale, add a channel dimension.
|
||||||
|
image_1_np = np.expand_dims(image_1_np, axis=-1)
|
||||||
|
image_2_np = np.array(image_2, dtype=np.float32)
|
||||||
|
if image_2_np.ndim == 2:
|
||||||
|
# If the image is greyscale, add a channel dimension.
|
||||||
|
image_2_np = np.expand_dims(image_2_np, axis=-1)
|
||||||
|
product_np = image_1_np * image_2_np // 255
|
||||||
|
product_np = np.clip(product_np, 0, 255).astype(np.uint8)
|
||||||
|
product = Image.fromarray(product_np)
|
||||||
|
return product
|
||||||
|
|
||||||
|
|
||||||
@torch.inference_mode()
|
@torch.inference_mode()
|
||||||
def main():
|
def main():
|
||||||
# Load the model image.
|
# Load the model image.
|
||||||
|
Loading…
Reference in New Issue
Block a user