在图像上添加摩尔纹,模仿手机拍摄LCD屏幕出现的摩尔纹,例如在下图添加摩尔纹
原图:
- 模仿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
- 透视投影变换,模仿相机在不同角度、不同距离拍摄的图像
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
- Resample the image using Bayer CFA to simulate the RAW data, and add Gaussian noise to simulate sensor noise.
- Apply a simple ISP pipeline including demosaicing (bilinear interpolation) and denoising (standard de- noising function provided by OpenCV).
- 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.