本文整理汇总了Python中matplotlib.colors.hsv_to_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python colors.hsv_to_rgb方法的具体用法?Python colors.hsv_to_rgb怎么用?Python colors.hsv_to_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.colors
的用法示例。
在下文中一共展示了colors.hsv_to_rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rainbow
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def rainbow(n):
"""
Returns a list of colors sampled at equal intervals over the spectrum.
Parameters
----------
n : int
The number of colors to return
Returns
-------
R : (n,3) array
An of rows of RGB color values
Notes
-----
Converts from HSV coordinates (0, 1, 1) to (1, 1, 1) to RGB. Based on
the Sage function of the same name.
"""
from matplotlib import colors
R = np.ones((1,n,3))
R[0,:,0] = np.linspace(0, 1, n, endpoint=False)
#Note: could iterate and use colorsys.hsv_to_rgb
return colors.hsv_to_rgb(R).squeeze()
示例2: main
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def main(imgsize):
y, x = np.ogrid[6: -6: imgsize*2j, -6: 6: imgsize*2j]
z = x + y*1j
z = RiemannSphere(Klein(Mobius(Klein(z))))
# define colors in hsv space
H = np.sin(z[0]*np.pi)**2
S = np.cos(z[1]*np.pi)**2
V = abs(np.sin(z[2]*np.pi) * np.cos(z[2]*np.pi))**0.2
HSV = np.stack((H, S, V), axis=2)
# transform to rgb space
img = hsv_to_rgb(HSV)
fig = plt.figure(figsize=(imgsize/100.0, imgsize/100.0), dpi=100)
ax = fig.add_axes([0, 0, 1, 1], aspect=1)
ax.axis('off')
ax.imshow(img)
fig.savefig('kaleidoscope.png')
示例3: colorize_image
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def colorize_image(self, flow_x, flow_y):
if self.hsv_buffer is None:
self.hsv_buffer = np.empty((flow_x.shape[0], flow_x.shape[1],3))
self.hsv_buffer[:,:,1] = 1.0
self.hsv_buffer[:,:,0] = (np.arctan2(flow_y,flow_x)+np.pi)/(2.0*np.pi)
self.hsv_buffer[:,:,2] = np.linalg.norm( np.stack((flow_x,flow_y), axis=0), axis=0 )
# self.hsv_buffer[:,:,2] = np.log(1.+self.hsv_buffer[:,:,2]) # hopefully better overall dynamic range in final video
flat = self.hsv_buffer[:,:,2].reshape((-1))
m = np.nanmax(flat[np.isfinite(flat)])
if not np.isclose(m, 0.0):
self.hsv_buffer[:,:,2] /= m
return colors.hsv_to_rgb(self.hsv_buffer)
示例4: visualise_latent
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def visualise_latent(Z, identifier):
"""
visualise a SINGLE point in the latent space
"""
seq_length = Z.shape[0]
latent_dim = Z.shape[1]
if latent_dim > 2:
print('WARNING: Only visualising first two dimensions of latent space.')
h = np.random.random()
colours = np.array([hsv_to_rgb((h, i/seq_length, 0.96)) for i in range(seq_length)])
# plt.plot(Z[:, 0], Z[:, 1], c='grey', alpha=0.5)
for i in range(seq_length):
plt.scatter(Z[i, 0], Z[i, 1], marker='o', c=colours[i])
plt.savefig('./experiments/plots/' + identifier + '_Z.png')
plt.clf()
plt.close()
return True
# --- to do with the model --- #
示例5: _get_rgb_phase_magnitude_array
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def _get_rgb_phase_magnitude_array(
phase, magnitude, rotation=None, magnitude_limits=None, max_phase=2 * np.pi
):
phase = _find_phase(phase, rotation=rotation, max_phase=max_phase)
phase = phase / (2 * np.pi)
if magnitude_limits is not None:
np.clip(magnitude, magnitude_limits[0], magnitude_limits[1], out=magnitude)
magnitude_max = magnitude.max()
if magnitude_max == 0:
magnitude_max = 1
magnitude = magnitude / magnitude_max
S = np.ones_like(phase)
HSV = np.dstack((phase, S, magnitude))
RGB = hsv_to_rgb(HSV)
return RGB
示例6: drawClusters
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def drawClusters(stat, ops):
Ly = ops['Lyc']
Lx = ops['Lxc']
ncells = len(stat)
r=np.random.random((ncells,))
iclust = -1*np.ones((Ly,Lx),np.int32)
Lam = np.zeros((Ly,Lx))
H = np.zeros((Ly,Lx,1))
for n in range(ncells):
isingle = Lam[stat[n]['ypix'],stat[n]['xpix']]+1e-4 < stat[n]['lam']
y = stat[n]['ypix'][isingle]
x = stat[n]['xpix'][isingle]
Lam[y,x] = stat[n]['lam'][isingle]
#iclust[ypix,xpix] = n*np.ones(ypix.shape)
H[y,x,0] = r[n]*np.ones(y.shape)
S = np.ones((Ly,Lx,1))
V = np.maximum(0, np.minimum(1, 0.75 * Lam / Lam[Lam>1e-10].mean()))
V = np.expand_dims(V,axis=2)
hsv = np.concatenate((H,S,V),axis=2)
rgb = hsv_to_rgb(hsv)
return rgb
示例7: create_masks_of_cells
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def create_masks_of_cells(self, mean_img):
H = np.zeros_like(mean_img)
S = np.zeros_like(mean_img)
columncol = self.parent.colors['istat'][0]
for n in np.arange(np.shape(self.parent.iscell)[0]):
if self.parent.iscell[n] == 1:
ypix = self.parent.stat[n]['ypix'].flatten()
xpix = self.parent.stat[n]['xpix'].flatten()
H[ypix, xpix] = np.random.rand()
S[ypix, xpix] = 1
pix = np.concatenate(((H[:, :, np.newaxis]),
S[:, :, np.newaxis],
mean_img[:, :, np.newaxis]), axis=-1)
pix = hsv_to_rgb(pix)
return pix
示例8: flow_visualize
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def flow_visualize(flow, max_range = 1e3):
""" Original code from SINTEL toolbox, by Jonas Wulff.
"""
import matplotlib.colors as colors
du = flow[:, :, 0]
dv = flow[:, :, 1]
[h,w] = du.shape
max_flow = min(max_range, np.max(np.sqrt(du * du + dv * dv)))
img = np.ones((h, w, 3), dtype=np.float64)
# angle layer
img[:, :, 0] = (np.arctan2(dv, du) / (2 * np.pi) + 1) % 1.0
# magnitude layer, normalized to 1
img[:, :, 1] = np.sqrt(du * du + dv * dv) / (max_flow + 1e-8)
# phase layer
#img[:, :, 2] = valid
# convert to rgb
img = colors.hsv_to_rgb(img)
# remove invalid point
img[:, :, 0] = img[:, :, 0]
img[:, :, 1] = img[:, :, 1]
img[:, :, 2] = img[:, :, 2]
return img
示例9: _single_hsv_to_rgb
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def _single_hsv_to_rgb(hsv):
"""Transform a color from the hsv space to the rgb."""
from matplotlib.colors import hsv_to_rgb
return hsv_to_rgb(array(hsv).reshape(1, 1, 3)).reshape(3)
示例10: hue_linspace_colors
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def hue_linspace_colors(n, sat=1.0, light=0.5):
return (hsv_to_rgb(np.dstack((
np.linspace(0., 1., n, endpoint=False),
np.ones(n) * sat,
np.ones(n) * light)))[0] * 255).astype(np.uint8)
示例11: main
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def main():
M = np.zeros((IMAGE_SIZE, IMAGE_SIZE), np.complex)
y, x = np.ogrid[YMAX: YMIN: IMAGE_SIZE*SUPER_SAMPLING*1j,
XMIN: XMAX: IMAGE_SIZE*SUPER_SAMPLING*1j]
z = x + y*1j
for c in tqdm.tqdm(z.flatten()):
if escape(c):
for z in iterate(c):
x, y = complex_to_pixel(z)
if 0 <= x < IMAGE_SIZE and 0 <= y < IMAGE_SIZE:
M[x, y] += c
M /= (SUPER_SAMPLING * SUPER_SAMPLING)
hue = (np.angle(M) / np.pi + 1) / 2
x = np.minimum(1, np.absolute(M) / 18.0)
H = hue
S = np.maximum(np.minimum(1, 2 * (1 - np.tan(x))), 0)
V = np.minimum(1, 2 * np.sin(x))
V = np.power(V / np.max(V), 1/1.6)
HSV = np.stack((H, S, V), axis=2)
img = hsv_to_rgb(HSV)
fig = plt.figure(figsize=(IMAGE_SIZE/100.0, IMAGE_SIZE/100.0), dpi=100)
ax = fig.add_axes([0, 0, 1, 1], aspect=1)
ax.axis("off")
ax.imshow(img, interpolation="bilinear")
plt.show()
fig.savefig("buddhabrot.png")
示例12: rgb_from_hsv_data
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def rgb_from_hsv_data(hue, saturation, value):
"""Creates image in RGB format from HSV data."""
return hsv_to_rgb(hsv_image(hue, saturation, value))
示例13: segmentation_probabilities
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def segmentation_probabilities(image, probabilities, hue):
return hsv_to_rgb(hsv_image(hue, probabilities, image))
示例14: masked_segmentation_probabilities
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def masked_segmentation_probabilities(image, probabilities, hue, mask):
return hsv_to_rgb(hsv_image(hue, np.where(mask, probabilities, 0), np.where(mask, 1, image)))
示例15: test_rgb_hsv_round_trip
# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import hsv_to_rgb [as 别名]
def test_rgb_hsv_round_trip():
for a_shape in [(500, 500, 3), (500, 3), (1, 3), (3,)]:
np.random.seed(0)
tt = np.random.random(a_shape)
assert_array_almost_equal(tt,
mcolors.hsv_to_rgb(mcolors.rgb_to_hsv(tt)))
assert_array_almost_equal(tt,
mcolors.rgb_to_hsv(mcolors.hsv_to_rgb(tt)))