本文整理汇总了Python中skimage.color.rgb2hsv方法的典型用法代码示例。如果您正苦于以下问题:Python color.rgb2hsv方法的具体用法?Python color.rgb2hsv怎么用?Python color.rgb2hsv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.color
的用法示例。
在下文中一共展示了color.rgb2hsv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _transform
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def _transform(self, filename):
try:
image = misc.imread(filename)
if len(image.shape) < 3: # make sure images are of shape(h,w,3)
image = np.array([image for i in range(3)])
if self.image_options.get("resize", False) and self.image_options["resize"]:
resize_size = int(self.image_options["resize_size"])
resize_image = misc.imresize(image,
[resize_size, resize_size])
else:
resize_image = image
if self.image_options.get("color", False):
option = self.image_options['color']
if option == "LAB":
resize_image = color.rgb2lab(resize_image)
elif option == "HSV":
resize_image = color.rgb2hsv(resize_image)
except:
print ("Error reading file: %s of shape %s" % (filename, str(image.shape)))
raise
return np.array(resize_image)
示例2: get_masked_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def get_masked_image(img, mask, multiplier=0.6):
"""
:param img: The image to be masked.
:param mask: Binary mask to be applied. The object should be represented by 1 and the background by 0
:param multiplier: Floating point multiplier that decides the colour of the mask.
:return: Masked image
"""
img_mask = np.zeros_like(img)
indices = np.where(mask == 1)
img_mask[indices[0], indices[1], 1] = 1
img_mask_hsv = color.rgb2hsv(img_mask)
img_hsv = color.rgb2hsv(img)
img_hsv[indices[0], indices[1], 0] = img_mask_hsv[indices[0], indices[1], 0]
img_hsv[indices[0], indices[1], 1] = img_mask_hsv[indices[0], indices[1], 1] * multiplier
return color.hsv2rgb(img_hsv)
示例3: run
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def run(args):
logging.basicConfig(level=logging.INFO)
slide = openslide.OpenSlide(args.wsi_path)
# note the shape of img_RGB is the transpose of slide.level_dimensions
img_RGB = np.transpose(np.array(slide.read_region((0, 0),
args.level,
slide.level_dimensions[args.level]).convert('RGB')),
axes=[1, 0, 2])
img_HSV = rgb2hsv(img_RGB)
background_R = img_RGB[:, :, 0] > threshold_otsu(img_RGB[:, :, 0])
background_G = img_RGB[:, :, 1] > threshold_otsu(img_RGB[:, :, 1])
background_B = img_RGB[:, :, 2] > threshold_otsu(img_RGB[:, :, 2])
tissue_RGB = np.logical_not(background_R & background_G & background_B)
tissue_S = img_HSV[:, :, 1] > threshold_otsu(img_HSV[:, :, 1])
min_R = img_RGB[:, :, 0] > args.RGB_min
min_G = img_RGB[:, :, 1] > args.RGB_min
min_B = img_RGB[:, :, 2] > args.RGB_min
tissue_mask = tissue_S & tissue_RGB & min_R & min_G & min_B
np.save(args.npy_path, tissue_mask)
示例4: _apply_
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def _apply_(self, *image):
res = ()
n_img = 0
for img in image:
if n_img == 0:
#pdb.set_trace()
### transform image into HSV
img = img_as_ubyte(color.rgb2hsv(img))
### perturbe each channel H, E, Dab
for i in range(3):
k_i = self.params['k'][i]
b_i = self.params['b'][i]
img[:,:,i] = GreyValuePerturbation(img[:, :, i], k_i, b_i, MIN=0., MAX=255)
#plt.imshow(img[:,:,i], "gray")
#plt.show()
sub_res = img_as_ubyte(color.hsv2rgb(img))
else:
sub_res = img
res += (sub_res,)
n_img += 1
return res
示例5: masked
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def masked(img, gt, mask, alpha=1):
"""Returns image with GT lung field outlined with red, predicted lung field
filled with blue."""
rows, cols = img.shape[:2]
color_mask = np.zeros((rows, cols, 3))
boundary = morphology.dilation(gt, morphology.disk(3)) ^ gt
color_mask[mask == 1] = [0, 0, 1]
color_mask[boundary == 1] = [1, 0, 0]
img_hsv = color.rgb2hsv(img)
color_mask_hsv = color.rgb2hsv(color_mask)
img_hsv[..., 0] = color_mask_hsv[..., 0]
img_hsv[..., 1] = color_mask_hsv[..., 1] * alpha
img_masked = color.hsv2rgb(img_hsv)
return img_masked
示例6: RDMcolormap
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
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)
示例7: get_masked_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def get_masked_image(img, mask, multiplier=0.6):
"""
:param img: The image to be masked.
:param mask: Binary mask to be applied. The object should be represented by 1 and the background by 0
:param multiplier: Floating point multiplier that decides the colour of the mask.
:return: Masked image
"""
img_mask = np.zeros_like(img)
indices = np.where(mask == 1)
img_mask[indices[0], indices[1], 1] = 1
img_mask_hsv = color.rgb2hsv(img_mask)
img_hsv = color.rgb2hsv(img)
img_hsv[indices[0], indices[1], 0] = img_mask_hsv[indices[0], indices[1], 0]
img_hsv[indices[0], indices[1], 1] = img_mask_hsv[indices[0], indices[1], 1] * multiplier
return color.hsv2rgb(img_hsv)
# Visualize spatial offset in HSV color space as rotation to spatial center (H),
# distance to spatial center (V)
示例8: masked
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def masked(img, gt, mask, alpha=1):
"""Returns image with GT lung field outlined with red, predicted lung field
filled with blue."""
rows, cols = img.shape
color_mask = np.zeros((rows, cols, 3))
boundary = morphology.dilation(gt, morphology.disk(3)) - gt
color_mask[mask == 1] = [0, 0, 1]
color_mask[boundary == 1] = [1, 0, 0]
img_color = np.dstack((img, img, img))
img_hsv = color.rgb2hsv(img_color)
color_mask_hsv = color.rgb2hsv(color_mask)
img_hsv[..., 0] = color_mask_hsv[..., 0]
img_hsv[..., 1] = color_mask_hsv[..., 1] * alpha
img_masked = color.hsv2rgb(img_hsv)
return img_masked
示例9: __call__
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def __call__(self, img):
if self.color_space == 'rgb':
return (img * 2 - 1.)
img = img.permute(1, 2, 0) # to [H, W, 3]
if self.color_space == 'lab':
img = color.rgb2lab(img) # [0~100, -128~127, -128~127]
img[:,:,0] = (img[:,:,0] - 50.0) * (1 / 50.)
img[:,:,1] = (img[:,:,1] + 0.5) * (1 / 127.5)
img[:,:,2] = (img[:,:,2] + 0.5) * (1 / 127.5)
elif self.color_space == 'hsv':
img = color.rgb2hsv(img) # [0~1, 0~1, 0~1]
img = (img * 2 - 1)
# to [3, H, W]
return torch.from_numpy(img).float().permute(2, 0, 1) # [-1~1, -1~1, -1~1]
示例10: forward
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def forward(self, bottom, top):
for nn in range(self.N):
top[0].data[nn, :, :, :] = color.rgb2hsv(bottom[0].data[nn, ::-1, :, :].astype('uint8').transpose((1, 2, 0))).transpose((2, 0, 1))
示例11: brightness
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def brightness(_x, c=0.):
_x = np.array(_x, copy=True) / 255.
_x = skcolor.rgb2hsv(_x)
_x[:, :, 2] = np.clip(_x[:, :, 2] + c, 0, 1)
_x = skcolor.hsv2rgb(_x)
return np.uint8(_x * 255)
示例12: get_overlayed_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def get_overlayed_image(x, c, gray_factor_bg = 0.3):
'''
For an image x and a relevance vector c, overlay the image with the
relevance vector to visualise the influence of the image pixels.
'''
imDim = x.shape[0]
if np.ndim(c)==1:
c = c.reshape((imDim,imDim))
if np.ndim(x)==2: # this happens with the MNIST Data
x = 1-np.dstack((x, x, x))*gray_factor_bg # make it a bit grayish
if np.ndim(x)==3: # this is what happens with cifar data
x = color.rgb2gray(x)
x = 1-(1-x)*0.5
x = np.dstack((x,x,x))
alpha = 0.8
# Construct a colour image to superimpose
im = plt.imshow(c, cmap = cm.seismic, vmin=-np.max(np.abs(c)), vmax=np.max(np.abs(c)), interpolation='nearest')
color_mask = im.to_rgba(c)[:,:,[0,1,2]]
# Convert the input image and color mask to Hue Saturation Value (HSV) colorspace
img_hsv = color.rgb2hsv(x)
color_mask_hsv = color.rgb2hsv(color_mask)
# Replace the hue and saturation of the original image
# with that of the color mask
img_hsv[..., 0] = color_mask_hsv[..., 0]
img_hsv[..., 1] = color_mask_hsv[..., 1] * alpha
img_masked = color.hsv2rgb(img_hsv)
return img_masked
示例13: original_colors
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def original_colors(original, stylized,original_color):
# Histogram normalization in v channel
ratio=1. - original_color
hsv = color.rgb2hsv(original/255)
hsv_s = color.rgb2hsv(stylized/255)
hsv_s[:,:,2] = (ratio* hsv_s[:,:,2]) + (1-ratio)*hsv [:,:,2]
img = color.hsv2rgb(hsv_s)
return img
示例14: TF_shift_hue
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
def TF_shift_hue(x, shift=0.0):
assert len(x.shape) == 3
h, w, nc = x.shape
hsv = rgb2hsv(x)
hsv[:,:,0] += shift
return hsv2rgb(hsv)
示例15: color_augment_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2hsv [as 别名]
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