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


Python Image.new方法代码示例

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


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

示例1: displayImageFileOnLCD

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def displayImageFileOnLCD(filename):
    print 'displays ', filename
    title = 'Review Mode'
    # resize/dither to screen resolution and send to LCD
    image = Image.open(filename)
    im_width, im_height = image.size
    if im_width < im_height:
        image = image.rotate(90)
    image.thumbnail(S_SIZE, Image.ANTIALIAS)
    image_sized = Image.new('RGB', S_SIZE, (0, 0, 0))
    image_sized.paste(image,((S_SIZE[0] - image.size[0]) / 2, (S_SIZE[1] - image.size[1]) / 2))
    # draw filename
    draw = ImageDraw.Draw(image_sized)
    font = ImageFont.truetype('arial.ttf', 18)
    draw.rectangle([(0, 0), (115, 22)], fill=(255,255,255), outline=(0,0,0))
    draw.text((2, 2), title, fill='black', font=font)
    draw.rectangle([(279, 217), (399, 239)], fill=(255,255,255), outline=(0,0,0))
    draw.text((290, 218), filename, fill='black', font=font)
    # display on LCD
    image_sized = ImageOps.invert(image_sized)
    image_sized = image_sized.convert('1') # convert image to black and white
    lcd.write(image_sized.tobytes()) 
开发者ID:pierre-muth,项目名称:polapi-zero,代码行数:24,代码来源:polapizero_03.py

示例2: create_image_from_text

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def create_image_from_text(in_text):
    colours = (255, 255, 250)
    font_file = '/usr/share/fonts/truetype/freefont/FreeSansBold.ttf'
    font_size = 12
    font = ImageFont.truetype(font_file, font_size)
    w, h = font.getsize(in_text)

    text_x, text_y = width, 0
    text_width, text_height = width, 0

    text_width += w + width                # add some padding so the ip scrolls off the unicorn hat
    text_height = max(text_height, h, 16)  # no more than the size of the unicorn hat

    image = Image.new('RGB', (text_width, text_height), (0, 0, 0))
    draw = ImageDraw.Draw(image)
    draw.text((text_x, text_y), in_text, colours, font=font)
    return (image, text_width)


# DISPLAY 
开发者ID:pimoroni,项目名称:unicorn-hat-hd,代码行数:22,代码来源:show_my_ip.py

示例3: decode_labels

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def decode_labels(mask, num_images=1, num_classes=21):
    """Decode batch of segmentation masks.
    
    Args:
      mask: result of inference after taking argmax.
      num_images: number of images to decode from the batch.
      num_classes: number of classes to predict (including background).
    
    Returns:
      A batch with num_images RGB images of the same size as the input. 
    """
    mask = mask.data.cpu().numpy()
    n, h, w = mask.shape
    assert(n >= num_images), 'Batch size %d should be greater or equal than number of images to save %d.' % (n, num_images)
    outputs = np.zeros((num_images, h, w, 3), dtype=np.uint8)
    for i in range(num_images):
      img = Image.new('RGB', (len(mask[i, 0]), len(mask[i])))
      pixels = img.load()
      for j_, j in enumerate(mask[i, :, :]):
          for k_, k in enumerate(j):
              if k < num_classes:
                  pixels[k_,j_] = label_colours[k]
      outputs[i] = np.array(img)
    return outputs 
开发者ID:speedinghzl,项目名称:pytorch-segmentation-toolbox,代码行数:26,代码来源:utils.py

示例4: draw

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def draw(self, image, overlay):
        if((overlay or not self.luoverlay) and not self.ludrawn):
            self.ludrawn = True
            stp = self.location
            transparent = int(255 * 0.45 if self.lucolor == 0 else 255 * 0.8)
            color = (self.lucolor, self.lucolor, self.lucolor, transparent)
            uline = Image.new("RGBA", (self.size[0], 1), color)
            lline = Image.new("RGBA", (1, self.size[1]), color)
            image.paste(uline, stp, uline)
            image.paste(lline, stp, lline)
        if((overlay or not self.rdoverlay) and not self.rddrawn):
            self.rddrawn = True
            dstp = (self.location[0], self.location[1] + self.size[1])
            rstp = (self.location[0] + self.size[0], self.location[1])
            transparent = int(255 * 0.45 if self.rdcolor == 0 else 255 * 0.8)
            color = (self.rdcolor, self.rdcolor, self.rdcolor, transparent)
            dline = Image.new("RGBA", (self.size[0], 1), color)
            rline = Image.new("RGBA", (1, self.size[1]), color)
            image.paste(dline, dstp, dline)
            image.paste(rline, rstp, rline) 
开发者ID:linsamtw,项目名称:TaiwanTrainVerificationCode2text,代码行数:22,代码来源:work_vcode.py

示例5: autocaptcha

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def autocaptcha(path):
    """Auto identify captcha in path.

    Use pytesseract to identify captcha.

    Args:
        path: string, image path.

    Returns:
        string, OCR identified code.
    """
    im = Image.open(path)

    im = im.convert('L')
    im = ImageEnhance.Contrast(im)
    im = im.enhance(3)
    img2 = Image.new('RGB', (150, 60), (255, 255, 255))
    img2.paste(im.copy(), (25, 10))

    # TODO: add auto environment detect
    return pytesseract.image_to_string(img2) 
开发者ID:MXWXZ,项目名称:sjtu-automata,代码行数:23,代码来源:autocaptcha.py

示例6: image_crop_with_padding

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def image_crop_with_padding(self, img, crop_region, crop_shape):
        set_left, set_up, right, bottom = crop_region
        crop_left, corp_up = max(set_left, 0), max(set_up, 0)
        crop_region = (crop_left, corp_up, right, bottom)

        img = img.crop(crop_region)
        if img.size != crop_shape:
            pad_img = Image.new('RGB', crop_shape, self.pad_pixel)
            paste_region = (max(0-set_left, 0),
                            max(0-set_up, 0),
                            max(0-set_left, 0)+img.size[0],
                            max(0-set_up, 0)+img.size[1])
            pad_img.paste(img, paste_region)
            return pad_img

        return img 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:18,代码来源:transforms.py

示例7: generate_board

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def generate_board():
    global initial_board
    initial_board = Image.new('RGB', (BOARD_EDGE, BOARD_EDGE))

    for i in range(0, BOARD_EDGE, SQUARE_EDGE):
        for j in range(0, BOARD_EDGE, SQUARE_EDGE):
            clear(initial_board, (i, j))

    row = ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r']
    order = ('w', 'b') if reverse else ('b', 'w')

    for i in range(8):
        col = SQUARE_EDGE * i
        exec('initial_board.paste({0}, (col, 0), {0})'
            .format(order[0] + row[i]))
        exec('initial_board.paste({0}, (col, BOARD_EDGE - SQUARE_EDGE), {0})'
            .format(order[1] + row[i]))

        exec('initial_board.paste({0}p, (col, SQUARE_EDGE), {0}p)'
            .format(order[0]))
        exec(
            'initial_board.paste({0}p, (col, BOARD_EDGE - (SQUARE_EDGE * 2)), {0}p)'
            .format(order[1])) 
开发者ID:dn1z,项目名称:pgn2gif,代码行数:25,代码来源:pgn2gif.py

示例8: drawSlants

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def drawSlants(side):
	randcolor = lambda : (randint(0,255),randint(0,255),randint(0,255))

	img = Image.new("RGB", (side,side), "#FFFFFF")
	draw = ImageDraw.Draw(img)
	y = 0
	min_w = int(side * 0.01)
	max_w = int(side * 0.1)
	adj = max_w * 2
	while y <= side+adj:
		w = randint(min_w, max_w)
		c = randcolor()
		draw.line([-adj , y,  y, -adj], width=w, fill=c)
		draw.line([y, side+adj,  side+adj, y], width=w, fill=c)
		y+=w

	return img


#################
# TRIANGULATION #
################# 
开发者ID:SubhrajitPrusty,项目名称:wallgen,代码行数:24,代码来源:shapes.py

示例9: nGradient

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def nGradient(side, *colors):
	img = Image.new("RGB", (side,side), "#FFFFFF")
	draw = ImageDraw.Draw(img)

	nc = len(colors)
	div = side//(nc-1)
	[r,g,b] = colors[0]
	p=0
	for i in range(1,nc):
		dc = [(y-x)/div for x,y in zip(colors[i-1], colors[i])]
		for x in range(p, p+div):
			draw.line([x,0,x,side], fill=tuple(map(int, [r,g,b])))
			r+=dc[0]
			g+=dc[1]
			b+=dc[2]
		p+=div
	
	return img 
开发者ID:SubhrajitPrusty,项目名称:wallgen,代码行数:20,代码来源:gradient.py

示例10: check_OP_1_Connection

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def check_OP_1_Connection():
    connected = Image.new('1', (128, 64))
    draw = ImageDraw.Draw(connected)
    draw.text((0, 25), "Connecting.....", font=getFont(), fill='white')
    displayImage(connected)

    # if is_connected():
    if do_mount("OP1"):
        connected = Image.new('1', (128, 64))
        draw = ImageDraw.Draw(connected)
        draw.text((0, 25), "Connected", font=getFont(), fill='white')
        displayImage(connected)
        return True
    else:
        connected = Image.new('1', (128, 64))
        draw = ImageDraw.Draw(connected)
        draw.text((0, 25), "No Connection!", font=getFont(), fill='white')
        displayImage(connected)
        config["USB_Mount_Path"] = ""
        config["OP_1_Mounted_Dir"] = ""
        time.sleep(1)
        return False 
开发者ID:adwuard,项目名称:OP_Manager,代码行数:24,代码来源:OP_1_Connection.py

示例11: unmount_OP_Z

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def unmount_OP_Z():
    if getMountPath("OPZ") != "":
        unmountDisplay = Image.new('1', (128, 64))
        draw = ImageDraw.Draw(unmountDisplay)
        draw.text((30, 25), "Ejecting!", font=getFont(), fill='white')
        displayImage(unmountDisplay)
        unmountdevice(config["OP_Z_Mounted_Dir"])
        config["USB_Mount_Path"] = ""
        unmountDisplay = Image.new('1', (128, 64))
        draw = ImageDraw.Draw(unmountDisplay)
        draw.text((30, 25), "Ejected!", font=getFont(), fill='white')
        displayImage(unmountDisplay)
        time.sleep(1)
        return True
    else:
        unmountDisplay = Image.new('1', (128, 64))
        draw = ImageDraw.Draw(unmountDisplay)
        draw.text((15, 25), "No Device to Eject", font=getFont(), fill='white')
        displayImage(unmountDisplay)
        time.sleep(1)
        return False 
开发者ID:adwuard,项目名称:OP_Manager,代码行数:23,代码来源:OP_1_Connection.py

示例12: debug_img

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def debug_img(img, bitmap, logistic_output):
  # create a debug image with three columns; 1) original RGB. 2) black/white
  # bitmap of labels 3) black/white bitmap of predictions (with centroids coloured
  # red.
  h, w, _channels = bitmap.shape
  canvas = Image.new('RGB', (w*3, h), (50, 50, 50))
  # original input image on left
  img = zero_centered_array_to_pil_image(img)
  img = img.resize((w, h))
  canvas.paste(img, (0, 0))
  # label bitmap in center
  canvas.paste(bitmap_to_pil_image(bitmap), (w, 0))
  # logistic output on right
  canvas.paste(bitmap_to_pil_image(logistic_output), (w*2, 0))
  # draw red dots on right hand side image corresponding to
  # final thresholded prediction
  draw = ImageDraw.Draw(canvas)
  for y, x in centroids_of_connected_components(logistic_output):
    draw.rectangle((w*2+x,y,w*2+x,y), fill='red')
  # finally draw blue lines between the three to delimit boundaries
  draw.line([w,0,w,h], fill='blue')
  draw.line([2*w,0,2*w,h], fill='blue')
  draw.line([3*w,0,3*w,h], fill='blue')
  # done
  return canvas 
开发者ID:matpalm,项目名称:bnn,代码行数:27,代码来源:util.py

示例13: side_by_side

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def side_by_side(rgb, bitmap):
  h, w, _ = rgb.shape
  canvas = Image.new('RGB', (w*2, h), (50, 50, 50))
  # paste RGB on left hand side
  lhs = zero_centered_array_to_pil_image(rgb)
  canvas.paste(lhs, (0, 0))
  # paste bitmap version of labels on right hand side
  # black with white dots at labels
  rhs = bitmap_to_pil_image(bitmap)
  rhs = rhs.resize((w, h))
  canvas.paste(rhs, (w, 0))
  # draw on a blue border (and blue middle divider) to make it
  # easier to see relative positions.
  draw = ImageDraw.Draw(canvas)
  draw.polygon([0,0,w*2-1,0,w*2-1,h-1,0,h-1], outline='blue')
  draw.line([w,0,w,h], fill='blue')
  canvas = canvas.resize((w, h//2))
  return canvas 
开发者ID:matpalm,项目名称:bnn,代码行数:20,代码来源:util.py

示例14: valid

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def valid(labels, cx, cy):
  # is idxth item in labels "valid"? where "valid" => bounding
  # box within image and no other bee in bounding box.
  x1, y1 = cx-HW, cy-HW
  if x1 < 0 or y1 < 0:
    # either left or top margin out of bounds => invalid
    return False
  x2, y2 = cx+HW, cy+HW
  if x2 > opts.width or y2 > opts.height:
    # either right or bottom margin out of bounds => invalid
    return False
  for ox, oy in labels:
    if ox == cx and oy == cy:
      # this 'other' bee is the one being checked => ignore
      continue
    if x1 < ox and ox < x2 and y1 < oy and oy < y2:
      # other bee inside bounding box => invalid
      return False
  return True

#canvas = Image.new('RGB', (HW*20, HW*20), (0,0,0)) 
开发者ID:matpalm,项目名称:bnn,代码行数:23,代码来源:dump_bee_crops.py

示例15: dump_images

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import new [as 别名]
def dump_images(prefix):
  # run from imgs -> bitmap and stitch them together...
  img_collage = Image.new('RGB', (17*8, 17*8), (0, 0, 0))
  bitmap_collage = Image.new('RGB', (9*8, 9*8), (255, 255, 255))
  centroids_collage = Image.new('RGB', (9*8, 9*8), (255, 255, 255))
  ims, bs = sess.run([imgs, model.output])
  for x in range(8):
    for y in range(8):
      i = (x * 8) + y
      img_collage.paste(u.zero_centered_array_to_pil_image(ims[i]), (17*x, 17*y))
      output_bitmap = u.bitmap_to_pil_image(bs[i])
      bitmap_collage.paste(output_bitmap, (9*x, 9*y))
      centroids = u.centroids_of_connected_components(bs[i])
      centroid_bitmap = u.bitmap_from_centroids(centroids, h=8, w=8)
      centroid_bitmap = u.bitmap_to_single_channel_pil_image(centroid_bitmap)
      centroids_collage.paste(centroid_bitmap, (9*x, 9*y))
  img_collage.save("images/ra/%s_imgs.png" % prefix)
  bitmap_collage.save("images/ra/%s_bitmaps.png" % prefix)
  centroids_collage.save("images/ra/%s_centroids.png" % prefix) 
开发者ID:matpalm,项目名称:bnn,代码行数:21,代码来源:reverse_optimise.py


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