From 904b1c61b6fa48ddc9649c15ac50bf17f9aaf75e Mon Sep 17 00:00:00 2001 From: x-o-i-o-x <103693092+x-o-i-o-x@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:16:25 +0200 Subject: [PATCH] image loading for compositing fixed --- paintModifier.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/paintModifier.py b/paintModifier.py index 115957a..d6cf871 100644 --- a/paintModifier.py +++ b/paintModifier.py @@ -1,5 +1,5 @@ import bpy -from .constants import image_name +from .constants import image_name, image_width, image_height import numpy as np from .libs.PIL import Image import mathutils @@ -21,9 +21,12 @@ def apply_color(): if normal_buffer and normal_color != mathutils.Vector((1.0, 1.0, 1.0)): if paint_buffer.size[0] == normal_buffer.size[0] and paint_buffer.size[1] == normal_buffer.size[1]: # create arrays - paint_mask_pixels = np.array(paint_buffer.pixels[:], dtype=np.float32).reshape(-1, 4)[:, 0] - target_pixels = np.array(normal_buffer.pixels[:], dtype=np.float32).reshape(-1, 4) - new_pixels = np.tile(np.array([*normal_color, 1.0], dtype=np.float32), (paint_buffer.size[0] * paint_buffer.size[1], 1)) + # paint_mask_pixels = np.array(paint_buffer.pixels[:], dtype=np.float32).reshape(-1, 4)[:, 0] + # target_pixels = np.array(normal_buffer.pixels[:], dtype=np.float32).reshape(-1, 4) + # new_pixels = np.tile(np.array([*normal_color, 1.0], dtype=np.float32), (paint_buffer.size[0] * paint_buffer.size[1], 1)) + paint_mask_pixels = (np.array(paint_buffer.pixels[:], dtype=np.float32) * 255).astype(np.uint8) + target_pixels = (np.array(normal_buffer.pixels[:], dtype=np.float32) * 255).astype(np.uint8) + new_pixels = np.tile((np.array([*normal_color, 1.0], dtype=np.float32) * 255), (image_width * image_height, 1)).astype(np.uint8) print("image lengths: ", len(paint_mask_pixels), len(target_pixels), len(new_pixels)) print("image shapes: ", paint_mask_pixels.shape, target_pixels.shape, new_pixels.shape) @@ -31,9 +34,17 @@ def apply_color(): # Convert arrays to PIL Images # paint_mask_image = Image.fromarray(paint_mask_pixels[:, 3], mode='F') # Use alpha channel for mask - paint_mask_image = Image.fromarray(paint_mask_pixels, mode='F') # Use alpha channel for mask - target_image = Image.fromarray(target_pixels, mode='RGBA') - new_image = Image.fromarray(new_pixels, mode='RGBA') + # paint_mask_image = Image.fromarray(paint_mask_pixels, mode='F') # Use alpha channel for mask + # target_image = Image.fromarray(target_pixels, mode='RGBA') + # new_image = Image.fromarray(new_pixels, mode='RGBA') + paint_mask_image = Image.frombuffer('RGBA', (image_width, image_height), paint_mask_pixels, 'raw', 'RGBA', 0, 1) + target_image = Image.frombuffer('RGBA', (image_width, image_height), target_pixels, 'raw', 'RGBA', 0, 1) + new_image = Image.frombuffer('RGBA', (image_width, image_height), new_pixels, 'raw', 'RGBA', 0, 1) + r_mask, g_mask, b_mask, a_mask = paint_mask_image.split() # separates the channels + paint_mask_image = Image.merge("RGBA", (r_mask, g_mask, b_mask, r_mask)) # replace alpha with red + + print("PIL image sizes: ", paint_mask_image.size, target_image.size, new_image.size) + print("PIL image modes: ", paint_mask_image.mode, target_image.mode, new_image.mode) paint_mask_image.show() target_image.show()