电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

python庫skimage給灰度圖像染色的方法示例

瀏覽:90日期:2022-07-27 11:22:18

灰度圖像染成紅色和黃色

# 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)

python庫skimage給灰度圖像染色的方法示例

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_gradientall_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()

python庫skimage給灰度圖像染色的方法示例

將灰度圖像染成不同的顏色

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()

python庫skimage給灰度圖像染色的方法示例

完整代碼

'''=========================Tinting gray-scale images=========================It can be useful to artificially tint an image with some color, either tohighlight particular regions of an image or maybe just to liven up a grayscaleimage. This example demonstrates image-tinting by scaling RGB values and byadjusting colors in the HSV color-space.In 2D, color images are often represented in RGB---3 layers of 2D arrays, wherethe 3 layers represent (R)ed, (G)reen and (B)lue channels of the image. Thesimplest way of getting a tinted image is to set each RGB channel to thegrayscale image scaled by a different multiplier for each channel. For example,multiplying the green and blue channels by 0 leaves only the red channel andproduces a bright red image. Similarly, zeroing-out the blue channel leavesonly the red and green channels, which combine to form yellow.'''import matplotlib.pyplot as pltfrom skimage import datafrom skimage import colorfrom skimage import img_as_floatgrayscale_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 nphue_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_gradientall_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 RGBdef 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),) * 2bottom_right = (slice(-100, None),) * 2sliced_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_multiplierfig, (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`_.

python庫skimage給灰度圖像染色的方法示例

到此這篇關于python庫skimage給灰度圖像染色的方法示例的文章就介紹到這了,更多相關python 灰度圖像染色內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 专注提供国外机电设备及配件-工业控制领域一站式服务商-深圳市华联欧国际贸易有限公司 | 深圳市宏康仪器科技有限公司-模拟高空低压试验箱-高温防爆试验箱-温控短路试验箱【官网】 | 北京律师咨询_知名专业北京律师事务所_免费法律咨询 | 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 深圳货架厂家_金丽声精品货架_广东金丽声展示设备有限公司官网 | 对夹式止回阀_对夹式蝶形止回阀_对夹式软密封止回阀_超薄型止回阀_不锈钢底阀-温州上炬阀门科技有限公司 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | 高精度电阻回路测试仪-回路直流电阻测试仪-武汉特高压电力科技有限公司 | 大立教育官网-一级建造师培训-二级建造师培训-造价工程师-安全工程师-监理工程师考试培训 | 西安展台设计搭建_西安活动策划公司_西安会议会场布置_西安展厅设计西安旭阳展览展示 | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 混合反应量热仪-高温高压量热仪-微机差热分析仪DTA|凯璞百科 | 玻璃钢板-玻璃钢防腐瓦-玻璃钢材料-广东壹诺 | 不锈钢复合板|钛复合板|金属复合板|南钢集团安徽金元素复合材料有限公司-官网 | 欧景装饰设计工程有限公司-无锡欧景装饰官网 | 萃取箱-萃取槽-PVC萃取箱厂家-混合澄清槽- 杭州南方化工设备 | 撕碎机_轮胎破碎机_粉碎机_回收生产线厂家_东莞华达机械有限公司 | 上海软件开发-上海软件公司-软件外包-企业软件定制开发公司-咏熠科技 | 釜溪印象网络 - Powered by Discuz! | 汽液过滤网厂家_安平县银锐丝网有限公司 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 泰国试管婴儿_泰国第三代试管婴儿_泰国试管婴儿费用/多少钱_孕泰来 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 首页-浙江橙树网络技术有限公司 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 定制液氮罐_小型气相液氮罐_自增压液氮罐_班德液氮罐厂家 | 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 清水-铝合金-建筑模板厂家-木模板价格-铝模板生产「五棵松」品牌 | YT保温材料_YT无机保温砂浆_外墙保温材料_南阳银通节能建材高新技术开发有限公司 | 大型果蔬切片机-水果冬瓜削皮机-洗菜机切菜机-肇庆市凤翔餐饮设备有限公司 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 建筑消防设施检测系统检测箱-电梯**检测仪器箱-北京宇成伟业科技有限责任公司 | 电加热导热油炉-空气加热器-导热油加热器-翅片电加热管-科安达机械 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | CTAB,表面活性剂1631溴型(十六烷基三甲基溴化铵)-上海升纬化工原料有限公司 | 柴油机_柴油发电机_厂家_品牌-江苏卡得城仕发动机有限公司 | 桥架-槽式电缆桥架-镀锌桥架-托盘式桥架 - 上海亮族电缆桥架制造有限公司 |