什么是opencv中matlab blockprop的等价物

时间:2015-02-02 10:21:35

标签: matlab opencv

opencv中的blockproc相当于什么?

http://www.mathworks.com/help/images/ref/blockproc.html?refresh=true

我想在3X3的块中打破图像并在每个块上应用平均值。

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

使用python绑定时,我们可以执行以下操作

import cv2 
import numpy as np



mat = cv2.imread('x.jpg')

rows, cols, x = mat.shape 
rows, cols = 3*(rows/3),  3*(cols/3) 
reshaped = mat[:rows,:cols].reshape(rows//3, 3, cols//3, 3,3) 
mat1 = reshaped.sum(axis=(1, 3)) / 9

cv2.imwrite('y.jpg', mat1.astype(np.uint8))