一:white_value=100 & black_value=10 & smoothness=50
import cv2
import numpy as np
dir_path='/Users/xxxx/Desktop/Share Folder/png&dat/new_img.png'
data=cv2.imread(dir_path)
def controlFuncBW(x):
return (float(x)/100)**2
def SetContrast(black,white):
contrast = 1/float(white-black) if white-black>0.01 else 100
return contrast
def SetBrightness(black,white):
brightness = float(black)
return brightness
def SetSmoothness(val):
smoothness=float(val)/100
return smoothness
white_value=100
black_value=10
white=controlFuncBW(white_value)
black=controlFuncBW(black_value)
contrast=SetContrast(black,white)
brightness=SetBrightness(black,white)
smoothness=SetSmoothness(50)
x=np.clip((255*contrast*(data-brightness)),0,255).astype(np.uint8)
GaussianBlur=cv2.GaussianBlur(new_image,(3,3),smoothness)
medianBlur=cv2.medianBlur(new_image,3)
cv2.imshow('GaussianBlur',GaussianBlur)
cv2.imshow('medianBlur',medianBlur)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)
原图:
GaussianBlur:
medianBlur:
二:white_value=10 & black_value=100 & smoothness=50
white_value=10
black_value=100
white=controlFuncBW(white_value)
black=controlFuncBW(black_value)
contrast=SetContrast(black,white)
brightness=SetBrightness(black,white)
smoothness=SetSmoothness(50)
x=np.clip((255*contrast*(data-brightness)),0,255).astype(np.uint8)
GaussianBlur=cv2.GaussianBlur(new_image,(3,3),smoothness)
medianBlur=cv2.medianBlur(new_image,3)
cv2.imshow('GaussianBlur',GaussianBlur)
cv2.imshow('medianBlur',medianBlur)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)
GaussianBlur:
medianBlur: