![](/img/trans.png)
[英]Pygame: How do I get rid of the black halo that is showing up on my planet images?
[英]How to get rid of black noise on text images?
我正在使用此代码来伽玛校正图像,当我得到足够暗的文本时(我的背景都是白色),如何获得伽玛校正图像随附的黑色噪声?
伽玛校正代码:
import cv2
import numpy as np
def adjust_gamma(image, gamma=1.0):
invGamma = 1.0 / gamma
table = np.array([((i / 255.0) ** invGamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
return cv2.LUT(image, table)
x = 'page-1.png' #location of the image
original = cv2.imread(x, 1)
#cv2.imshow('original', original)
print("Choose a value between 0-1 for gamma correction:")
print("[Choose 0.0 to exit]")
def apply_gamma():
while True:
gamma = float(input("\nWhat value would you like the gamma correction to be? "))
if 1 > gamma > 0:
adjusted = adjust_gamma(original, gamma=gamma)
cv2.putText(adjusted, "g={}".format(gamma), (10, 30),cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
cv2.imshow('Original', original)
cv2.imshow("Gamma corrected image", adjusted)
cv2.waitKey(0)
cv2.destroyAllWindows()
print('\n[press "y" to continue. Press "n" to readjust"]')
while True:
gc = input('Are you satisfied with the image? ')
if gc == 'n':
apply_gamma()
if gc == 'y':
print('\nDenoise is next')
cv2.imwrite('text1_gc.png', adjusted)
break
else:
print('\nInvalid input')
gc = True
break
apply_gamma()
噪音:
您只需要使用threshold
值对图像进行二值化处理即可。 为此,您可以使用cv2.threshold
方法。 在此, threshold value = 85
。
使用此代码:
import cv2
img = cv2.imread('test.png', 0)
threshold = 85
cv2.threshold(img,threshold,255,cv2.THRESH_BINARY,img)
cv2.imshow('test',img)
cv2.waitKey(0)
OUTPUT:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.