本文整理匯總了Python中torchvision.transforms.functional.adjust_hue方法的典型用法代碼示例。如果您正苦於以下問題:Python functional.adjust_hue方法的具體用法?Python functional.adjust_hue怎麽用?Python functional.adjust_hue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchvision.transforms.functional
的用法示例。
在下文中一共展示了functional.adjust_hue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cv_transform
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def cv_transform(img):
# img = resize(img, size=(100, 300))
# img = to_tensor(img)
# img = normalize(img, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
# img = pad(img, padding=(10, 10, 20, 20), fill=(255, 255, 255), padding_mode='constant')
# img = pad(img, padding=(100, 100, 100, 100), fill=5, padding_mode='symmetric')
# img = crop(img, -40, -20, 1000, 1000)
# img = center_crop(img, (310, 300))
# img = resized_crop(img, -10.3, -20, 330, 220, (500, 500))
# img = hflip(img)
# img = vflip(img)
# tl, tr, bl, br, center = five_crop(img, 100)
# img = adjust_brightness(img, 2.1)
# img = adjust_contrast(img, 1.5)
# img = adjust_saturation(img, 2.3)
# img = adjust_hue(img, 0.5)
# img = adjust_gamma(img, gamma=3, gain=0.1)
# img = rotate(img, 10, resample='BILINEAR', expand=True, center=None)
# img = to_grayscale(img, 3)
# img = affine(img, 10, (0, 0), 1, 0, resample='BICUBIC', fillcolor=(255,255,0))
# img = gaussion_noise(img)
# img = poisson_noise(img)
img = salt_and_pepper(img)
return to_tensor(img)
示例2: pil_transform
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def pil_transform(img):
# img = functional.resize(img, size=(100, 300))
# img = functional.to_tensor(img)
# img = functional.normalize(img, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
# img = functional.pad(img, padding=(10, 10, 20, 20), fill=(255, 255, 255), padding_mode='constant')
# img = functional.pad(img, padding=(100, 100, 100, 100), padding_mode='symmetric')
# img = functional.crop(img, -40, -20, 1000, 1000)
# img = functional.center_crop(img, (310, 300))
# img = functional.resized_crop(img, -10.3, -20, 330, 220, (500, 500))
# img = functional.hflip(img)
# img = functional.vflip(img)
# tl, tr, bl, br, center = functional.five_crop(img, 100)
# img = functional.adjust_brightness(img, 2.1)
# img = functional.adjust_contrast(img, 1.5)
# img = functional.adjust_saturation(img, 2.3)
# img = functional.adjust_hue(img, 0.5)
# img = functional.adjust_gamma(img, gamma=3, gain=0.1)
# img = functional.rotate(img, 10, resample=PIL.Image.BILINEAR, expand=True, center=None)
# img = functional.to_grayscale(img, 3)
# img = functional.affine(img, 10, (0, 0), 1, 0, resample=PIL.Image.BICUBIC, fillcolor=(255,255,0))
return functional.to_tensor(img)
示例3: __call__
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def __call__(self, inputs, disps):
inputs = [Image.fromarray(np.uint8(inp)) for inp in inputs]
if self.brightness > 0:
brightness_factor = np.random.uniform(max(0, 1 - self.brightness), 1 + self.brightness)
inputs = [F.adjust_brightness(inp, brightness_factor) for inp in inputs]
if self.contrast > 0:
contrast_factor = np.random.uniform(max(0, 1 - self.contrast), 1 + self.contrast)
inputs = [F.adjust_contrast(inp, contrast_factor) for inp in inputs]
if self.saturation > 0:
saturation_factor = np.random.uniform(max(0, 1 - self.saturation), 1 + self.saturation)
inputs = [F.adjust_saturation(inp, saturation_factor) for inp in inputs]
if self.hue > 0:
hue_factor = np.random.uniform(-self.hue, self.hue)
inputs = [F.adjust_hue(inp, hue_factor) for inp in inputs]
inputs = [np.asarray(inp) for inp in inputs]
inputs = [inp.clip(0,255) for inp in inputs]
return inputs, disps
示例4: get_params
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def get_params(brightness, contrast, saturation, hue):
transforms = []
if brightness is not None:
brightness_factor = random.uniform(brightness[0], brightness[1])
transforms.append(Lambda_image(lambda img: F.adjust_brightness(img, brightness_factor)))
if contrast is not None:
contrast_factor = random.uniform(contrast[0], contrast[1])
transforms.append(Lambda_image(lambda img: F.adjust_contrast(img, contrast_factor)))
if saturation is not None:
saturation_factor = random.uniform(saturation[0], saturation[1])
transforms.append(Lambda_image(lambda img: F.adjust_saturation(img, saturation_factor)))
if hue is not None:
hue_factor = random.uniform(hue[0], hue[1])
transforms.append(Lambda_image(lambda img: F.adjust_hue(img, hue_factor)))
random.shuffle(transforms)
transform = Compose(transforms)
return transform
示例5: get_params
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def get_params(brightness, contrast, saturation, hue):
"""Get a randomized transform to be applied on image.
Arguments are same as that of __init__.
Returns:
Transform which randomly adjusts brightness, contrast and
saturation in a random order.
"""
transforms = []
if brightness > 0:
brightness_factor = random.uniform(max(0, 1 - brightness), 1 + brightness)
transforms.append(lambda img: F.adjust_brightness(img, brightness_factor))
if contrast > 0:
contrast_factor = random.uniform(max(0, 1 - contrast), 1 + contrast)
transforms.append(lambda img: F.adjust_contrast(img, contrast_factor))
if saturation > 0:
saturation_factor = random.uniform(max(0, 1 - saturation), 1 + saturation)
transforms.append(lambda img: F.adjust_saturation(img, saturation_factor))
if hue > 0:
hue_factor = random.uniform(-hue, hue)
transforms.append(lambda img: F.adjust_hue(img, hue_factor))
random.shuffle(transforms)
return transforms
示例6: photometric_distort
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def photometric_distort(image):
"""
Distort brightness, contrast, saturation, and hue, each with a 50% chance, in random order.
:param image: image, a PIL Image
:return: distorted image
"""
new_image = image
distortions = [FT.adjust_brightness,
FT.adjust_contrast,
FT.adjust_saturation,
FT.adjust_hue]
random.shuffle(distortions)
for d in distortions:
if random.random() < 0.5:
if d.__name__ is 'adjust_hue':
# Caffe repo uses a 'hue_delta' of 18 - we divide by 255 because PyTorch needs a normalized value
adjust_factor = random.uniform(-18 / 255., 18 / 255.)
else:
# Caffe repo uses 'lower' and 'upper' values of 0.5 and 1.5 for brightness, contrast, and saturation
adjust_factor = random.uniform(0.5, 1.5)
# Apply this distortion
new_image = d(new_image, adjust_factor)
return new_image
示例7: get_params
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def get_params(brightness, contrast, saturation, hue):
"""Get a randomized transform to be applied on image.
Arguments are same as that of __init__.
Returns:
Transform which randomly adjusts brightness, contrast and
saturation in a random order.
"""
transforms = []
if brightness is not None:
brightness_factor = random.uniform(brightness[0], brightness[1])
transforms.append(torchvision.transforms.Lambda(lambda img: F.adjust_brightness(img, brightness_factor)))
if contrast is not None:
contrast_factor = random.uniform(contrast[0], contrast[1])
transforms.append(torchvision.transforms.Lambda(lambda img: F.adjust_contrast(img, contrast_factor)))
if saturation is not None:
saturation_factor = random.uniform(saturation[0], saturation[1])
transforms.append(torchvision.transforms.Lambda(lambda img: F.adjust_saturation(img, saturation_factor)))
if hue is not None:
hue_factor = random.uniform(hue[0], hue[1])
transforms.append(torchvision.transforms.Lambda(lambda img: F.adjust_hue(img, hue_factor)))
random.shuffle(transforms)
transform = torchvision.transforms.Compose(transforms)
return transform
示例8: adjust_hue
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def adjust_hue(img, hue_factor):
"""Adjust hue of an image.
The image hue is adjusted by converting the image to HSV and
cyclically shifting the intensities in the hue channel (H).
The image is then converted back to original image mode.
`hue_factor` is the amount of shift in H channel and must be in the
interval `[-0.5, 0.5]`.
See https://en.wikipedia.org/wiki/Hue for more details on Hue.
Args:
img (np.ndarray): CV Image to be adjusted.
hue_factor (float): How much to shift the hue channel. Should be in
[-0.5, 0.5]. 0.5 and -0.5 give complete reversal of hue channel in
HSV space in positive and negative direction respectively.
0 means no shift. Therefore, both -0.5 and 0.5 will give an image
with complementary colors while 0 gives the original image.
Returns:
np.ndarray: Hue adjusted image.
"""
if not(-0.5 <= hue_factor <= 0.5):
raise ValueError('hue_factor is not in [-0.5, 0.5].'.format(hue_factor))
if not _is_numpy_image(img):
raise TypeError('img should be CV Image. Got {}'.format(type(img)))
im = img.astype(np.uint8)
hsv = cv2.cvtColor(im, cv2.COLOR_RGB2HSV_FULL)
hsv[..., 0] += np.uint8(hue_factor * 255)
im = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB_FULL)
return im.astype(img.dtype)
示例9: __call__
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def __call__(self, seq_blur, seq_clear):
seq_blur = [Image.fromarray(np.uint8(img)) for img in seq_blur]
seq_clear = [Image.fromarray(np.uint8(img)) for img in seq_clear]
if self.brightness > 0:
brightness_factor = np.random.uniform(max(0, 1 - self.brightness), 1 + self.brightness)
seq_blur = [F.adjust_brightness(img, brightness_factor) for img in seq_blur]
seq_clear = [F.adjust_brightness(img, brightness_factor) for img in seq_clear]
if self.contrast > 0:
contrast_factor = np.random.uniform(max(0, 1 - self.contrast), 1 + self.contrast)
seq_blur = [F.adjust_contrast(img, contrast_factor) for img in seq_blur]
seq_clear = [F.adjust_contrast(img, contrast_factor) for img in seq_clear]
if self.saturation > 0:
saturation_factor = np.random.uniform(max(0, 1 - self.saturation), 1 + self.saturation)
seq_blur = [F.adjust_saturation(img, saturation_factor) for img in seq_blur]
seq_clear = [F.adjust_saturation(img, saturation_factor) for img in seq_clear]
if self.hue > 0:
hue_factor = np.random.uniform(-self.hue, self.hue)
seq_blur = [F.adjust_hue(img, hue_factor) for img in seq_blur]
seq_clear = [F.adjust_hue(img, hue_factor) for img in seq_clear]
seq_blur = [np.asarray(img) for img in seq_blur]
seq_clear = [np.asarray(img) for img in seq_clear]
seq_blur = [img.clip(0,255) for img in seq_blur]
seq_clear = [img.clip(0,255) for img in seq_clear]
return seq_blur, seq_clear
示例10: get_params
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def get_params(brightness, contrast, saturation, hue):
"""Get a randomized transform to be applied on image.
Arguments are same as that of __init__.
Returns:
Transform which randomly adjusts brightness, contrast and
saturation in a random order.
"""
transforms = []
if brightness is not None:
brightness_factor = random.uniform(brightness[0], brightness[1])
transforms.append(Lambda(lambda img: F.adjust_brightness(img, brightness_factor)))
if contrast is not None:
contrast_factor = random.uniform(contrast[0], contrast[1])
transforms.append(Lambda(lambda img: F.adjust_contrast(img, contrast_factor)))
if saturation is not None:
saturation_factor = random.uniform(saturation[0], saturation[1])
transforms.append(Lambda(lambda img: F.adjust_saturation(img, saturation_factor)))
if hue is not None:
hue_factor = random.uniform(hue[0], hue[1])
transforms.append(Lambda(lambda img: F.adjust_hue(img, hue_factor)))
random.shuffle(transforms)
transform = Compose(transforms)
return transform
示例11: __call__
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def __call__(self, img, mask):
assert img.size == mask.size
return tf.adjust_hue(img, random.uniform(-self.hue,
self.hue)), mask
示例12: __call__
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def __call__(self, img, mask):
assert img.size == mask.size
return tf.adjust_hue(img, random.uniform(-self.hue, self.hue)), mask
示例13: torchvision_transform
# 需要導入模塊: from torchvision.transforms import functional [as 別名]
# 或者: from torchvision.transforms.functional import adjust_hue [as 別名]
def torchvision_transform(self, img):
img = torchvision.adjust_hue(img, hue_factor=0.1)
img = torchvision.adjust_saturation(img, saturation_factor=1.2)
img = torchvision.adjust_brightness(img, brightness_factor=1.2)
return img