Skip to content

Instantly share code, notes, and snippets.

@ashnair1
Last active May 8, 2019 08:49
Show Gist options
  • Save ashnair1/aedddb5d612e23bfac9efc4b330e295a to your computer and use it in GitHub Desktop.
Save ashnair1/aedddb5d612e23bfac9efc4b330e295a to your computer and use it in GitHub Desktop.
Script to slice image into a set number of tiles
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