diff --git a/core/compose.py b/core/compose.py index 3d516f3..89a6588 100644 --- a/core/compose.py +++ b/core/compose.py @@ -40,7 +40,7 @@ from Jovimetrix.sup.image.channel import EnumPixelSwizzle, channel_merge, \ channel_solid from Jovimetrix.sup.image.compose import EnumAdjustOP, EnumBlendType, \ - EnumOrientation, image_levels, image_split, image_stack, image_blend, \ + EnumOrientation, image_by_size, image_levels, image_split, image_stack, image_blend, \ image_crop, image_crop_center, image_crop_polygonal from Jovimetrix.sup.image.mapping import EnumProjection, remap_fisheye, \ @@ -262,17 +262,32 @@ Combine two input images using various blending modes, such as normal, screen, m if flip: pA, pB = pB, pA + width, height = MIN_IMAGE_SIZE, MIN_IMAGE_SIZE if pA is None: - pA = channel_solid(MIN_IMAGE_SIZE, MIN_IMAGE_SIZE, matte, chan=EnumImageType.BGRA) + if pB is None: + if mask is None: + images.append(img) + pbar.update_absolute(idx) + continue + else: + height, width = mask.shape[:2] + else: + height, width = pB.shape[:2] + else: + height, width = pA.shape[:2] + + if pA is None: + pA = channel_solid(width, height, matte, chan=EnumImageType.BGRA) else: pA = tensor2cv(pA) matted = pixel_eval(matte, EnumImageType.BGRA) pA = image_matte(pA, matted) if pB is None: - pB = channel_solid(MIN_IMAGE_SIZE, MIN_IMAGE_SIZE, matte, chan=EnumImageType.BGRA) + pB = channel_solid(width, height, matte, chan=EnumImageType.BGRA) else: pB = tensor2cv(pB) + print(pB.shape) if mask is not None: mask = tensor2cv(mask) @@ -283,7 +298,9 @@ Combine two input images using various blending modes, such as normal, screen, m img = image_blend(pA, pB, mask, func, alpha) if mode != EnumScaleMode.MATTE: - img = image_scalefit(img, *wihi, mode, sample) + # or mode != EnumScaleMode.RESIZE_MATTE: + width, height = wihi + img = image_scalefit(img, width, height, mode, sample) img = cv2tensor_full(img, matte) images.append(img) diff --git a/core/create.py b/core/create.py index 8a08374..400864f 100644 --- a/core/create.py +++ b/core/create.py @@ -137,16 +137,10 @@ Create n-sided polygons. These shapes can be customized by adjusting parameters back = matte[:3] match shape: - case EnumShapes.RECTANGLE: + case EnumShapes.RECTANGLE | EnumShapes.SQUARE: pA = shape_quad(width, height, sizeX, sizeY, fill, back) - case EnumShapes.SQUARE: - pA = shape_quad(width, height, sizeX, sizeX, fill, back) - - case EnumShapes.ELLIPSE: - pA = shape_ellipse(width, height, sizeX, sizeY, fill, back) - - case EnumShapes.CIRCLE: + case EnumShapes.ELLIPSE | EnumShapes.CIRCLE: pA = shape_ellipse(width, height, sizeX, sizeY, fill, back) case EnumShapes.POLYGON: diff --git a/sup/image/adjust.py b/sup/image/adjust.py index 118652b..b67ea29 100644 --- a/sup/image/adjust.py +++ b/sup/image/adjust.py @@ -60,6 +60,7 @@ class EnumScaleMode(Enum): FIT = 10 ASPECT = 30 ASPECT_SHORT = 35 + RESIZE_MATTE = 40 class EnumThreshold(Enum): BINARY = cv2.THRESH_BINARY @@ -167,7 +168,7 @@ def image_flatten(image: List[TYPE_IMAGE], width:int=None, height:int=None, current = np.zeros((height, width, 4), dtype=np.uint8) for x in image: - if mode != EnumScaleMode.MATTE: + if mode != EnumScaleMode.MATTE and mode != EnumScaleMode.RESIZE_MATTE: x = image_scalefit(x, width, height, mode, sample) x = image_matte(x, (0,0,0,0), width, height) x = image_scalefit(x, width, height, EnumScaleMode.CROP, sample) @@ -363,7 +364,7 @@ def image_scalefit(image: TYPE_IMAGE, width: int, height:int, matte:TYPE_PIXEL=(0,0,0,0)) -> TYPE_IMAGE: match mode: - case EnumScaleMode.MATTE: + case EnumScaleMode.MATTE | EnumScaleMode.RESIZE_MATTE: image = image_matte(image, matte, width, height) case EnumScaleMode.ASPECT: