python方格染色_python库skimage给灰度图像染色的方法示例

灰度图像染成红色和黄色

# 1.将灰度图像转换为RGB图像

image = color.gray2rgb(grayscale_image)

# 2.保留红色分量和黄色分量

red_multiplier = [1, 0, 0]

yellow_multiplier = [1, 1, 0]

# 3.显示图像

fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4),

sharex=True, sharey=True)

ax1.imshow(red_multiplier * image)

ax2.imshow(yellow_multiplier * image)

ccd635156c0b8fc2ffafec87d5dc8b07.png

HSV图像,H从0到1表示的颜色

hue_gradient = np.linspace(0, 1)

# print(hue_gradient.shape) # output:(50,)

hsv = np.ones(shape=(1, len(hue_gradient), 3), dtype=float)

hsv[:, :, 0] = hue_gradient

all_hues = color.hsv2rgb(hsv)

fig, ax = plt.subplots(figsize=(5, 2))

# Set image extent so hues go from 0 to 1 and the image is a nice aspect ratio.

ax.imshow(all_hues, extent=(0, 1, 0, 0.2))

ax.set_axis_off()

29e131484d360f4b91a276480da0c75a.png

将灰度图像染成不同的颜色

hue_rotations = np.linspace(0, 1, 6)

fig, axes = plt.subplots(nrows=2, ncols=3, sharex=True, sharey=True)

for ax, hue in zip(axes.flat, hue_rotations):

# Turn down the saturation to give it that vintage look.

tinted_image = colorize(image, hue, saturation=0.3)

ax.imshow(tinted_image, vmin=0, vmax=1)

ax.set_axis_off()

fig.tight_layout()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值