p = pixelBlocks["raster_pixels"]
if self.measure is None:
b = resize(p, shape, order=0, preserve_range=True)
else:
blockSizes = tuple(np.divide(p.shape, shape))
b = measure.block_reduce(p, blockSizes, self.measure)
After Change
def updatePixels(self, tlc, shape, props, **pixelBlocks):
if self.func is None:
b = resize(pixelBlocks["raster_pixels"], shape, order=0, preserve_range=True)
m = resize(pixelBlocks["raster_mask"], shape, order=0, preserve_range=True)
else:
p = pixelBlocks["raster_pixels"]
blockSizes = tuple(np.divide(p.shape, shape))
q = np.ma.masked_array(view_as_blocks(p, blockSizes),
view_as_blocks(~pixelBlocks["raster_mask"].astype("b1"), blockSizes))
for i in range(len(q.shape) // 2):
q = self.func(q, axis=-1)
b = q.data
m = ~q.mask
pixelBlocks["output_pixels"] = b.astype(props["pixelType"], copy=False)
pixelBlocks["output_mask"] = m.astype("u1", copy=False)
return pixelBlocks