Created
May 21, 2021 10:02
-
-
Save Pangoraw/0ed1e799841582ff148be4f61348ef58 to your computer and use it in GitHub Desktop.
Image concat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
import argparse | |
from PIL import Image | |
from torchvision import utils, transforms | |
def parse_args(): | |
parser = argparse.ArgumentParser("Image concat") | |
parser.add_argument("inputs", metavar="input", nargs="+") | |
parser.add_argument("output") | |
parser.add_argument("--resize", type=str) | |
return parser.parse_args() | |
def main(args): | |
inputs = args.inputs | |
output = args.output | |
size = args.resize | |
if size is not None: | |
to_tensor = transforms.Compose([ | |
transforms.ToTensor(), | |
transforms.Resize(tuple(map(int, size.split("x")))), | |
]) | |
else: | |
to_tensor = transforms.ToTensor() | |
img_tensors = [] | |
for input_file in inputs: | |
img = Image.open(input_file) | |
img = to_tensor(img) | |
img_tensors.append(img) | |
utils.save_image(img_tensors, output, ncol=1) | |
if __name__ == "__main__": | |
args = parse_args() | |
main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
Result:

Image from the MVTec-AD dataset