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


Python ImageColor.getrgb方法代码示例

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


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

示例1: get_base_color

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def get_base_color(self):
        # calculate perceptual gray of key color
        color = ImageColor.getrgb(self.color)
        bright = 0.3 * color[0] + 0.59 * color[1] + 0.11 * color[2] 

        # get corresponding base image's average color
        if (bright > 0xB0):
            return 0xE0  # 224
        elif (bright > 0x80):
            return 0xB0  # 176
        elif (bright > 0x50):
            return 0x80  # 128
        elif (bright > 0x20):
            return 0x50  # 80
        else:
            return 0x20  # 32 
开发者ID:CQCumbers,项目名称:kle_render,代码行数:18,代码来源:key.py

示例2: open_base_img

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def open_base_img(full_profile, res, base_color, color):
    # get base image according to profile and perceptual gray of key color
    base_num = str([0xE0, 0xB0, 0x80, 0x50, 0x20].index(base_color) + 1)

    # open image and convert to Lab
    with Image.open('images/{0}_{1}{2}.png'.format(*full_profile, base_num)) as img:
        key_img = img.resize((int(s * res / 200) for s in img.size), resample=Image.BILINEAR).convert('RGBA')
    if full_profile[1] in ('ISO', 'BIGENTER'): alpha = key_img.split()[-1]
    l, a, b = ImageCms.applyTransform(key_img, rgb2lab_transform).split()

    # convert key color to Lab
    # a and b should be scaled by 128/100, but desaturation looks more natural
    rgb_color = color_objects.sRGBColor(*ImageColor.getrgb(color), is_upscaled=True)
    lab_color = color_conversions.convert_color(rgb_color, color_objects.LabColor)
    l1, a1, b1 = lab_color.get_value_tuple()
    l1, a1, b1 = int(l1 * 256 / 100), int(a1 + 128), int(b1 + 128)

    # change Lab of base image to match that of key color
    l = ImageMath.eval('convert(l + l1 - l_avg, "L")', l=l, l1=l1, l_avg=base_color)
    a = ImageMath.eval('convert(a + a1 - a, "L")', a=a, a1=a1)
    b = ImageMath.eval('convert(b + b1 - b, "L")', b=b, b1=b1)

    key_img = ImageCms.applyTransform(Image.merge('LAB', (l, a, b)), lab2rgb_transform).convert('RGBA')
    if full_profile[1] in ('ISO', 'BIGENTER'): key_img.putalpha(alpha)
    return key_img 
开发者ID:CQCumbers,项目名称:kle_render,代码行数:27,代码来源:key.py

示例3: decode

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def decode(self, code):
        # decode the code        
        middleType  = self.MIDDLE_PATCH_SET[code & 0x03]
        middleInvert= (code >> 2) & 0x01
        cornerType  = (code >> 3) & 0x0F
        cornerInvert= (code >> 7) & 0x01
        cornerTurn  = (code >> 8) & 0x03
        sideType    = (code >> 10) & 0x0F
        sideInvert  = (code >> 14) & 0x01
        sideTurn    = (code >> 15) & 0x03
        blue        = (code >> 16) & 0x1F
        green       = (code >> 21) & 0x1F
        red         = (code >> 27) & 0x1F
        
        foreColor = (red << 3, green << 3, blue << 3)
        
        return (middleType, middleInvert, 0),\
               (cornerType, cornerInvert, cornerTurn),\
               (sideType, sideInvert, sideTurn),\
               foreColor, ImageColor.getrgb('white') 
开发者ID:PacktPublishing,项目名称:Hands-On-Blockchain-for-Python-Developers,代码行数:22,代码来源:identicon.py

示例4: test_floodfill_border

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def test_floodfill_border(self):
        # floodfill() is experimental

        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        draw.rectangle(BBOX2, outline="yellow", fill="green")
        centre_point = (int(W/2), int(H/2))

        # Act
        ImageDraw.floodfill(
            im, centre_point, ImageColor.getrgb("red"),
            border=ImageColor.getrgb("black"))

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_floodfill2.png")) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:19,代码来源:test_imagedraw.py

示例5: test_floodfill_thresh

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def test_floodfill_thresh(self):
        # floodfill() is experimental

        # Arrange
        im = Image.new("RGB", (W, H))
        draw = ImageDraw.Draw(im)
        draw.rectangle(BBOX2, outline="darkgreen", fill="green")
        centre_point = (int(W/2), int(H/2))

        # Act
        ImageDraw.floodfill(
            im, centre_point, ImageColor.getrgb("red"),
            thresh=30)

        # Assert
        self.assert_image_equal(
            im, Image.open("Tests/images/imagedraw_floodfill2.png")) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:19,代码来源:test_imagedraw.py

示例6: get_region_color

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def get_region_color(self, regions):
        """
        Gets the RGB color of a brain region from the atlas.

        :param regions:  list of regions acronyms.

        """
        if not isinstance(regions, list):
            if not self._check_valid_region_arg(regions):
                return None
            return ImageColor.getrgb(self.structures.loc[self.structures.acronym == regions].color.values[0])
        else:
            colors = []
            for region in regions:
                if not self._check_valid_region_arg(region):
                    return None
                colors.append(ImageColor.getrgb(self.structures.loc[self.structures.acronym == region].color.values[0]))
            return colors 
开发者ID:BrancoLab,项目名称:BrainRender,代码行数:20,代码来源:insects_brains_db.py

示例7: draw_mask_on_image_array

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [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

示例8: draw_mask_on_image_array

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [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

示例9: draw_mask_on_image_array

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [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

示例10: get_base_img

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def get_base_img(self, full_profile):
        if self.flat:
            res, color, row, sizes = self.res, self.color, full_profile[1], {'ISO': (1.5, 2), 'BIGENTER': (2.25, 2)}
            return Image.new('RGBA', [int(res * x) for x in sizes.get(row, (1, 1))], color=ImageColor.getrgb(color))
        return open_base_img(full_profile, self.res, self.get_base_color(), self.color) 
开发者ID:CQCumbers,项目名称:kle_render,代码行数:7,代码来源:key.py

示例11: __init__

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def __init__(self, json):
        # parse keyboard-layout-editor JSON format
        data = deserialise(json)
        self.keys, self.color = data[0], ImageColor.getrgb(data[1])
        self.keyboard = Image.new('RGB', (1000, 1000), color=self.color)
        self.max_size = (0, 0) 
开发者ID:CQCumbers,项目名称:kle_render,代码行数:8,代码来源:keyboard.py

示例12: colorconvert

# 需要导入模块: from PIL import ImageColor [as 别名]
# 或者: from PIL.ImageColor import getrgb [as 别名]
def colorconvert(self, colour="#FF0000"):
        im = Image.open("data/pillconvert/blackpill.png")
        im = im.convert('RGBA')
        colour = ImageColor.getrgb(colour)
        data = np.array(im)
        red, green, blue, alpha = data.T
        white_areas = (red == 0) & (blue == 0) & (green == 0) & (alpha == 255)
        data[..., :-1][white_areas.T] = colour
        im2 = Image.fromarray(data)
        im2.save("data/pillconvert/pill.png") 
开发者ID:TrustyJAID,项目名称:Trusty-cogs-archive,代码行数:12,代码来源:pillconvert.py


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