Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- import sys
- import argparse
- import numpy as np
- import matplotlib as plt
- from PIL import (
- Image,
- ImageDraw,
- )
- def get_window_locs(img_arr, hwcoef, scoef):
- """
- """
- x, y = 0, 0
- lis = []
- # (h, w) = img_arr.shape
- (h, w) = img_arr.size
- hws = min(h, w)/hwcoef
- s = hws/scoef
- while y+hws <= h:
- while x+hws <= w:
- if x == 0 and y == 0:
- window_locs = np.array([x, y, x+hws, y+hws])
- else:
- window_locs = np.vstack((window_locs, [x, y, x+hws, y+hws]))
- x += s
- x = 0
- y += s
- if window_locs.ndim == 1:
- window_locs = window_locs[np.newaxis,:]
- return window_locs
- def main(argv=sys.argv[1:]):
- parser = argparse.ArgumentParser()
- parser.add_argument('image')
- args = parser.parse_args(argv)
- im = Image.open(args.image)
- height, width = im.size
- img_size = 100
- os.makedirs('trash', exist_ok=True)
- for yy in range(0, height-img_size):
- for xx in range(0, width-img_size):
- box = (yy, xx, yy+img_size, xx+img_size)
- image = im.crop(box)
- image.save('trash/{}-{}-{}-{}.jpg'.format(box[0], box[1], box[2], box[3]))
- # img = ImageDraw.Draw(im)
- res = get_window_locs(im, 1, 1)
- print(args.image)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement