原理:将所有像素点随机赋值比其大某个不大的值,如:0-8间的某个值
import cv2
import numpy as np
import random
img = cv2.imread('D:/pythonob/imageinpaint/img/zidan.jpg',1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
dst = np.zeros((height,width,3),np.uint8)
for i in range(0,height-8):
for j in range(0,width-8):
index = int(random.random()*8)#随机数0-8
(b,g,r) = img[i+index,j+index]
dst[i,j] = (b,g,r)
cv2.imshow('maoboli',dst)
cv2.waitKey(0)
效果图: