import cv2 import numpy as np img = cv2.imread("F:\\mytupian\\xihuduanqiao.jpg") # 低反光 cv2.imshow('image', img) # ============================================================================= # 图像分块 # ============================================================================= dst = np.zeros(img.shape, img.dtype) ratio = 2 #图像边长缩小比率是2,也就是一张图片被分割成四份 height, width = img.shape[:2] pheight = int(height / ratio) pwidth = int(width / ratio) pHeightInterval = int(pheight) pWidthInterval = int(pwidth) cnt = 1 for i in range(ratio): for j in range(ratio): y = int(pHeightInterval * i) x = int(pWidthInterval * j) patch = img[y:y + pheight, x:x + pwidth] cv2.imshow('%d' % cnt + '.jpg', patch) cnt = cnt + 1 # patch=cv2.equalizeHist(patch) #直方图均衡 # ret,patch=cv2.threshold(patch,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) dst[y:y + pheight, x:x + pwidth] = patch cv2.imshow('final image', dst) cv2.waitKey(0) cv2.destroyAllWindows()