Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在饱和度不均匀的图像中渲染文本_Python_Image_Image Processing_Noise_Distortion - Fatal编程技术网

Python 在饱和度不均匀的图像中渲染文本

Python 在饱和度不均匀的图像中渲染文本,python,image,image-processing,noise,distortion,Python,Image,Image Processing,Noise,Distortion,如何渲染饱和度不均匀的文本,就像第二幅图像一样?(两幅图像的字体不同,但饱和度值得关注。) 我的初始代码是 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 o

如何渲染饱和度不均匀的文本,就像第二幅图像一样?(两幅图像的字体不同,但饱和度值得关注。)

我的初始代码是

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")

我希望饱和度不会带来任何变化,因为它是一个二值图像,我想你们正在寻找增加一些噪音的图像

请查看库,根据您的需要添加或删除相关的图像处理技术

import numpy as np
import cv2
import imgaug.augmenters as iaa


a = cv2.imread('fontimage.jpg')[None,:,:,:]
# Standard scenario: You have N RGB-images and additionally 21 heatmaps per

images = a.copy()
heatmaps = np.random.random(size=(1, 64, 64, 1)).astype(np.float32)

seq = iaa.Sequential([
    # Comment or uncomment the filters on your preference
    #iaa.GaussianBlur((0,3.0)),
    iaa.MultiplyHueAndSaturation((0.5, 1.5), per_channel=True),
    iaa.MultiplySaturation((0.1, 0.4)),
    iaa.SaltAndPepper(0.2)
])

images_aug, heatmaps_aug = seq(images=images, heatmaps=heatmaps)
输出:


由于两幅图像不匹配,您是想更改饱和度还是与字体和其他一起更改?@Nagakiran两幅图像的字体不同,但饱和度水平值得关注。饱和度是指颜色的生动性,黑色(以及白色和灰色)根据定义是完全不饱和的,即没有饱和度。所以我认为这可能是个错误的词。你可以用深灰色而不是黑色打印文本。你可以用部分不透明度打印文本,这样一些不均匀的背景就会显示出来。如果你需要定制的OCR引擎,请联系我