Reputation: 628
I am wondering is it possible to divide image into blocks for example 8x8 blocks (64 pixels per block
) and perform histogram function for each block and save results into a new image not to separately images?
def apply_histogram(block):
h, b = np.histogram(block.flatten(), 256, normed=True)
cdf = h.cumsum()
cdf = 255 * cdf / cdf[-1]
return np.interp(block.flatten(), b[:-1], cdf).reshape(block.shape)
Upvotes: 1
Views: 4158
Reputation: 23032
Why not loop through all 8x8
blocks in the image?
image = ...
block_img = np.zeros(image.shape)
im_h, im_w = image.shape[:2]
bl_h, bl_w = 8, 8
for row in np.arange(im_h - bl_h + 1, step=bl_h):
for col in np.arange(im_w - bl_w + 1, step=bl_w):
block_img[row:row+bl_h, col:col+bl_w] = apply_histogram(image[row:row+bl_h, col:col+bl_w])
image
:
block_img
:
Upvotes: 7