Spaces:
Runtime error
Runtime error
Update create_print_layover.py
Browse files- create_print_layover.py +28 -0
create_print_layover.py
CHANGED
@@ -79,6 +79,33 @@ def create_hard_light_layover(img_in, img_layer, opacity, disable_type_checks: b
|
|
79 |
img_out = np.nan_to_num(np.dstack((img_out, img_in_norm[:, :, 3]))) # add alpha channel and replace nans
|
80 |
return img_out * 255.0
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
def stitch_images(image1, image2, overlap_width):
|
83 |
"""Stitch two images side by side with overlapping edges."""
|
84 |
height = min(image1.shape[0], image2.shape[0])
|
@@ -177,3 +204,4 @@ def control_texture(texture_image, direction, overlap, width, height):
|
|
177 |
img2, overlap, direction)
|
178 |
os.remove('tiled_image.png')
|
179 |
cv2.imwrite('tiled_image_2.png', control_tile_image)
|
|
|
|
79 |
img_out = np.nan_to_num(np.dstack((img_out, img_in_norm[:, :, 3]))) # add alpha channel and replace nans
|
80 |
return img_out * 255.0
|
81 |
|
82 |
+
def create_soft_light_layover(img_in, img_layer, opacity, disable_type_checks: bool = False):
|
83 |
+
if not disable_type_checks:
|
84 |
+
_fcn_name = 'soft_light'
|
85 |
+
assert_image_format(img_in, _fcn_name, 'img_in')
|
86 |
+
assert_image_format(img_layer, _fcn_name, 'img_layer')
|
87 |
+
assert_opacity(opacity, _fcn_name)
|
88 |
+
|
89 |
+
img_in_norm = img_in / 255.0
|
90 |
+
img_layer_norm = img_layer / 255.0
|
91 |
+
|
92 |
+
ratio = _compose_alpha(img_in_norm, img_layer_norm, opacity)
|
93 |
+
|
94 |
+
# The following code does this:
|
95 |
+
# multiply = img_in_norm[:, :, :3]*img_layer[:, :, :3]
|
96 |
+
# screen = 1.0 - (1.0-img_in_norm[:, :, :3])*(1.0-img_layer[:, :, :3])
|
97 |
+
# comp = (1.0 - img_in_norm[:, :, :3]) * multiply + img_in_norm[:, :, :3] * screen
|
98 |
+
# ratio_rs = np.reshape(np.repeat(ratio,3),comp.shape)
|
99 |
+
# img_out = comp*ratio_rs + img_in_norm[:, :, :3] * (1.0-ratio_rs)
|
100 |
+
|
101 |
+
comp = (1.0 - img_in_norm[:, :, :3]) * img_in_norm[:, :, :3] * img_layer_norm[:, :, :3] \
|
102 |
+
+ img_in_norm[:, :, :3] * (1.0 - (1.0 - img_in_norm[:, :, :3]) * (1.0 - img_layer_norm[:, :, :3]))
|
103 |
+
|
104 |
+
ratio_rs = np.reshape(np.repeat(ratio, 3), [comp.shape[0], comp.shape[1], comp.shape[2]])
|
105 |
+
img_out = comp * ratio_rs + img_in_norm[:, :, :3] * (1.0 - ratio_rs)
|
106 |
+
img_out = np.nan_to_num(np.dstack((img_out, img_in_norm[:, :, 3]))) # add alpha channel and replace nans
|
107 |
+
return img_out * 255.0
|
108 |
+
|
109 |
def stitch_images(image1, image2, overlap_width):
|
110 |
"""Stitch two images side by side with overlapping edges."""
|
111 |
height = min(image1.shape[0], image2.shape[0])
|
|
|
204 |
img2, overlap, direction)
|
205 |
os.remove('tiled_image.png')
|
206 |
cv2.imwrite('tiled_image_2.png', control_tile_image)
|
207 |
+
|