图像增加摩尔纹

在图像上添加摩尔纹,模仿手机拍摄LCD屏幕出现的摩尔纹,例如在下图添加摩尔纹
原图:
原图

  1. 模仿LCD屏幕显示的图像
    Resample the input RGB image into a mosaic of RGB subpixels (modeled as 9 pixels with [K, K, K; R, G, B; R, G, B], where K stands for black) to simulate the image displayed on the LCD. Note that this step causes the final moire image to be darker.
    在这里插入图片描述
  • 图像长宽会增大3倍
  • 图像会变暗
import numpy as np
def RGB2mosaicRGB(img, k=0):
    '''
    img: RGB, numpy
    k: int 0-255  The smaller, the darker
    return:
        mosaic:
    step1:
    Resample the input RGB image into a mosaic of RGB subpixels 
    (modeled as 9 pixels with [K, K, K; R, G, B; R, G, B], where 
    K stands for black) to simulate the image displayed on the LCD. 
    Note that this step causes the final moire image to be darker.
    '''
    h, w, c = img.shape
    scale = 3
    h_, w_ = int(h*scale), int(w*scale)
    mosaic = np.ones((h_, w_, c), np.uint8) * k
    for i in range(h):
        for j in range(w):
            mosaic[i*scale+1, j*scale, 0] = img[i, j, 0]
            mosaic[i*scale+1, j*scale+1, 1] = img[i, j, 1]
            mosaic[i*scale+1, j*scale+2, 2] = img[i, j, 2]
        mosaic[i*scale+2, :, :] = mosaic[i*scale+1, :, :]

    return mosaic
  1. 透视投影变换,模仿相机在不同角度、不同距离拍摄的图像
    在这里插入图片描述
def project_transform(img, r=0.2):
    '''
    img: mosaic image, RGB, numpy
    r: ratio
    step2:
    Apply a random projective transformation on the im- age to simulate different 
    relative positions and orienta- tions of the display and camera, and apply 3×3 
    Gaussian filter. To model the random projective transformation, four image corners 
    were randomly sampled (us- ing a uniform distribution) within a radius of 0.2 
    times of the image size
    '''
    h, w, c = img.shape
    src = np.array([[0, 0], [w, 0], [w, h], [0, h]]).astype(np.float32)
    dst = np.array([[np.random.randint(0, r*w), np.random.randint(0, r*h)], 
                    [np.random.randint(w-r*w, w), np.random.randint(0, r*h)], 
                    [np.random.randint(w-r*w, w), np.random.randint(h-r*h, h)], 
                    [np.random.randint(0, r*w), np.random.randint(h-r*h, h)]]).astype(np.float32)
    M = cv2.getPerspectiveTransform(src, dst)
    img = cv2.warpPerspective(img, M, (w, h)) 

    img = cv2.GaussianBlur(img, (3, 3), 0)

    return img
  1. Resample the image using Bayer CFA to simulate the RAW data, and add Gaussian noise to simulate sensor noise.
  2. Apply a simple ISP pipeline including demosaicing (bilinear interpolation) and denoising (standard de- noising function provided by OpenCV).
  3. Compress the image using JPEG compression to simu- late the compression noise, align the clean image with the moire image, and crop out the image pair.

3、4、5是为了模仿相机拍摄过程,拍摄、存储、压缩等带来的噪声,这里忽略

参考文献

Yuan S , Timofte R , Slabaugh G , et al. AIM 2019 Challenge on Image Demoireing: Dataset and Study[J]. 2019.
Liu B , Shu X , Wu X . Demoir’eing of Camera-Captured Screen Images Using Deep Convolutional Neural Network[J]. 2018.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值