【发布时间】:2021-05-23 14:08:29
【问题描述】:
使用此功能:
import numpy as np
def blockshaped(arr, nrows, ncols):
''' Return an array of shape (n, nrows, ncols) where
n * nrows * ncols = arr.size
If arr is a 2D array, the returned array should look like n subblocks with
each subblock preserving the "physical" layout of arr.
'''
h, w = arr.shape
assert h % nrows == 0, "{} rows is not evenly divisble by {}".format(h, nrows)
assert w % ncols == 0, "{} cols is not evenly divisble by {}".format(w, ncols)
return (arr.reshape(h//nrows, nrows, -1, ncols)
.swapaxes(1, 2)
.reshape(-1, nrows, ncols))
我能够将我的图像分成每块 16 像素的块。
我想要做的是计算每个块中黑色像素的密度。
我知道像素的值范围从 0 到 255。
我想做black_density = numberof_zeros / 16,但我不确定。
【问题讨论】: