1

我有文档的彩色图像。样本输入

PAN卡 (取自https://www.indiamart.com/proddetail/pan-card-21687536812.html

我希望由此创建逼真的施乐/影印图像。大多数施乐/复印都设置为低调。这是一个示例输出(示例输出不是示例输入的施乐 - 我在网上找不到相同的图像) 在此处输入图像描述(取自http://shrikantmail7862.blogspot.com/2016/06/

注意输出不是彩色图像的简单黑白。

我正在寻找可以为我执行此操作的工具/代码/算法。我需要为超过 0.1M 的图像执行此操作,我确信在图像处理中必须有这样的过滤器。寻找合适的指针

4

2 回答 2

2

要创建类似施乐的效果,一种方法是将图像转换为灰度,然后减少色彩空间。

def xeroxFilter(imgPath, colorSpaceReduction=8, rotate=False, fillColor=(255,255,255)):
  '''Takes image as input and returns a xerox like image of the input image.
  impPath: Name of Image(keep the images in the same folder as this script)
  colorSpaceReduction:  Reducing the color space. Higher the value, Higher the reduction. 
  rotate: Rotate to the image
  fillColor: Specify the RGB value of the background color after roatation
  '''
  print("Original Image")
  cv2_imshow(cv2.imread(imgPath))

  print('GreyScale')
  cv2_imshow(cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE))
  
  print('Color Space Reduced')
  color_reduced_img = cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE) // colorSpaceReduction * colorSpaceReduction + colorSpaceReduction // 2
  cv2_imshow(color_reduced_img)
  file_name = 'ColorSpaceReduced-'+imgPath.split('.')[0]+'.png'
  cv2.imwrite(file_name, color_reduced_img)
  
  if rotate:
    print("Rotated")
    img = Image.open(file_name)
    rgb_img = Image.new("RGBA", img.size)
    rgb_img.paste(img)
    rotated_img = rgb_img.rotate(random.randint(-25,25), expand = 1, fillcolor = fillColor)
    display(rotated_img)
    rotated_img.save('Rotated-'+file_name)
  print("Original Image")
  cv2_imshow(cv2.imread(imgPath))

xeroxFilter('MCRV7.jpg', rotate=True)

色彩空间缩减代码 (credits @elizer )
将第一张图像传入脚本时的输出如下所示:
[ 施乐过滤器输出图像1

于 2020-09-03T08:56:31.157 回答
0

'''将图像作为输出并返回输出图像的原始图像。impPath:图像的名称(将图像保存在与此脚本相同的文件夹中) colorSpaceReduction:减少色彩空间。值越高,减少量越大。rotate:旋转到图像 fillColor:指定旋转后背景色的RGB值

print("Original Image")
cv2_imshow(cv2.imread(imgPath))

print('GreyScale')
cv2_imshow(cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE))
  
print('Color Space Reduced')
于 2021-03-18T18:06:45.120 回答