当前位置: 首页>>代码示例>>Python>>正文


Python colorsys.rgb_to_hsv方法代码示例

本文整理汇总了Python中colorsys.rgb_to_hsv方法的典型用法代码示例。如果您正苦于以下问题:Python colorsys.rgb_to_hsv方法的具体用法?Python colorsys.rgb_to_hsv怎么用?Python colorsys.rgb_to_hsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colorsys的用法示例。


在下文中一共展示了colorsys.rgb_to_hsv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_state

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def get_state(channel):
    global status
    for chan in range(1, 5):
        for pixel in range(16):
            if mote.get_pixel(chan, pixel) != (0, 0, 0):
                status['state'][chan] = 1
            else:
                status['state'][chan] = 0
        r, g, b = mote.get_pixel(chan, 0)[0:3]
        h, s, v = rgb_to_hsv(r, g, b)[2]
        status['colour'][chan] = [r, g, b]
        status['brightness'][chan] = v
    if channel == 'all':
        return jsonify(status)
    else:
        channel_status = {}
        for k in status:
            channel_status[k] = {int(channel): status[k][int(channel)]}
        return jsonify(channel_status)

## Sets all channels, or a given channel, "on" or "off" 
开发者ID:pimoroni,项目名称:mote,代码行数:23,代码来源:mote-api.py

示例2: set_brightness

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def set_brightness(channel, br):
    global status
    if channel == 'all':
        for ch in status['colour']:
            c = status['colour'][ch]
            r, g, b = c
            h, s, v = rgb_to_hsv(r, g, b)
            v = int(br) / 100.0
            r, g, b = [int(c * 255) for c in hsv_to_rgb(h, s, v)]
            status['colour'][ch] = [r, g, b]
        if not all(status['state'].values()) == 0:
            mote_on(status)
    else:
        c = status['colour'][int(channel)]
        r, g, b = c
        h, s, v = rgb_to_hsv(r, g, b)
        v = int(br) / 100.0
        r, g, b = [int(c * 255) for c in hsv_to_rgb(h, s, v)]
        status['colour'][int(channel)] = [r, g, b]
        if not status['state'][int(channel)] == 0:
            mote_on(status)
    return jsonify(status)

## Returns the current API version to the requester 
开发者ID:pimoroni,项目名称:mote,代码行数:26,代码来源:mote-api.py

示例3: get_random_h_and_v_shifts_for_custom_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def get_random_h_and_v_shifts_for_custom_color(self, default_color):
    r, g, b = default_color
    h, s, v = colorsys.rgb_to_hsv(r/255, g/255, b/255)
    h = int(h*360)
    s = int(s*100)
    v = int(v*100)
    
    min_v_shift = -40
    max_v_shift = 40
    if s < 10:
      # For very unsaturated colors, we want to limit the range of value randomization to exclude results that wouldn't change anything anyway.
      # This effectively stops white and black from having a 50% chance to not change at all.
      min_v_shift = max(-40, 0-v)
      max_v_shift = min(40, 100-v)
    
    h_shift = random.randint(0, 359)
    v_shift = random.randint(min_v_shift, max_v_shift)
    
    return (h_shift, v_shift) 
开发者ID:LagoLunatic,项目名称:wwrando,代码行数:21,代码来源:randomizer_window.py

示例4: test_hsv_values

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def test_hsv_values(self):
        values = [
            # rgb, hsv
            ((0.0, 0.0, 0.0), (  0  , 0.0, 0.0)), # black
            ((0.0, 0.0, 1.0), (4./6., 1.0, 1.0)), # blue
            ((0.0, 1.0, 0.0), (2./6., 1.0, 1.0)), # green
            ((0.0, 1.0, 1.0), (3./6., 1.0, 1.0)), # cyan
            ((1.0, 0.0, 0.0), (  0  , 1.0, 1.0)), # red
            ((1.0, 0.0, 1.0), (5./6., 1.0, 1.0)), # purple
            ((1.0, 1.0, 0.0), (1./6., 1.0, 1.0)), # yellow
            ((1.0, 1.0, 1.0), (  0  , 0.0, 1.0)), # white
            ((0.5, 0.5, 0.5), (  0  , 0.0, 0.5)), # grey
        ]
        for (rgb, hsv) in values:
            self.assertTripleEqual(hsv, colorsys.rgb_to_hsv(*rgb))
            self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(*hsv)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_colorsys.py

示例5: testBatch

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def testBatch(self):
    # Build an arbitrary RGB image
    np.random.seed(7)
    batch_size = 5
    shape = (batch_size, 2, 7, 3)

    for nptype in [np.float32, np.float64]:
      inp = np.random.rand(*shape).astype(nptype)

      # Convert to HSV and back, as a batch and individually
      with self.test_session(use_gpu=True) as sess:
        batch0 = constant_op.constant(inp)
        batch1 = image_ops.rgb_to_hsv(batch0)
        batch2 = image_ops.hsv_to_rgb(batch1)
        split0 = array_ops.unpack(batch0)
        split1 = list(map(image_ops.rgb_to_hsv, split0))
        split2 = list(map(image_ops.hsv_to_rgb, split1))
        join1 = array_ops.pack(split1)
        join2 = array_ops.pack(split2)
        batch1, batch2, join1, join2 = sess.run([batch1, batch2, join1, join2])

      # Verify that processing batch elements together is the same as separate
      self.assertAllClose(batch1, join1)
      self.assertAllClose(batch2, join2)
      self.assertAllClose(batch2, inp) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:image_ops_test.py

示例6: _adjustHueNp

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def _adjustHueNp(self, x_np, delta_h):
    self.assertEqual(x_np.shape[-1], 3)
    x_v = x_np.reshape([-1, 3])
    y_v = np.ndarray(x_v.shape, dtype=x_v.dtype)
    channel_count = x_v.shape[0]
    for i in xrange(channel_count):
      r = x_v[i][0]
      g = x_v[i][1]
      b = x_v[i][2]
      h, s, v = colorsys.rgb_to_hsv(r, g, b)
      h += delta_h
      h = math.fmod(h + 10.0, 1.0)
      r, g, b = colorsys.hsv_to_rgb(h, s, v)
      y_v[i][0] = r
      y_v[i][1] = g
      y_v[i][2] = b
    return y_v.reshape(x_np.shape) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:image_ops_test.py

示例7: createLatentPicker

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def createLatentPicker(self, widgetLayout):
		def clearLayout(layout):
			while layout.count():
				child = layout.takeAt(0)
				if child.widget():
					child.widget().deleteLater()

		clearLayout(widgetLayout)

		latent_images = np.asarray(tf_manager.getLatentImages()._getvalue())

		latent_colors = np.asarray(tf_manager.getDominantClusterColors()._getvalue())
		latent_hues = [ colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)[0] for r, g, b in latent_colors ]
		sorting = np.argsort(latent_hues)

		# create latent picker label widgets
		self.latentLabels = []
		for i in range(len(latent_images)):
			cluster = sorting[i]
			label = LatentLabel(self, cluster, latent_images[cluster], tuple(latent_colors[cluster]))
			label.latentDragged.connect(self.viewer.dragStarted)
			label.activated.connect(self.activateLabel)
			self.latentLabels.append(label)
			self.viewer.mouseDrop.connect(label.dropFinished)
			widgetLayout.addWidget(label) 
开发者ID:afruehstueck,项目名称:tileGAN,代码行数:27,代码来源:tileGAN_client.py

示例8: set_outline

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def set_outline(self, color=(255, 0, 0), width=2):
        'enables the draw_outline and sets line color and width'
        self.perm_outline = True
        if color == 0 and hasattr(self, "door_outline") is False:  # if color is 0 calculate colour from base colour
            # convert to hsv
            c = self.color
            h, s, v = ex.rgb_to_hsv(c[0], c[1], c[2])
            outline_color = ex.hsv_to_rgb(h, s + 50, v - 50)
            self.perm_outline_color = outline_color
        elif color == 1:
            c = self.color
            h, s, v = ex.rgb_to_hsv(c[0], c[1], c[2])
            outline_color = ex.hsv_to_rgb(h, s + 20, v - 20)
            self.perm_outline_color = outline_color
        elif hasattr(self, "door_outline") is False:
            self.perm_outline_color = color

        self.perm_outline_width = width
        self.init_pow = width 
开发者ID:imiolek-ireneusz,项目名称:eduActiv8,代码行数:21,代码来源:board.py

示例9: hue_name

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def hue_name(color):
    arr = np.array(color)
    h, s, v = colorsys.rgb_to_hsv(*arr[:3] / 255)
    if s == 0:
        return 'Greys'

    if h < 0.02:
        return 'Reds'
    elif h < 0.11:
        return "Oranges"
    elif h < 0.2:
        return "Yellows"
    elif h < 0.45:
        return "Greens"
    elif h < 0.52:
        return "Turquoises"
    elif h < 0.7:
        return "Blues"
    else:
        return "Purples" 
开发者ID:lordmauve,项目名称:wasabi2d,代码行数:22,代码来源:update_colors.py

示例10: step

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def step(target, repetitions=1):
  _, rgba = target.split(' = ')

  rgba = re.findall(r'rgba\((\d+), (\d+), (\d+), ([\d\.]+)(?:.*)?\)', rgba)[0]
  rgba = [float(x) for x in rgba]
  r, g, b, a = rgba

  lum = math.sqrt(.241 * r + .691 * g + .068 * b)

  h, s, v = colorsys.rgb_to_hsv(r, g, b)

  h2 = int(h * repetitions)
  # lum2 = int(lum * repetitions)
  v2 = int(v * repetitions)

  if h2 % 2 == 1:
    v2 = repetitions - v2
    lum = repetitions - lum

  return (h2, lum, v2) 
开发者ID:indietyp,项目名称:hawthorne,代码行数:22,代码来源:color-renderer.py

示例11: RGB_to_RG

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def RGB_to_RG(rgb):
    if rgb[2] != 0:
        color = list(colorsys.rgb_to_hsv(rgb[0], rgb[1], rgb[2]))
        color[0] = color[0] * (106/330)
        color = list(colorsys.hsv_to_rgb(color[0], color[1], color[2]))
        color = [round(x) for x in color]
        for x in range(2):
            color[x] = round(color[x])
        return color[:2] + [0]
    else:
        return rgb 
开发者ID:nimaid,项目名称:LPHK,代码行数:13,代码来源:lp_colors.py

示例12: _assert_all_hues

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def _assert_all_hues(self, colors):
        hues = []
        for color in colors:
            hue, _, _ = colorsys.rgb_to_hsv(*color)
            hues.append(hue)

        for target_hue in range(0, 10):
            closest = min(abs(hue - target_hue / 10) for hue in hues)
            self.assertLess(closest, 0.1) 
开发者ID:raveberry,项目名称:raveberry,代码行数:11,代码来源:test_lights.py

示例13: continuous_palette_for_color

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def continuous_palette_for_color(color, bins=256):
    """Creates a continuous color palette based on a single color.

    Args:
      color: the rgb color tuple to create a continuous palette for.
      bins: the number of colors to create in the continuous palette.

    Returns:
      The continuous rgb color palette with 3*bins values represented as [r0,g0,b0,r1,g1,b1,..]
    """

    # A quick and dirty way to create a continuous color palette is to convert from the RGB color
    # space into the HSV color space and then only adapt the color's saturation (S component).

    r, g, b = [v / 255 for v in Mapbox[color].value]
    h, s, v = colorsys.rgb_to_hsv(r, g, b)

    palette = []

    for i in range(bins):
        ns = (1 / bins) * (i + 1)
        palette.extend([int(v * 255) for v in colorsys.hsv_to_rgb(h, ns, v)])

    assert len(palette) // 3 == bins

    return palette 
开发者ID:mapbox,项目名称:robosat,代码行数:28,代码来源:colors.py

示例14: _rgb2hs

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def _rgb2hs(self, rgb):
        r = rgb[0] / 255.0
        g = rgb[1] / 255.0
        b = rgb[2] / 255.0

        h, s, v = colorsys.rgb_to_hsv(r, g, b)

        h = int(self._mapRange(h, 0.0, 1.0, 0, 65535))
        s = int(self._mapRange(s, 0.0, 1.0, 0, 254))
        return (h, s) 
开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:12,代码来源:hue.py

示例15: rgb_to_hsv

# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import rgb_to_hsv [as 别名]
def rgb_to_hsv(pixel):
    return colorsys.rgb_to_hsv(*(p / 255 for p in pixel)) 
开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:4,代码来源:conversions.py


注:本文中的colorsys.rgb_to_hsv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。