灰度图像染成红色和黄色
# 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)
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()
将灰度图像染成不同的颜色
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()
完整代码
""" ========================= Tinting gray-scale images ========================= It can be useful to artificially tint an image with some color, either to highlight particular regions of an image or maybe just to liven up a grayscale image. This example demonstrates image-tinting by scaling RGB values and by adjusting colors in the HSV color-space. In 2D, color images are often represented in RGB---3 layers of 2D arrays, where the 3 layers represent (R)ed, (G)reen and (B)lue channels of the image. The simplest way of getting a tinted image is to set each RGB channel to the grayscale image scaled by a different multiplier for each channel. For example, multiplying the green and blue channels by 0 leaves only the red channel and produces a bright red image. Similarly, zeroing-out the blue channel leaves only the red and green channels, which combine to form yellow. """ import matplotlib.pyplot as plt from skimage import data from skimage import color from skimage import img_as_float grayscale_image = img_as_float(data.camera()[::2, ::2]) image = color.gray2rgb(grayscale_image) red_multiplier = [1, 0, 0] yellow_multiplier = [1, 1, 0] fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(red_multiplier * image) ax2.imshow(yellow_multiplier * image) ###################################################################### # In many cases, dealing with RGB values may not be ideal. Because of that, # there are many other `color spaces`_ in which you can represent a color # image. One popular color space is called HSV, which represents hue (~the # color), saturation (~colorfulness), and value (~brightness). For example, a # color (hue) might be green, but its saturation is how intense that green is # ---where olive is on the low end and neon on the high end. # # In some implementations, the hue in HSV goes from 0 to 360, since hues wrap # around in a circle. In scikit-image, however, hues are float values from 0 # to 1, so that hue, saturation, and value all share the same scale. # # .. _color spaces: # https://en.wikipedia.org/wiki/List_of_color_spaces_and_their_uses # # Below, we plot a linear gradient in the hue, with the saturation and value # turned all the way up: import numpy as np 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() ###################################################################### # Notice how the colors at the far left and far right are the same. That # reflects the fact that the hues wrap around like the color wheel (see HSV_ # for more info). # # .. _HSV: https://en.wikipedia.org/wiki/HSL_and_HSV # # Now, let's create a little utility function to take an RGB image and: # # 1. Transform the RGB image to HSV 2. Set the hue and saturation 3. # Transform the HSV image back to RGB def colorize(image, hue, saturation=1): """ Add color of the given hue to an RGB image. By default, set the saturation to 1 so that the colors pop! """ hsv = color.rgb2hsv(image) hsv[:, :, 1] = saturation hsv[:, :, 0] = hue return color.hsv2rgb(hsv) ###################################################################### # Notice that we need to bump up the saturation; images with zero saturation # are grayscale, so we need to a non-zero value to actually see the color # we've set. # # Using the function above, we plot six images with a linear gradient in the # hue and a non-zero saturation: 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() ###################################################################### # You can combine this tinting effect with numpy slicing and fancy-indexing # to selectively tint your images. In the example below, we set the hue of # some rectangles using slicing and scale the RGB values of some pixels found # by thresholding. In practice, you might want to define a region for tinting # based on segmentation results or blob detection methods. from skimage.filters import rank # Square regions defined as slices over the first two dimensions. top_left = (slice(100),) * 2 bottom_right = (slice(-100, None),) * 2 sliced_image = image.copy() sliced_image[top_left] = colorize(image[top_left], 0.82, saturation=0.5) sliced_image[bottom_right] = colorize(image[bottom_right], 0.5, saturation=0.5) # Create a mask selecting regions with interesting texture. noisy = rank.entropy(grayscale_image, np.ones((9, 9))) textured_regions = noisy > 4 # Note that using `colorize` here is a bit more difficult, since `rgb2hsv` # expects an RGB image (height x width x channel), but fancy-indexing returns # a set of RGB pixels (# pixels x channel). masked_image = image.copy() masked_image[textured_regions, :] *= red_multiplier fig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(8, 4), sharex=True, sharey=True) ax1.imshow(sliced_image) ax2.imshow(masked_image) plt.show() ###################################################################### # For coloring multiple regions, you may also be interested in # `skimage.color.label2rgb http://scikit- # image.org/docs/0.9.x/api/skimage.color.html#label2rgb`_.
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2024年11月24日
2024年11月24日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]