Skip to content

Commit fcf39a7

Browse files
committed
make load_and_preprocess available to grayscale image
1 parent c4b5da2 commit fcf39a7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

vggt/utils/load_fn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from torchvision import transforms as TF
1010

1111

12-
def load_and_preprocess_images(image_path_list, mode="crop"):
12+
def load_and_preprocess_images(image_path_list, mode="crop", grayscale=False):
1313
"""
1414
A quick start function to load and preprocess images for model input.
1515
This assumes the images should have the same shape for easier batching, but our model can also work well with different shapes.
@@ -56,14 +56,14 @@ def load_and_preprocess_images(image_path_list, mode="crop"):
5656
img = Image.open(image_path)
5757

5858
# If there's an alpha channel, blend onto white background:
59-
if img.mode == "RGBA":
59+
if not grayscale and img.mode == "RGBA":
6060
# Create white background
6161
background = Image.new("RGBA", img.size, (255, 255, 255, 255))
6262
# Alpha composite onto the white background
6363
img = Image.alpha_composite(background, img)
6464

6565
# Now convert to "RGB" (this step assigns white for transparent areas)
66-
img = img.convert("RGB")
66+
img = img.convert("L" if grayscale else "RGB")
6767

6868
width, height = img.size
6969

0 commit comments

Comments
 (0)