【发布时间】:2020-06-24 05:19:46
【问题描述】:
如何以不均匀的饱和度渲染文本,就像第二张图片一样? (两张图片的字体不同,但饱和度值得关注。)
我的初始代码是
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from random import seed
from random import randint
import numpy as np
import os.path
#Returns the text size in terms of width and height.
def getSize(txt, font):
testImg = Image.new('RGB', (1, 1))
testDraw = ImageDraw.Draw(testImg)
return testDraw.textsize(txt, font)
text = 'lemper'
fontname = 'arial.ttf'
fontsize= 25
font = ImageFont.truetype(fontname, fontsize)
width, height = getSize(text, font)
#Creates an image with white background of constant size.
img = Image.new('RGB', (100, 100), 'white')
d = ImageDraw.Draw( img)
d.text(get_xy_coordinates(text, font), text, fill='black', font=font)
img.save("text_images/1.png")
【问题讨论】:
-
你想改变饱和度还是连同字体和其他,因为两个图像不匹配?
-
@NagaKiran 两张图片的字体不同,但饱和度值得关注。
-
饱和度是颜色的鲜艳度,黑色(以及白色和灰色阴影)根据定义是完全不饱和的,即没有饱和度。所以我认为这可能是错误的词。您可以用深灰色而不是黑色打印文本。您可以打印部分不透明的文本,这样一些不均匀的背景就会显示出来。
-
如果您需要定制 OCR 引擎,请联系我
标签: python image image-processing noise distortion