本文整理汇总了Python中skimage.color.hsv2rgb函数的典型用法代码示例。如果您正苦于以下问题:Python hsv2rgb函数的具体用法?Python hsv2rgb怎么用?Python hsv2rgb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hsv2rgb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ton_and_color_corrections
def ton_and_color_corrections():
#色调和彩色校正
image=data.astronaut()
h1=color.rgb2hsv(image)
h2=h1.copy()
h1[:,:,1]=h1[:,:,1]*0.5
image1=color.hsv2rgb(h1)
h2[:,:,1]=h2[:,:,1]*0.5+0.5
image2=color.hsv2rgb(h2)
io.imshow(image)
io.imsave('astronaut.png',image)
io.imshow(image1)
io.imsave('astronautlight.png',image1)
io.imshow(image2)
io.imsave('astronautdark.png',image2)
imagered=image.copy()
imagered[:,:,0]=image[:,:,0]*127.0/255+128
io.imsave('astronautred.png',imagered)
imageblue=image.copy()
imageblue[:,:,2]=image[:,:,2]*127.0/255+128
io.imsave('astronautblue.png',imageblue)
imageyellow=image.copy()
imageyellow[:,:,0]=image[:,:,0]*127.0/255+128
imageyellow[:,:,1]=image[:,:,1]*127.0/255+128
io.imsave('astronautyellow.png',imageyellow)
io.imshow(imageyellow)
示例2: classify_and_show
def classify_and_show(km, img_dir):
'''Use a km object to display both the original and altered version of the image at
img_dir, must be PNG'''
img = rgb2hsv(mpimg.imread(img_dir)[...,:3])
s = img.shape
data = img.reshape((s[0] * s[1], s[2]))
labels = km.classify(data)
plt.imshow(hsv2rgb(img))
plt.figure()
plt.imshow(hsv2rgb(km.means[labels].reshape(s)))
示例3: gaborbank_orientation_vis
def gaborbank_orientation_vis(d, method='mean', legend=True):
""" Visualise the orientation for each point in the image.
Method 'mean' uses the mean resultant vector over
all orientation filters. Method 'max' takes the orientation
at each pixel to be that of the filter with maximum energy
at that pixel.
Adapted from http://nbviewer.ipython.org/github/gestaltrevision\
/python_for_visres/blob/master/Part7/Part7_Image_Statistics.ipynb
Args:
d: the dict output by gaborbank_convolve.
"""
res = d['res']
e = res.real**2 + res.imag**2 # energy
e = e.sum(axis=3).sum(axis=2) # sum energy over scales and orientations.
if method == 'mean':
ori = gaborbank_mean_orientation(d)
elif method == 'max':
ori = gaborbank_max_orientation(d)
else:
raise ValueError('Unknown method!')
# output values range 0--pi; adjust hues accordingly:
H = ori / np.pi
S = np.ones_like(H)
V = (e - e.min()) / e.max()
HSV = np.dstack((H, S, V))
RGB = hsv2rgb(HSV)
if legend is True:
# Render a hue circle
sz = int(e.shape[0] * 0.1)
r, a = pu.image.axes_polar(sz)
a[a < 0] += np.pi
a /= np.pi
# a = (a - a.min()) / a.max()
a = 1 - a # not sure why I have to flip this, but
# otherwise diagonals are reversed.
mask = (r < 0.9) & (r > 0.3)
hsv_legend = np.dstack((a,
np.ones_like(a, dtype='float'),
mask.astype('float')))
rgb_legend = hsv2rgb(hsv_legend)
RGB[:sz, :sz, :] = rgb_legend[::-1, ::]
return RGB
示例4: get_merged_pic
def get_merged_pic(self, nuclei_color = 0.66, foci_color = 0.33, seeds = False):
'''Return merged pic with foci and nuclei'''
x_max, y_max = self.nuclei.shape
active_cells = self.active_cells()
cell_number = len(active_cells)
if cell_number == 0:
return np.zeros((x_max, y_max, 3), dtype = np.uint8)
merged_pic_peaces = []
nuclei_rgb_koef = hsv2rgb(np.array([nuclei_color, 1., 1.]).reshape((1,1,3))).reshape(3)
foci_rgb_koef = hsv2rgb(np.array([foci_color, 1., 1.]).reshape((1,1,3))).reshape(3)
for cur_cell in active_cells:
if seeds:
foci = cur_cell.foci_seeds
else:
foci = cur_cell.foci_binary
nucleus_only = cur_cell.nucleus - foci
pic_foci_enhanced = 255 - np.floor((255 - cur_cell.pic_foci)*0.6)
pic_foci_enhanced = foci*pic_foci_enhanced
pic_nucleus_only = cur_cell.pic_nucleus*nucleus_only
pic_foci_enhanced_3d = np.dstack((pic_foci_enhanced, pic_foci_enhanced, pic_foci_enhanced))
pic_nucleus_only_3d = np.dstack((pic_nucleus_only, pic_nucleus_only, pic_nucleus_only))
pic_foci_rgb = pic_foci_enhanced_3d*foci_rgb_koef
pic_nucleus_only_rgb = pic_nucleus_only_3d*nuclei_rgb_koef
pic_merged_rgb = np.floor(pic_foci_rgb + pic_nucleus_only_rgb).astype(np.uint8)
merged_pic_peaces.append(peace(pic_merged_rgb, cur_cell.coords))
merged_pic = join_peaces_3d(merged_pic_peaces, x_max, y_max, dtype = np.uint8)
return merged_pic
示例5: stretchImageHue
def stretchImageHue(imrgb):
# Image must be stored as 0-1 bound float. If it's 0-255 int, convert
if( imrgb.max() > 1 ):
imrgb = imrgb*1./255
# Transform to HSV
imhsv = rgb2hsv(imrgb)
# Find 2-98 percentiles of H histogram (except de-saturated pixels)
plt.figure()
plt.hist(imhsv[imhsv[:,:,1]>0.1,0].flatten(), bins=360)
p2, p98 = np.percentile(imhsv[imhsv[:,:,1]>0.1,0], (2, 98))
print p2, p98
imhsv[:,:,0] = doStretch(imhsv[:,:,0], p2, p98, 0.6, 0.99)
plt.figure()
plt.hist(imhsv[imhsv[:,:,1]>0.1,0].flatten(), bins=360)
imrgb_stretched = hsv2rgb(imhsv)
plt.figure()
plt.imshow(imrgb)
plt.figure()
plt.imshow(imrgb_stretched)
plt.show()
示例6: color_augment_image
def color_augment_image(data):
image = data.transpose(1, 2, 0)
hsv = color.rgb2hsv(image)
# Contrast 2
s_factor1 = numpy.random.uniform(0.25, 4)
s_factor2 = numpy.random.uniform(0.7, 1.4)
s_factor3 = numpy.random.uniform(-0.1, 0.1)
hsv[:, :, 1] = (hsv[:, :, 1] ** s_factor1) * s_factor2 + s_factor3
v_factor1 = numpy.random.uniform(0.25, 4)
v_factor2 = numpy.random.uniform(0.7, 1.4)
v_factor3 = numpy.random.uniform(-0.1, 0.1)
hsv[:, :, 2] = (hsv[:, :, 2] ** v_factor1) * v_factor2 + v_factor3
# Color
h_factor = numpy.random.uniform(-0.1, 0.1)
hsv[:, :, 0] = hsv[:, :, 0] + h_factor
hsv[hsv < 0] = 0.0
hsv[hsv > 1] = 1.0
rgb = color.hsv2rgb(hsv)
data_out = rgb.transpose(2, 0, 1)
return data_out
示例7: hsi_equalize_hist
def hsi_equalize_hist():
image=data.astronaut()
h=color.rgb2hsv(image)
h[:,:,2]=exposure.equalize_hist(h[:,:,2])
image_equal=color.hsv2rgb(h)
io.imshow(image_equal)
io.imsave('astronautequal.png',image_equal)
示例8: test_hsv2rgb_conversion
def test_hsv2rgb_conversion(self):
rgb = self.img_rgb.astype("float32")[::16, ::16]
# create HSV image with colorsys
hsv = np.array([colorsys.rgb_to_hsv(pt[0], pt[1], pt[2]) for pt in rgb.reshape(-1, 3)]).reshape(rgb.shape)
# convert back to RGB and compare with original.
# relative precision for RGB -> HSV roundtrip is about 1e-6
assert_almost_equal(rgb, hsv2rgb(hsv), decimal=4)
示例9: RDMcolormap
def RDMcolormap(nCols=256):
# blue-cyan-gray-red-yellow with increasing V (BCGRYincV)
anchorCols = np.array([
[0, 0, 1],
[0, 1, 1],
[.5, .5, .5],
[1, 0, 0],
[1, 1, 0],
])
# skimage rgb2hsv is intended for 3d images (RGB)
# here we add a new axis to our 2d anchorCols to satisfy skimage, and then squeeze
anchorCols_hsv = rgb2hsv(anchorCols[np.newaxis, :]).squeeze()
incVweight = 1
anchorCols_hsv[:, 2] = (1-incVweight)*anchorCols_hsv[:, 2] + \
incVweight*np.linspace(0.5, 1, anchorCols.shape[0]).T
# anchorCols = brightness(anchorCols)
anchorCols = hsv2rgb(anchorCols_hsv[np.newaxis, :]).squeeze()
cols = colorScale(nCols, anchorCols)
return ListedColormap(cols)
示例10: _process
def _process(self, img):
hsv = rgb2hsv(img)
h = hsv[:, :, 0] + self._adjust
h[h > 1] -= 1
hsv[:, :, 0] = h
img[:, :, :] = hsv2rgb(hsv)
return img
示例11: saturate
def saturate(im, amount=1.1):
hsvim = skcolor.rgb2hsv(im)
hue = np.take(hsvim, 0, axis=2)
sat = np.take(hsvim, 1, axis=2)
val = np.take(hsvim, 2, axis=2)
# sat = sat * amount
newhsv = np.dstack((hue, sat, val))
return skcolor.hsv2rgb(newhsv)
示例12: main
def main():
# read the images
image_from = io.imread(name_from) / 256
image_to = io.imread(name_to) / 256
# change to hsv domain (if requested)
if args.use_hsv:
image_from[:] = rgb2hsv(image_from)
image_to[:] = rgb2hsv(image_to)
# get shapes
shape_from = image_from.shape
shape_to = image_to.shape
# flatten
X_from = im2mat(image_from)
X_to = im2mat(image_to)
# number of pixes
n_pixels_from = X_from.shape[0]
n_pixels_to = X_to.shape[0]
# subsample
X_from_ss = X_from[np.random.randint(0, n_pixels_from-1, n_pixels),:]
X_to_ss = X_to[np.random.randint(0, n_pixels_to-1, n_pixels),:]
if save_col_distribution:
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('white')
fig, axes = plt.subplots(nrows=2, figsize=(5, 10))
for ax, X in zip(axes, [X_from_ss, X_to_ss]):
ax.scatter(X[:,0], X[:,1], color=X)
if args.use_hsv:
ax.set_xhsvel('hue')
ax.set_yhsvel('value')
else:
ax.set_xhsvel('red')
ax.set_yhsvel('green')
axes[0].set_title('distr. from')
axes[1].set_title('distr. to')
fig.tight_layout()
fig.savefig('color_distributions.png')
# optimal tranportation
ot_color = OptimalTransport(X_to_ss, X_from_ss, lam=lam,
distance_metric=distance_metric)
# model transfer
transfer_model = KNeighborsRegressor(n_neighbors=n_neighbors)
transfer_model.fit(X_to_ss, n_pixels * ot_color.P @ X_from_ss)
X_transfered = transfer_model.predict(X_to)
image_transferd = minmax(mat2im(X_transfered, shape_to))
if args.use_hsv:
image_transferd[:] = hsv2rgb(image_transferd)
io.imsave(name_out, image_transferd)
示例13: _rotate_Scale_fired
def _rotate_Scale_fired(self):
"""" _rotate_Scale_fired(self): rotates scale and re-displays image when button is pressed """
max = 255. # this will only work with certain image types...
hsvimage = rgb2hsv([x/max for x in self.image])
hsvimage[:,:,1] = [np.mod(x+0.5,1) for x in hsvimage[:,:,1]]
hsvimage = [np.uint8(x*max) for x in hsv2rgb(hsvimage)]
self.image = hsvimage
self.ax.imshow(hsvimage)
self.figure.canvas.draw()
示例14: _rotate_Hue_fired
def _rotate_Hue_fired(self):
"""" _rotate_Hue_fired(self): rotates hue and re-displays image when button is pressed """
max = 255.
hsvimage = rgb2hsv([x/max for x in self.image])
hsvimage[:,:,0] = [np.mod(x+0.5,1) for x in hsvimage[:,:,0]]
hsvimage = [np.uint8(x*max) for x in hsv2rgb(hsvimage)]
self.image = hsvimage
self.ax.imshow(hsvimage)
self.figure.canvas.draw()
示例15: colorize
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)