當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。