forked from nftblackmagic/IDM-VTON-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
49 lines (38 loc) · 1.51 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from PIL import Image
import torch
def combine_images_horizontally(images):
"""
Combine a list of PIL.Image objects into a single image horizontally.
:param images: List of PIL.Image objects
:return: A single PIL.Image object
"""
# Calculate total width and maximum height
total_width = sum(image.width for image in images)
max_height = max(image.height for image in images)
# Create a new blank image with the calculated dimensions
combined_image = Image.new("RGB", (total_width, max_height))
# Paste each image into the new image
x_offset = 0
for image in images:
combined_image.paste(image, (x_offset, 0))
x_offset += image.width
return combined_image
def combine_images_vertically(images):
"""
Combine a list of PIL.Image objects into a single image vertically.
:param images: List of PIL.Image objects
:return: A single PIL.Image object
"""
# Calculate total height and maximum width
total_height = sum(image.height for image in images)
max_width = max(image.width for image in images)
# Create a new blank image with the calculated dimensions
combined_image = Image.new("RGB", (max_width, total_height))
# Paste each image into the new image
y_offset = 0
for image in images:
combined_image.paste(image, (0, y_offset))
y_offset += image.height
return combined_image
def is_in_range(tensor, min_value, max_value):
return torch.min(tensor) >= min_value and torch.max(tensor) <= max_value