python改图片颜色_如何使用python改变二值图像的颜色?

你可以用调色板来做,但这里我做了一个完整的RGB版本。在from PIL import Imagefrom skimage import datafrom skimage.filters import threshold_otsu# Load imageimage = data.camera()# Threshold image to binarythresh = threshold_otsu(i...
摘要由CSDN通过智能技术生成

你可以用调色板来做,但这里我做了一个完整的RGB版本。在from PIL import Image

from skimage import data

from skimage.filters import threshold_otsu

# Load image

image = data.camera()

# Threshold image to binary

thresh = threshold_otsu(image)

binary = image > thresh

# Make 3 channel RGB image same dimensions

RGB = np.zeros((binary.shape[0],binary.shape[1],3), dtype=np.uint8)

# Make True pixels red

RGB[binary] = [255,0,0]

# Make False pixels blue

RGB[~binary] = [0,0,255]

# Display result

Image.fromarray(RGB).show()

e66a3c467a021584e00b8860cb350d5d.png

你可以用这种方式表达同样的事情:

^{pr2}$

存储一个只有2种颜色的完整的RGB图像是相当浪费空间的,因为每个像素有3个字节(R、G和B)。最好是制作一个调色板图像,其中每个像素只存储1个字

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值