Last active
May 8, 2019 08:49
-
-
Save ashnair1/aedddb5d612e23bfac9efc4b330e295a to your computer and use it in GitHub Desktop.
Script to slice image into a set number of tiles
This file contains 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
import image_slicer | |
from PIL import Image | |
def parser(): | |
arg_parser = argparse.ArgumentParser('Image Slicer') | |
arg_parser.add_argument('--image', help='Image to be sliced') | |
arg_parser.add_argument('--num_tiles', help='Number of tiles') | |
arg_parser.add_argument('--save_tiles', help="Save tiles",action='store_true') | |
arg_parser.add_argument('--tiles_dir',help="Directory to store tiles",type=str) | |
return arg_parser.parse_args() | |
def main(): | |
args = parser() | |
Image.MAX_IMAGE_PIXELS = 1600 * 1600 * 10 * 10 | |
tiles = image_slicer.slice(args.image, args.num_tiles, save=False) | |
if args.save_tiles: | |
if os.path.isdir(args.tiles_dir) is False: | |
os.makedirs(args.tiles_dir) | |
print("Saving tiles into {}".format(args.tiles_dir)) | |
image_slicer.save_tiles(tiles,directory=args.tiles_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment