当前位置: 首页>>代码示例>>Python>>正文


Python Image.composite方法代码示例

本文整理汇总了Python中PIL.Image.composite方法的典型用法代码示例。如果您正苦于以下问题:Python Image.composite方法的具体用法?Python Image.composite怎么用?Python Image.composite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL.Image的用法示例。


在下文中一共展示了Image.composite方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_rotated_image_labels

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def get_rotated_image_labels(client, image, bg, phi):

    # https://stackoverflow.com/a/5253554
    rot = image.rotate(-phi)   # clockwise
    image_tf = Image.composite(rot, bg, rot)

    filename = str(phi) + '.png'
    image_tf.convert('RGB').save(os.path.join(output_path, filename))

    # https://stackoverflow.com/a/33117447
    imgByteArr = io.BytesIO()
    image_tf.save(imgByteArr, format='PNG')
    imgByteArr = imgByteArr.getvalue() 

    image = types.Image(content=imgByteArr)
    response = client.label_detection(image=image)
    return response 
开发者ID:minimaxir,项目名称:optillusion-animation,代码行数:19,代码来源:image_rotation_data.py

示例2: lomoize

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def lomoize (image,darkness,saturation):
	
	(width,height) = image.size

	max = width
	if height > width:
		max = height
	
	mask = Image.open("./lomolive/lomomask.jpg").resize((max,max))

	left = round((max - width) / 2)
	upper = round((max - height) / 2)
	
	mask = mask.crop((left,upper,left+width,upper + height))

#	mask = Image.open('mask_l.png')

	darker = ImageEnhance.Brightness(image).enhance(darkness)	
	saturated = ImageEnhance.Color(image).enhance(saturation)
	lomoized = Image.composite(saturated,darker,mask)
	
	return lomoized 
开发者ID:Lavande,项目名称:wx-fancy-pic,代码行数:24,代码来源:lomolive.py

示例3: mask_img

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def mask_img(img, attn, upscale=32):
		"""
		Put attention weights to each region in image.
		--------------------
		Arguments:
			img (ndarray: H x W x C): image data.
			attn (ndarray: 14 x 14): attention weights of each region.
			upscale (int): the ratio between attention size and image size.
		"""
		attn = transform.pyramid_expand(attn, upscale=upscale, sigma=20)
		attn = misc.toimage(attn).convert("L")
		mask = misc.toimage(np.zeros(img.shape, dtype=np.uint8)).convert("RGBA")
		img = misc.toimage(img).convert("RGBA")
		img = Image.composite(img, mask, attn)

		return img 
开发者ID:cvlab-tohoku,项目名称:Dense-CoAttention-Network,代码行数:18,代码来源:utils.py

示例4: draw_mask_on_image_array

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def draw_mask_on_image_array(image, mask, color='red', alpha=0.7):
  """Draws mask on an image.

  Args:
    image: uint8 numpy array with shape (img_height, img_height, 3)
    mask: a float numpy array of shape (img_height, img_height) with
      values between 0 and 1
    color: color to draw the keypoints with. Default is red.
    alpha: transparency value between 0 and 1. (default: 0.7)

  Raises:
    ValueError: On incorrect data type for image or masks.
  """
  if image.dtype != np.uint8:
    raise ValueError('`image` not of type np.uint8')
  if mask.dtype != np.float32:
    raise ValueError('`mask` not of type np.float32')
  if np.any(np.logical_or(mask > 1.0, mask < 0.0)):
    raise ValueError('`mask` elements should be in [0, 1]')
  rgb = ImageColor.getrgb(color)
  pil_image = Image.fromarray(image)

  solid_color = np.expand_dims(
      np.ones_like(mask), axis=2) * np.reshape(list(rgb), [1, 1, 3])
  pil_solid_color = Image.fromarray(np.uint8(solid_color)).convert('RGBA')
  pil_mask = Image.fromarray(np.uint8(255.0*alpha*mask)).convert('L')
  pil_image = Image.composite(pil_solid_color, pil_image, pil_mask)
  np.copyto(image, np.array(pil_image.convert('RGB'))) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:30,代码来源:visualization_utils.py

示例5: draw_mask_on_image_array

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def draw_mask_on_image_array(image, mask, color='red', alpha=0.7):
  """Draws mask on an image.

  Args:
    image: uint8 numpy array with shape (img_height, img_height, 3)
    mask: a uint8 numpy array of shape (img_height, img_height) with
      values between either 0 or 1.
    color: color to draw the keypoints with. Default is red.
    alpha: transparency value between 0 and 1. (default: 0.7)

  Raises:
    ValueError: On incorrect data type for image or masks.
  """
  if image.dtype != np.uint8:
    raise ValueError('`image` not of type np.uint8')
  if mask.dtype != np.uint8:
    raise ValueError('`mask` not of type np.uint8')
  if np.any(np.logical_and(mask != 1, mask != 0)):
    raise ValueError('`mask` elements should be in [0, 1]')
  rgb = ImageColor.getrgb(color)
  pil_image = Image.fromarray(image)

  solid_color = np.expand_dims(
      np.ones_like(mask), axis=2) * np.reshape(list(rgb), [1, 1, 3])
  pil_solid_color = Image.fromarray(np.uint8(solid_color)).convert('RGBA')
  pil_mask = Image.fromarray(np.uint8(255.0*alpha*mask)).convert('L')
  pil_image = Image.composite(pil_solid_color, pil_image, pil_mask)
  np.copyto(image, np.array(pil_image.convert('RGB'))) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:30,代码来源:visualization_utils.py

示例6: draw_mask_on_image_array

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def draw_mask_on_image_array(image, mask, color='red', alpha=0.4):
  """Draws mask on an image.

  Args:
    image: uint8 numpy array with shape (img_height, img_height, 3)
    mask: a uint8 numpy array of shape (img_height, img_height) with
      values between either 0 or 1.
    color: color to draw the keypoints with. Default is red.
    alpha: transparency value between 0 and 1. (default: 0.4)

  Raises:
    ValueError: On incorrect data type for image or masks.
  """
  if image.dtype != np.uint8:
    raise ValueError('`image` not of type np.uint8')
  if mask.dtype != np.uint8:
    raise ValueError('`mask` not of type np.uint8')
  if np.any(np.logical_and(mask != 1, mask != 0)):
    raise ValueError('`mask` elements should be in [0, 1]')
  if image.shape[:2] != mask.shape:
    raise ValueError('The image has spatial dimensions %s but the mask has '
                     'dimensions %s' % (image.shape[:2], mask.shape))
  rgb = ImageColor.getrgb(color)
  pil_image = Image.fromarray(image)

  solid_color = np.expand_dims(
      np.ones_like(mask), axis=2) * np.reshape(list(rgb), [1, 1, 3])
  pil_solid_color = Image.fromarray(np.uint8(solid_color)).convert('RGBA')
  pil_mask = Image.fromarray(np.uint8(255.0*alpha*mask)).convert('L')
  pil_image = Image.composite(pil_solid_color, pil_image, pil_mask)
  np.copyto(image, np.array(pil_image.convert('RGB'))) 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:33,代码来源:visualization_utils.py

示例7: put_transparent_mask

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def put_transparent_mask(img, mask, palette):
    mask_np = np.array(mask, dtype=np.uint8)
    mask_png = Image.fromarray(mask_np, mode='P')
    mask_png.putpalette(palette)
    mask_rgb = mask_png.convert('RGB')

    mask_np[mask_np > 0] = 130
    mask_np[mask_np == 0] = 255
    mask_l = Image.fromarray(mask_np, mode='L')
    out_image = Image.composite(img, mask_rgb, mask_l)
    return out_image 
开发者ID:dvornikita,项目名称:blitznet,代码行数:13,代码来源:demo_utils.py

示例8: mask_image

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def mask_image(img, mask, opacity=1.00, bg=False):
    """
        - img (PIL)
        - mask (PIL)
        - opacity (float) (default: 1.00)
    Returns a PIL image.
    """
    blank = Image.new('RGB', img.size, color=0)
    if bg:
        masked_image = Image.composite(blank, img, mask)
    else:
        masked_image = Image.composite(img, blank, mask)
    if opacity < 1:
        masked_image = Image.blend(img, masked_image, opacity)
    return masked_image 
开发者ID:MattKleinsmith,项目名称:pbt,代码行数:17,代码来源:utils.py

示例9: draw_mask_on_image_array

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import composite [as 别名]
def draw_mask_on_image_array(image, mask, color='red', alpha=0.7):
    """Draws mask on an image.

    Args:
      image: uint8 numpy array with shape (img_height, img_height, 3)
      mask: a float numpy array of shape (img_height, img_height) with
        values between 0 and 1
      color: color to draw the keypoints with. Default is red.
      alpha: transparency value between 0 and 1. (default: 0.7)

    Raises:
      ValueError: On incorrect data type for image or masks.
    """
    if image.dtype != np.uint8:
        raise ValueError('`image` not of type np.uint8')
    if mask.dtype != np.float32:
        raise ValueError('`mask` not of type np.float32')
    if np.any(np.logical_or(mask > 1.0, mask < 0.0)):
        raise ValueError('`mask` elements should be in [0, 1]')
    rgb = ImageColor.getrgb(color)
    pil_image = Image.fromarray(image)

    solid_color = np.expand_dims(
        np.ones_like(mask), axis=2) * np.reshape(list(rgb), [1, 1, 3])
    pil_solid_color = Image.fromarray(np.uint8(solid_color)).convert('RGBA')
    pil_mask = Image.fromarray(np.uint8(255.0 * alpha * mask)).convert('L')
    pil_image = Image.composite(pil_solid_color, pil_image, pil_mask)
    np.copyto(image, np.array(pil_image.convert('RGB'))) 
开发者ID:PacktPublishing,项目名称:Hands-On-Machine-Learning-with-OpenCV-4,代码行数:30,代码来源:visualization_utils.py


注:本文中的PIL.Image.composite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。