本文整理汇总了Python中matplotlib.colors.rgb_to_hsv函数的典型用法代码示例。如果您正苦于以下问题:Python rgb_to_hsv函数的具体用法?Python rgb_to_hsv怎么用?Python rgb_to_hsv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rgb_to_hsv函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: remove_noise_with_hsv
def remove_noise_with_hsv(self, img):
# Use number of occurrences to find the standard h, s, v
# Convert to int so we can sort the colors
# noinspection PyTypeChecker
img_int = np.dot(np.rint(img * 255), np.power(256, np.arange(3)))
color_array = sort_by_occurrence(img_int.flatten())
# standard color is the 2nd most frequent color
std_color = color_array[1]
std_b, mod = divmod(std_color, 256 ** 2)
std_g, std_r = divmod(mod, 256)
# noinspection PyTypeChecker
std_h, std_s, std_v = colors.rgb_to_hsv(np.array([std_r, std_g, std_b]) / 255)
# print(std_h * 360, std_s * 100, std_v * 100)
height, width, _ = img.shape
img_hsv = colors.rgb_to_hsv(img)
h, s, v = img_hsv[:, :, 0], img_hsv[:, :, 1], img_hsv[:, :, 2]
h_mask = np.abs(h - std_h) > self.h_tolerance
s_mask = np.abs(s - std_s) > self.s_tolerance
delta_v = np.abs(v - std_v)
v_mask = delta_v > self.v_tolerance
hsv_mask = np.logical_or(np.logical_or(h_mask, s_mask), v_mask)
new_img = 1 - delta_v
new_img[hsv_mask] = 0
# Three types of grayscale colors in new_img:
# Type A: 1. Outside noise, or inside point.
# Type B: between 0 and 1. Outside noise, or contour point.
# Type C: 0. Inside noise, or background.
return new_img
开发者ID:clcarwin,项目名称:bilibili-captcha,代码行数:28,代码来源:captcha_recognizer.py
示例2: generate_color_range
def generate_color_range(self):
# color and marker range:
self.colorrange = []
self.markerrange = []
mr2 = []
# first color range:
cc0 = plt.cm.gist_rainbow(np.linspace(0.0, 1.0, 8.0))
# shuffle it:
for k in range((len(cc0) + 1) // 2):
self.colorrange.extend(cc0[k::(len(cc0) + 1) // 2])
self.markerrange.extend(len(cc0) * 'o')
mr2.extend(len(cc0) * 'v')
# second darker color range:
cc1 = plt.cm.gist_rainbow(np.linspace(0.33 / 7.0, 1.0, 7.0))
cc1 = mc.hsv_to_rgb(mc.rgb_to_hsv(np.array([cc1])) * np.array([1.0, 0.9, 0.7, 0.0]))[0]
cc1[:, 3] = 1.0
# shuffle it:
for k in range((len(cc1) + 1) // 2):
self.colorrange.extend(cc1[k::(len(cc1) + 1) // 2])
self.markerrange.extend(len(cc1) * '^')
mr2.extend(len(cc1) * '*')
# third lighter color range:
cc2 = plt.cm.gist_rainbow(np.linspace(0.67 / 6.0, 1.0, 6.0))
cc2 = mc.hsv_to_rgb(mc.rgb_to_hsv(np.array([cc2])) * np.array([1.0, 0.5, 1.0, 0.0]))[0]
cc2[:, 3] = 1.0
# shuffle it:
for k in range((len(cc2) + 1) // 2):
self.colorrange.extend(cc2[k::(len(cc2) + 1) // 2])
self.markerrange.extend(len(cc2) * 'D')
mr2.extend(len(cc2) * 'x')
self.markerrange.extend(mr2)
开发者ID:jfsehuanes,项目名称:thunderfish,代码行数:31,代码来源:fishfinder.py
示例3: test_rgb_hsv_round_trip
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)))
开发者ID:bastibe,项目名称:matplotlib,代码行数:8,代码来源:test_colors.py
示例4: test2
def test2(dicLoc):
itemCollection = pickle.load(open('itemCollection',"rb"))
bagTypes = itemCollection.getBagTypes()
for image in bagTypes['silver']:
img = scipy.misc.imread(image.getFullImageLocation())
array=np.asarray(img)
arr=(array.astype(float))/255.0
img_hsv = colors.rgb_to_hsv(arr[...,:3])
lu1=img_hsv[...,0].flatten()
plt.subplot(1,3,1)
plt.hist(lu1*360,bins=10,range=(0.0,360.0),histtype='stepfilled', color='r', label='Hue')
plt.title("Hue")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
lu2=img_hsv[...,1].flatten()
plt.subplot(1,3,2)
plt.hist(lu2,bins=10,range=(0.0,1.0),histtype='stepfilled', color='g', label='Saturation')
plt.title("Saturation")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
lu3=img_hsv[...,2].flatten()
plt.subplot(1,3,3)
plt.hist(lu3*255,bins=10,range=(0.0,255.0),histtype='stepfilled', color='b', label='Intesity')
plt.title("Intensity")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
plt.show()
开发者ID:testing32,项目名称:unsuper_bag_analysis,代码行数:34,代码来源:hw2.py
示例5: get_color_range
def get_color_range(n):
colors = mcolors.TABLEAU_COLORS
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
for name, color in colors.items())
sorted_names = [name for hsv, name in by_hsv]
delta = int(len(sorted_names)/n)
return sorted_names[::delta]
开发者ID:NazBen,项目名称:impact-of-dependence,代码行数:7,代码来源:plots.py
示例6: abrir_imagen
def abrir_imagen(self, widget):
img = None
fc = gtk.FileChooserDialog(title='Abrir imagen...', parent=None, action=gtk.FILE_CHOOSER_ACTION_OPEN,
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
fc.set_default_response(gtk.RESPONSE_OK)
respuesta = fc.run()
if respuesta == gtk.RESPONSE_OK:
self.nombre_archivo = fc.get_filename()
ext = self.nombre_archivo[-4:]
if ext == ".jpg":
img = Image.open(self.nombre_archivo)
self.imagen = numpy.asarray(img,dtype=numpy.float64)
if len(self.imagen.shape) == 3: # si es a color
self.imagen_color = c.rgb_to_hsv(self.imagen)
self.imagen = self.imagen_color[:,:,2]
self.imagen = self.imagen.astype(numpy.uint8)
self.color = True
else:
self.color = False
else:
self.imagen = self.switch_ext(ext)
self.dibujar_img(self.imagen)
self.historial = []
self.historial_color = []
self.indice_historial = -1
self.actualiza_historial()
fc.destroy()
开发者ID:jluisacosta,项目名称:Image-Editor,代码行数:29,代码来源:main.py
示例7: main
def main():
from scipy import ndimage
from matplotlib import colors
image = ndimage.imread('../../../heavy/raspberry.jpg')
image = colors.rgb_to_hsv(image)
height = image.shape[0]
width = image.shape[1]
hue = image[:, :, 0]
saturation = image[:, :, 1]
value = image[:, :, 2]
analyzer = Analyzer(width, height)
from PIL import Image, ImageEnhance
output = Image.open('../../../heavy/raspberry.jpg')
converter = ImageEnhance.Color(output)
output = converter.enhance(0)
prepared = analyzer.prepare(saturation, value)
for target in HUES:
x, y, angle, r = analyzer.analyze(hue, saturation, value, target, prepared)
if r != 0:
render(output, target, x, y, angle, r)
output.save('output.png')
开发者ID:BenWiederhake,项目名称:emsys,代码行数:31,代码来源:detector.py
示例8: sorted_color_maps
def sorted_color_maps():
'''List of color name and their hex values sorted by HSV.
This code is taken from:
http://matplotlib.org/examples/color/named_colors.html
'''
colors_ = list(six.iteritems(colors.cnames))
# Add the single letter colors.
for name, rgb in six.iteritems(colors.ColorConverter.colors):
hex_ = colors.rgb2hex(rgb)
colors_.append((name, hex_))
# Transform to hex color values.
hex_ = [color[1] for color in colors_]
# Get the rgb equivalent.
rgb = [colors.hex2color(color) for color in hex_]
# Get the hsv equivalent.
hsv = [colors.rgb_to_hsv(color) for color in rgb]
# Split the hsv values to sort.
hue = [color[0] for color in hsv]
sat = [color[1] for color in hsv]
val = [color[2] for color in hsv]
# Sort by hue, saturation and value.
ind = np.lexsort((val, sat, hue))
sorted_colors = [colors_[i] for i in ind]
sorted_colors = [
c_1
for (c_1, c_2) in zip(sorted_colors[:-1], sorted_colors[1:])
if c_1[1] != c_2[1]]
return sorted_colors
开发者ID:chaobin,项目名称:isaac,代码行数:33,代码来源:basic.py
示例9: shadow_filter
def shadow_filter(image, dpi):
"""This filter creates a metallic look on patches.
image : the image of the patch
dpi : the resultion of the patch"""
# Get the shape of the image
nx, ny, depth = image.shape
# Create a mash grid
xx, yy = np.mgrid[0:nx, 0:ny]
# Draw a circular "shadow"
circle = (xx + nx * 4) ** 2 + (yy + ny) ** 2
# Normalize
circle -= circle.min()
circle = circle / circle.max()
# Steepness
value = circle.clip(0.3, 0.6) + 0.4
saturation = 1 - circle.clip(0.7, 0.8)
# Normalize
saturation -= saturation.min() - 0.1
saturation = saturation / saturation.max()
# Convert the rgb part (without alpha) to hsv
hsv = mc.rgb_to_hsv(image[:, :, :3])
# Multiply the value of hsv image with the shadow
hsv[:, :, 2] = hsv[:, :, 2] * value
# Highlights with saturation
hsv[:, :, 1] = hsv[:, :, 1] * saturation
# Copy the hsv back into the image (we haven't touched alpha)
image[:, :, :3] = mc.hsv_to_rgb(hsv)
# the return values are: new_image, offset_x, offset_y
return image, 0, 0
开发者ID:TRiedling,项目名称:adsy-python,代码行数:30,代码来源:plotenhance.py
示例10: rgb_to_greyscale
def rgb_to_greyscale(dataset_rgb):
"""
Convert each image in the given dataset to greyscale.
The dataset used in the model uses this specific shape:
[channels, hight, width]
it has to be changed as the rgb_to_hsv function needs this shape:
[hight, width, channels]
The new greyscale image is stored in a new array only using the last
value of the hsv array.
This new array has to be reshaped to meet the original criteria
of the model.
"""
dataset_grey = np.zeros((dataset_rgb.shape[0], 1,
dataset_rgb.shape[2], dataset_rgb.shape[3]))
for i in range(len(dataset_rgb)):
img_rgb = np.swapaxes(dataset_rgb[i], 0, 2)
img_hsv = colors.rgb_to_hsv(img_rgb)
img_grey = np.zeros((img_hsv.shape[0], img_hsv.shape[1]))
for x in range(len(img_hsv)):
for y in range(len(img_hsv[x])):
img_grey[x][y] = img_hsv[x][y][2:]
# plt.imshow(img_grey, cmap=cm.Greys_r)
# plt.show()
img_grey = img_grey.reshape(32, 32, 1)
img_grey = np.swapaxes(img_grey, 2, 0)
dataset_grey[i] = img_grey
return dataset_grey
开发者ID:andreashdez,项目名称:ConvolutionalNeuralNetwork,代码行数:30,代码来源:cnn_cifar10.py
示例11: Detect_laser
def Detect_laser(image):
hsv= col.rgb_to_hsv((image/255.0))
laser = np.zeros(image.shape[:2])
for i in range(150,450):
for j in range(260,640):
if hsv[i,j,1]<0.25 and hsv[i,j,2]>0.85:
laser[i,j] = 1
return laser
开发者ID:elekhac,项目名称:Projet_Polype,代码行数:8,代码来源:Fonctions_Analyse_Hough.py
示例12: rgb_to_hsv_tuple
def rgb_to_hsv_tuple(rgb_tuple):
"""
Convert 3 tuple that represents a RGB color (values between 0..1)
to a 3 tuple in HSV color space.
If you have an array of color values use: ``matplotlib.colors.rgb_to_hsv``.
"""
colarr = rgb_to_hsv(np.array([[rgb_tuple]]))
return tuple(colarr[0, 0, :])
开发者ID:eike-welk,项目名称:clair,代码行数:8,代码来源:diagram.py
示例13: __init__
def __init__(self, imageRGB):
self.imageRGB = imageRGB.copy()
self.imageHSV = colors.rgb_to_hsv(self.imageRGB)
self.imageHeight = self.imageRGB.shape[0]
self.imageWidth = self.imageRGB.shape[1]
self.segmentedRGB = None
self.segmentedHSV = None
self.computationTime = None
开发者ID:svenzel,项目名称:DrawBN,代码行数:8,代码来源:segmentation.py
示例14: extract_hue
def extract_hue(infile):
"""
Returns a hue greyscale image from an rgb image.
"""
rgb_image = imread(infile)
hsv_image = rgb_to_hsv(rgb_image)
hue_image = -hsv_image[:,:,0]
imsave(fname='%s-hue.png' %(infile.split('.')[0]),arr=hue_image,cmap='gray')
开发者ID:Larothus,项目名称:ToolBox,代码行数:8,代码来源:img_tools.py
示例15: Detect_laser
def Detect_laser(image):
hsv= col.rgb_to_hsv((image/255.0))
laser = np.zeros(image.shape[:2])
for i in range(150,450):
for j in range(260,640):
if hsv[i,j,1]<0.25 and hsv[i,j,2]>0.85:
laser[i,j] = 1
open_laser = cv2.morphologyEx(laser, cv2.MORPH_OPEN, disk(2))
return open_laser
开发者ID:elekhac,项目名称:Projet_Polype,代码行数:9,代码来源:laser_on_polyp.py
示例16: Detect_laser
def Detect_laser(image):
hsv= col.rgb_to_hsv((image/255.0))
laser = np.zeros(image.shape[:2])
for i in range(laser.shape[0]):
for j in range(laser.shape[1]):
if hsv[i,j,0] < 0.5 and hsv[i,j,2]> 0.6:
laser[i,j] = 1
open_laser = laser
return open_laser
开发者ID:elekhac,项目名称:Projet_Polype,代码行数:10,代码来源:Detecte_laser.py
示例17: open_hsv
def open_hsv(fname, size=(256,256)):
img = Image.open(fname)
img.thumbnail(size)
ary = np.asarray(img)/255.0
# xform to hsv
if just_rgb:
hsv = ary
else:
hsv = rgb_to_hsv(ary)
return hsv
开发者ID:schimfim,项目名称:palettes,代码行数:10,代码来源:np1d.py
示例18: Detect_laser
def Detect_laser(image):
hsv= col.rgb_to_hsv((image/255.0))
laser = np.zeros(image.shape[:2])
target=0.29 #green
seuil=0.05
for i in range(laser.shape[0]):
for j in range(laser.shape[1]):
if abs(hsv[i,j,0] - target) < seuil and hsv[i,j,1]>0.2 and hsv[i,j,2]>0.1:
laser[i,j] = 1
return laser
开发者ID:elekhac,项目名称:Projet_Polype,代码行数:11,代码来源:Fonctions_Analyse.py
示例19: get_color_scheme
def get_color_scheme(base_color, num=4, spread=1.):
""" Distributes num colors around the color wheel starting with a base
color and converting the fraction `spread` of the circle """
base_rgb = mclr.colorConverter.to_rgb(base_color)
base_rgb = np.reshape(np.array(base_rgb), (1, 1, 3))
base_hsv = mclr.rgb_to_hsv(base_rgb)[0, 0]
res_hsv = np.array([[
((base_hsv[0] + dh) % 1., base_hsv[1], base_hsv[2])
for dh in np.linspace(-0.5*spread, 0.5*spread, num, endpoint=False)
]])
return mclr.hsv_to_rgb(res_hsv)[0]
开发者ID:drat,项目名称:python-functions,代码行数:11,代码来源:plotting_functions.py
示例20: create_brightness_colormap
def create_brightness_colormap(self,principal_rgb_color, scale_size):
'''
Create brightness colormap based on one principal RGB color
'''
if np.any(principal_rgb_color > 1):
raise Exception('principal_rgb_color values should be in range [0,1]')
hsv_color = colors.rgb_to_hsv(principal_rgb_color)
hsv_colormap = np.concatenate((np.tile(hsv_color[:-1][None, :], (scale_size, 1))[:],
np.linspace(0, 1, scale_size)[:, None]),
axis=1)
self.colormap=self.array2cmap(colors.hsv_to_rgb(hsv_colormap))
开发者ID:VasLem,项目名称:ProjectionPainting,代码行数:11,代码来源:hist4d.py
注:本文中的matplotlib.colors.rgb_to_hsv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论