积分图像的构建

实现前后图对比:

实现代码:

import cv2
import numpy as np

img = cv2.imread('./4.jpg', 0)

h, w = img.shape

s = 0
#积分图
ii = np.zeros((h, w))

for i in range(h):
    for j in range(w):
        s += img[i, j]
        ii[i, j] = int(s) if i==0 else int(s+ii[i-1, j])
    s = 0
ii = 255 * ii/ii[h-1, w-1]

cv2.imshow('picture', ii)
cv2.imwrite('6.jpg', ii)
cv2.waitKey()
cv2.destroyAllWindows()

 

posted @ 2019-06-18 22:00  车路历程  阅读(243)  评论(0编辑  收藏  举报