image loading for compositing fixed
This commit is contained in:
parent
76effe3617
commit
904b1c61b6
@ -1,5 +1,5 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from .constants import image_name
|
from .constants import image_name, image_width, image_height
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from .libs.PIL import Image
|
from .libs.PIL import Image
|
||||||
import mathutils
|
import mathutils
|
||||||
@ -21,9 +21,12 @@ def apply_color():
|
|||||||
if normal_buffer and normal_color != mathutils.Vector((1.0, 1.0, 1.0)):
|
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]:
|
if paint_buffer.size[0] == normal_buffer.size[0] and paint_buffer.size[1] == normal_buffer.size[1]:
|
||||||
# create arrays
|
# create arrays
|
||||||
paint_mask_pixels = np.array(paint_buffer.pixels[:], dtype=np.float32).reshape(-1, 4)[:, 0]
|
# 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)
|
# 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))
|
# 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 lengths: ", len(paint_mask_pixels), len(target_pixels), len(new_pixels))
|
||||||
print("image shapes: ", paint_mask_pixels.shape, target_pixels.shape, new_pixels.shape)
|
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
|
# 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[:, 3], mode='F') # Use alpha channel for mask
|
||||||
paint_mask_image = Image.fromarray(paint_mask_pixels, 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')
|
# target_image = Image.fromarray(target_pixels, mode='RGBA')
|
||||||
new_image = Image.fromarray(new_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()
|
paint_mask_image.show()
|
||||||
target_image.show()
|
target_image.show()
|
||||||
|
Loading…
Reference in New Issue
Block a user