Created
January 11, 2017 01:51
-
-
Save sters/73a52f1a75b85f3958e293633ba31acf to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
# In[14]: | |
get_ipython().magic(u'matplotlib inline') | |
from PIL import Image | |
import os | |
import sys | |
from matplotlib import pyplot as plt | |
# In[20]: | |
def splitter(im): | |
width, height = im.size | |
for x in range(0, width / 32): | |
for y in range(0, width / 32): | |
x1 = x * 32 | |
y1 = y * 32 | |
x2 = x1 + 32 | |
y2 = y1 + 32 | |
if x2 > width or y2 > height: | |
next | |
cropped = im.crop((int(x1), int(y1), int(x2), int(y2))) | |
yield cropped | |
# In[24]: | |
files = ( | |
'1_before.jpg', '1_after.jpg', | |
'2_before.jpg', '2_after.jpg', | |
'3_before.jpg', '3_after.jpg', | |
) | |
for file in files: | |
im = Image.open(file) | |
name = file.replace('.jpg', '') | |
num = 1 | |
for cropped in splitter(im): | |
cropped.save('images/' + file + "_%d.jpg"%num, "JPEG") | |
num += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment