In [1]:
import numpy as np
In [2]:
import skimage.io
import skimage.util
In [3]:
img = skimage.io.imread('data/src/lena_square.png')
print(img.shape)
In [4]:
blocks = skimage.util.view_as_blocks(img, (256, 256, 3))
print(blocks.shape)
In [5]:
# blocks = skimage.util.view_as_blocks(img, (256, 256))
# ValueError: 'block_shape' must have the same length as 'arr_in.shape'
In [6]:
print(blocks[0, 0, 0].shape)
In [7]:
skimage.io.imsave('data/dst/skimage_block_00.jpg', blocks[0, 0, 0])
skimage.io.imsave('data/dst/skimage_block_01.jpg', blocks[0, 1, 0])
skimage.io.imsave('data/dst/skimage_block_10.jpg', blocks[1, 0, 0])
skimage.io.imsave('data/dst/skimage_block_11.jpg', blocks[1, 1, 0])
In [8]:
print(np.shares_memory(img, blocks))
In [9]:
blocks[0, 0, 0] = 0
blocks[1, 1, 0] //= 2
In [10]:
skimage.io.imsave('data/dst/skimage_block_change.jpg', img)
In [11]:
blocks_s = skimage.util.view_as_blocks(img, (256, 256, 3)).squeeze()
print(blocks_s.shape)
In [12]:
print(blocks_s[0, 0].shape)