莫尔纹

论文<Moire Photo Restoration using multiresolution convolutional neural networks>

import cv2
import numpy as np
import math

if __name__ == '__main__':
    im = cv2.imread('/Users/xxx/Desktop/qingyunian-1.jpg')
    
    height, width = im.shape[0], im.shape[1]
    degree = 3
    center_x = width/2
    center_y = height/2

    im1 = np.zeros(im.shape,dtype = im.dtype)
    for i in range(height):
        for j in range(width):
            x_offset = j-center_x
            y_offset = i-center_y

            radian = math.atan2(float(x_offset),float(y_offset))
            radius = math.sqrt(1.0*x_offset*x_offset+y_offset*y_offset)

            x = int(radius*math.cos(radian+radius*degree))
            y = int(radius*math.sin(radian+radius*degree))
            
            if x>=width:
                x = width-1
            if x<0:
                x = 0
            if y>=height:
                y = height-1
            if y<0:
                y=0
            im1[i,j,:] =im[y,x,:] 
    dst = (im1.astype(np.float32)-im.astype(np.float32))*0.3+im.astype(np.float32)

    cv2.imshow('moire',dst.astype(np.uint8))
    cv2.waitKey(0)
    cv2.imwrite('/Users/xxx/Desktop/moire-qingyunian-1.png', dst)

推荐阅读更多精彩内容