图像增强

CV的图像处理

Posted by WEW on July 23, 2019

感谢基于图像处理,启发修改。

局部模糊

import cv2
import random
import pdb

def flower_screen(img, rect):
    outimg= img.copy()
    for i in range(0,rect[3],20):
        for j in range(0,rect[2],20):
            ran = random.random()
            if ran <=0.5 and i>15 and j>15:
                hash=outimg[i,j]#记录中心值
                width = random.randint(0,15)
                height = random.randint(0,15)

                for x in range(i-height,i+height):
                    for y in range(j-width,j+width):
                        outimg[x,y]= hash

    return outimg

img = cv2.imread('11.png')
height, width, _ =img.shape
rect = [0,0,width-10,height-20]
outimg = flower_screen(img,rect)
cv2.imwrite('12.png',outimg)