python中color_transfer库介绍

【时间】2018.10.19

【题目】python中color_transfer库介绍

概述

Color_Transfer包是一个基于 Color Transfer between Images[Reinhard et al., 2001] 的OpenCV和Python实现。该算法用于图像间的颜色迁移,它本身非常高效(比基于直方图的方法快得多),只需要L*a*b*颜色空间中每个通道像素强度的均值和标准差。要获得更多信息,以及详细的代码审查, 看看原作者博客上的这篇文章.

库地址:https://github.com/jrosebr1/color_transfer

库安装:  pip install color_transfer

 

一、功能描述

color_transfer库中的color_transfer函数用于两张图片之间的色彩迁移。

 

二、基本用法

transfer = color_transfer(source, target)

  • 其中输入source, target分别为想要进行色彩迁移的原图像和目标图像,可以使用cv2.imread()进行读取

  • 输出transfer是色彩迁移后的图像

注意:这只是color_transfer函数的最基本用法,它的输入还可以包含其它参数用于进一步的调节,具体请看概述中的库地址。

 

三、代码示例

下面的代码示例显示了颜色迁移的结果以及原图像

【代码】

from color_transfer import color_transfer

import cv2



def show_image(title, image, width = 300):

    # resize the image to have a constant width, just to

    # make displaying the images take up less screen real

    # estate

    r = width / float(image.shape[1])

    dim = (width, int(image.shape[0] * r))

    resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)



    # show the resized image

    cv2.imshow(title, resized)



source = cv2.imread('C:\\Users\\Administrator\\Desktop\\test\\image\\autumn.jpg')

target = cv2.imread('C:\\Users\\Administrator\\Desktop\\test\\image\\fallingwater.jpg')



# transfer the color distribution from the source image

# to the target image

transfer = color_transfer(source, target)



# check to see if the output image should be saved



# show the images and wait for a key press

show_image("Source", source)

show_image("Target", target)

show_image("Transfer", transfer)

cv2.waitKey(0)

【运行结果】

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值