def moire_fringe(img, degree):
    #img = cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2RGBA).astype(np.uint32)
    degree = min(max(degree, 1), 16)
    height, width, _ = img.shape
    center = height / 2, width / 2

    r_idx_array, c_idx_array = np.where(img[:, :, 0] < 256)
    r_idx_array = r_idx_array.reshape(height, width)
    c_idx_array = c_idx_array.reshape(height, width)

    offset_x = r_idx_array - center[0]
    offset_y = c_idx_array - center[1]
    radian = np.arctan2(offset_y, offset_x)
    radius = np.sqrt(offset_x**2 + offset_y**2)

    x = radius * np.cos(radian + degree * radius)
    y = radius * np.sin(radian + degree * radius)

    #不能使用uint
    x = np.minimum(np.maximum(x.astype(np.int32), 0), width - 1)
    y = np.minimum(np.maximum(y.astype(np.int32), 0), height - 1)

    #x = x.flatten()
    #y = y.flatten()
    dst_img = img[y, x, :]

    return inosculate(img, dst_img, 128)  # 对生成的图像和源图像进行色彩混合
def magic(bg_img, fg_img, transparency, _contrast):
    '''
    @效果:将两张图像合成为魔术图
    @param bg_img: 背景图像
    @param fg_img: 前景图像
    @param transparency: 前景透明度  [0, 255]
    @param _contrast: 前景图与背景图的对比度[-100, 100]
    @return: instance of Image
    '''
    
    bg_img = interleaving(bg_img)
    bg_img = contrast(bg_img, _contrast)
    
    return inosculate(bg_img, fg_img, transparency)
Exemple #3
0
def magic(bg_img, fg_img, transparency, _contrast):
    '''
    @效果:将两张图像合成为魔术图
    @param bg_img: 背景图像
    @param fg_img: 前景图像
    @param transparency: 前景透明度  [0, 255]
    @param _contrast: 前景图与背景图的对比度[-100, 100]
    @return: instance of Image
    '''

    bg_img = interleaving(bg_img)
    bg_img = contrast(bg_img, _contrast)

    return inosculate(bg_img, fg_img, transparency)
Exemple #4
0
def moire_fringe(img, degree):
    '''
    @效果:摩尔纹,对图像进行摩尔纹特效处理
    @param img: instance of Image
    @param degree: 强度,大小范围[1, 16] 
    @return: instance of Image
    '''
    
    degree = min(max(degree, 1), 16)
    
    if img.mode != "RGBA":
        img = img.convert("RGBA")
        
    width, height = img.size
    center = width / 2, height / 2 # 中心点
    pix = img.load()
    
    dst_img = Image.new("RGBA", (width, height))
    dst_pix = dst_img.load()
    
    for w in xrange(width):
        for h in xrange(height):
            offset_x = w - center[0]
            offset_y = h - center[1]
            
            radian = math.atan2(offset_y, offset_x) # 角度
            radius = math.sqrt(offset_x ** 2 + offset_y ** 2) # 半径
            
            x = int(radius * math.cos(radian + degree * radius))
            y = int(radius * math.sin(radian + degree * radius))
            
            x = min(max(x, 0), width - 1)
            y = min(max(y, 0), height - 1)
            
            dst_pix[w, h] = pix[x, y]
            
    return inosculate(img, dst_img, 128) # 对生成的图像和源图像进行色彩混合