Created
November 14, 2019 09:48
-
-
Save ninjakx/10b0d31daa302cfa1826620c67f85808 to your computer and use it in GitHub Desktop.
splitting image and merge them
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 numpy as np | |
import matplotlib.pyplot as plt | |
# https://stackoverflow.com/a/55176783/6660373 | |
# 20x20 image | |
img = im#np.random.randint(0,9,(512,512)) | |
# List of 4 5x20 image slices | |
sliced = np.split(img,4,axis=0) | |
# List of 4 lists of 4 5x5 image blocks | |
blocks = [np.split(img_slice,4,axis=1) for img_slice in sliced] | |
# stacking them back together | |
img_stacked = np.block(blocks) | |
# testing if the stacking works right | |
# print((img==img_stacked).all()) | |
image = im | |
# tiles = get_tile_images(image, 128, 128) | |
tiles = blocks | |
_nrows = int(image.shape[0] / 128) | |
_ncols = int(image.shape[1] / 128) | |
fig, ax = plt.subplots(nrows=_nrows, ncols=_ncols) | |
# # count = 0 | |
for i in range(_nrows): | |
for j in range(_ncols): | |
ax[i, j].imshow(blocks[i][j]) | |
ax[i, j].set_axis_off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment