Created
October 4, 2019 04:02
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
#image分割 | |
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
from mpl_toolkits.axes_grid1 import ImageGrid | |
image = plt.imread('moonworld.jpg') | |
image.shape | |
#(800, 800, 3) | |
def image_div(image, div): | |
image_list = [] | |
image_size = image.shape[0] | |
im_size = int(image_size/div) | |
for i in range(div): | |
for l in range(div): | |
im = image[im_size*i:im_size*(i+1)+1,im_size*l:im_size*(l+1)+1] | |
image_list.append(im) | |
fig = plt.figure(figsize=(8, 8)) | |
grid = ImageGrid(fig, 111, | |
nrows_ncols=(div, div), | |
axes_pad=0.05, | |
share_all=True, | |
) | |
for i in range(len(image_list)): | |
grid[i].imshow(image_list[i]) | |
grid[i].set_axis_off() | |
image_div(image,2) | |
image_div(image,4) | |
image_div(image,8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment