當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageOps.invert方法代碼示例

本文整理匯總了Python中PIL.ImageOps.invert方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageOps.invert方法的具體用法?Python ImageOps.invert怎麽用?Python ImageOps.invert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PIL.ImageOps的用法示例。


在下文中一共展示了ImageOps.invert方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: displayImageFileOnLCD

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [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: run

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def run(self):
        global lcd
        for foo in camera.capture_continuous(self.stream2, format='jpeg', use_video_port=True, resize=(S_WIDTH, S_HEIGHT), splitter_port=0):
            self.stream2.seek(0) # "Rewind" the stream to the beginning so we can read its content
            print('live-view thread')
            
            # create image and invert it
            image_source = Image.open(self.stream2)
            imageInverted = ImageOps.invert(image_source)
            
            # convert image to black or white and send to LCD
            lcd.write(imageInverted.convert('1').tobytes())
            self.stream2.seek(0)
            
            if self.exit:
                break
            
# Variables 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:20,代碼來源:polapizero_05.py

示例3: autocrop_image

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def autocrop_image(image, border = 0):
    from PIL import Image, ImageOps
    size = image.size
    bb_image = image
    bbox = bb_image.getbbox()
    if (size[0] == bbox[2]) and (size[1] == bbox[3]):
        bb_image=bb_image.convert("RGB")
        bb_image = ImageOps.invert(bb_image)
        bbox = bb_image.getbbox()
    image = image.crop(bbox)
    (width, height) = image.size
    width += border * 2
    height += border * 2
    ratio = float(width)/height
    cropped_image = Image.new("RGBA", (width, height), (0,0,0,0))
    cropped_image.paste(image, (border, border))
    #TODO find epg height
    logo_height = 450 / int(ADDON.getSetting('channels.per.page'))
    logo_height = logo_height - 2
    if ADDON.getSetting('program.channel.logo') == "false":
        cropped_image = cropped_image.resize((int(logo_height*ratio), logo_height),Image.ANTIALIAS)
    return cropped_image 
開發者ID:primaeval,項目名稱:script.tvguide.fullscreen,代碼行數:24,代碼來源:utils.py

示例4: autocrop_image

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def autocrop_image(infile,outfile):
    infile = xbmc.translatePath(infile)
    image = Image.open(infile)
    border = 0
    size = image.size
    bb_image = image
    bbox = bb_image.getbbox()
    if (size[0] == bbox[2]) and (size[1] == bbox[3]):
        bb_image=bb_image.convert("RGB")
        bb_image = ImageOps.invert(bb_image)
        bbox = bb_image.getbbox()
    image = image.crop(bbox)
    (width, height) = image.size
    width += border * 2
    height += border * 2
    ratio = float(width)/height
    cropped_image = Image.new("RGBA", (width, height), (0,0,0,0))
    cropped_image.paste(image, (border, border))
    #TODO find epg height
    logo_height = 450 / int(ADDON.getSetting('channels.per.page'))
    logo_height = logo_height - 2
    cropped_image = cropped_image.resize((int(logo_height*ratio), logo_height),Image.ANTIALIAS)
    outfile = xbmc.translatePath(outfile)
    cropped_image.save(outfile) 
開發者ID:primaeval,項目名稱:script.tvguide.fullscreen,代碼行數:26,代碼來源:ResizeLogos.py

示例5: post

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def post(self):
        # 獲得分頁參數。
        imgStr = self.get_argument("txt", default="", strip=False)
        # imgStr.replace(" ", "+")
        imgStr = base64.b64decode(imgStr)
        print("imgStr:", type(imgStr))
        image = Image.open(io.StringIO(imgStr))
        image.thumbnail((28, 28), Image.ANTIALIAS)
        image = image.convert('L')
        image = ImageOps.invert(image)
        image.save(work_dir + "/web-tmp.bmp", format="BMP") #保存看看,是否
        #print(image)
        # img_url = self.get_argument("img_url", default=0, strip=False)
        # print(img_url)
        server = "0.0.0.0:8500"
        prediction = do_inference(server, image)
        print('######### prediction : ', prediction)
        self.write(json.dumps(prediction))



# 調用 grpc 代碼,將圖片轉換成數組,讓後放到 grpc 調用。 
開發者ID:pythonstock,項目名稱:stock,代碼行數:24,代碼來源:minstServingHandler.py

示例6: invert_image

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def invert_image(self, extension: str = "png"):
        """Invert the colors of the image
        
        Args:
            extension (str, optional): File extension of loaded image. Defaults to png
        
        Returns:
            Chepy: The Chepy object. 

        Examples:
            >>> c = Chepy("logo.png").load_file().invert_image("png")
            >>> >>> c.write('/path/to/file.png', as_binary=True)
        """
        image = Image.open(self._load_as_file())
        image = self._force_rgb(image)
        fh = io.BytesIO()
        inverted = ImageOps.invert(image)
        inverted.save(fh, extension)
        self.state = fh.getvalue()
        return self 
開發者ID:securisec,項目名稱:chepy,代碼行數:22,代碼來源:multimedia.py

示例7: __init__

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def __init__(self, img_source):
        """
        Load in an image

        :param img_source: PIL.Image, or filename to load one from.
        """
        if isinstance(img_source, Image.Image):
            img_original = img_source
        else:
            img_original = Image.open(img_source)

        # store image for eventual further processing (splitting)
        self.img_original = img_original

        # Convert to white RGB background, paste over white background
        # to strip alpha.
        img_original = img_original.convert('RGBA')
        im = Image.new("RGB", img_original.size, (255, 255, 255))
        im.paste(img_original, mask=img_original.split()[3])
        # Convert down to greyscale
        im = im.convert("L")
        # Invert: Only works on 'L' images
        im = ImageOps.invert(im)
        # Pure black and white
        self._im = im.convert("1") 
開發者ID:python-escpos,項目名稱:python-escpos,代碼行數:27,代碼來源:image.py

示例8: __call__

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def __call__(self, img_group, is_flow=False):
        v = random.random()
        if v < 0.5:
            ret = [img.transpose(Image.FLIP_LEFT_RIGHT) for img in img_group]
            if self.is_flow:
                for i in range(0, len(ret), 2):
                    ret[i] = ImageOps.invert(ret[i])  # invert flow pixel values when flipping
            return ret
        else:
            return img_group 
開發者ID:yjxiong,項目名稱:tsn-pytorch,代碼行數:12,代碼來源:transforms.py

示例9: displayImageFileOnLCD

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def displayImageFileOnLCD(filename):
    print 'displays ', filename
    # 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))
    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,代碼行數:16,代碼來源:interface_tests2.py

示例10: write

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def write(self, s):
        global lcd
        image = Image.frombuffer('L', P_SIZE, s, "raw", 'L', 0, 1)
        image = image.crop((self.x, 0, self.x+1, P_HEIGHT))
        self.image_scan.paste(image,(self.x, 0))
        if self.x < P_WIDTH-1:
            self.x += 1
        image = ImageOps.invert(self.image_scan)
        image.thumbnail(S_SIZE, Image.NEAREST)
        image = image.convert('1')
        lcd.write(image.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:13,代碼來源:video_test2.py

示例11: displayImageFileOnLCD

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def displayImageFileOnLCD(filename):
    print 'displays ', filename
    title = 'Review Mode'
    # resize/dither to screen resolution and send to LCD
    try:
        image = Image.open(filename)
    except IOError:
        print ("cannot identify image file", filename)
        image = Image.open('unidentified.jpg')
    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 the 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,代碼行數:28,代碼來源:polapizero_05.py

示例12: write

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def write(self, s):
        global lcd
        self.size += len(s)
        image = Image.frombuffer('L', (416, 240), s, "raw", 'L', 0, 1)
        image = image.crop((0, 0, S_WIDTH, S_HEIGHT))
        image = ImageOps.invert(image)
        image = image.convert('1')
        lcd.write(image.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:10,代碼來源:video_test1.py

示例13: write

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def write(self, s):
        global lcd
        
        b1 = bytearray()
        b1.extend(s[:(P_WIDTH*P_HEIGHT)])
        
        mi = min(b1)
        ma = max(b1)
        ra = ma-mi
        b2 = bytearray()
        
        for pix in range(P_WIDTH*P_HEIGHT):
            b2.append( (b1[pix]*(255/ra))-mi )
        
        print(max(b1), min(b1), max(b2), min(b2))
        
        image = Image.frombuffer('L', P_SIZE, b2, "raw", 'L', 0, 1)
        image.thumbnail(S_SIZE, Image.NEAREST)
        
#         draw = ImageDraw.Draw(image)
#         font = ImageFont.truetype('arial.ttf', 18)
#         
#         draw.rectangle([(0, 0), (115, 22)], fill=255, outline=0)
#         draw.text((2, 2), "TESt *", fill='black', font=font)
        
        image = ImageOps.invert(image)
        image = image.convert('1')
        lcd.write(image.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:30,代碼來源:video_test3.py

示例14: displayImageFileOnLCD

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def displayImageFileOnLCD(filename):
    print 'displays ', filename
    title = 'Review Mode'
    # resize/dither to screen resolution and send to LCD
    try:
        image = Image.open(filename)
    except IOError:
        print ("cannot identify image file", filename)
        image = Image.open('unidentified.jpg')
    im_width, im_height = image.size
    if im_width < im_height:
        image = image.rotate(90)
    image.thumbnail(SCREEN_SIZE, Image.ANTIALIAS)
    image_sized = Image.new('RGB', SCREEN_SIZE, (0, 0, 0))
    image_sized.paste(image,((SCREEN_SIZE[0] - image.size[0]) / 2, (SCREEN_SIZE[1] - image.size[1]) / 2))
    # draw texts
    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)
    font = ImageFont.truetype('arial.ttf', 10)
    draw.rectangle([(300, 0), (399, 14)], fill=(255,255,255), outline=(0,0,0))
    draw.text((302, 2), hostIP, 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,代碼行數:31,代碼來源:polapizero_07.py

示例15: write

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import invert [as 別名]
def write(self, s):
        global lcd
        image = Image.frombuffer('L', (416, 240), s, "raw", 'L', 0, 1)
        image = image.crop((8, 0, S_WIDTH+8, S_HEIGHT))
        image = ImageOps.invert(image)
        image = image.convert('1')
        lcd.write(image.tobytes()) 
開發者ID:pierre-muth,項目名稱:polapi-zero,代碼行數:9,代碼來源:polapizero_06.py


注:本文中的PIL.ImageOps.invert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。