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


Python ImageOps.crop方法代碼示例

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


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

示例1: get_cropped_tiles

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def get_cropped_tiles(img, border=112):
    new_im = ImageOps.crop(Image.fromarray(img), border=border)
    paddedimg = np.array(new_im)
    padded_tiles = get_tile_images(paddedimg)
    return padded_tiles 
開發者ID:Esri,項目名稱:raster-deep-learning,代碼行數:7,代碼來源:util.py

示例2: find_objects

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def find_objects(model, tiles, extent, crop=(0, 0, 0, 0), cycle=1):
    xmin = extent['xmin']  + crop[0]
    ymin = extent['ymin']  + crop[1]
    xmax = extent['xmax']  - crop[2]
    ymax = extent['ymax']  - crop[3]
    
    img_normed = norm(tiles)

    clas, bbox = predict_(model, img_normed.transpose(0, 3, 1, 2))
    preds = { }

    for idx in range(bbox.size()[0]): 
        preds[idx] = get_nms_preds(clas, bbox, idx, anchors)
    
    w, h = 90, 90
    pools = []
    numboxes = bbox.size()[0]
    side = math.sqrt(numboxes)

    for idx in range(numboxes): 
        i, j = idx//side, idx%side

        x = xmin + (j)*w
        y = ymax - (i+1)*h

        for pred in preds[idx]:
            objx = x + ((pred['x1'] + pred['x2']) / 2)*w
            objy = y + h - ((pred['y1'] + pred['y2']) / 2)*h
            pools.append({'x': objx, 'y': objy, 'category': pred['category'], 'score': pred['score']})

    if len(pools) > 0:
        result = project(geometries=pools, in_sr=3857, out_sr=4326)
        for i, p in enumerate(pools):
            p['SHAPE'] = dict(result[i])
            p['cycle']  = cycle

    return pools 
開發者ID:Esri,項目名稱:raster-deep-learning,代碼行數:39,代碼來源:util.py

示例3: detect_objects

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def detect_objects(model, tiles, extent, crop=(0, 0, 0, 0), cycle=1):
    xmin = extent['xmin']  + crop[0]
    ymin = extent['ymin']  + crop[1]
    xmax = extent['xmax']  - crop[2]
    ymax = extent['ymax']  - crop[3]
    
    img_normed = norm(tiles)

    clas, bbox = predict_(model, img_normed.transpose(0, 3, 1, 2))
    preds = { }

    for idx in range(bbox.size()[0]): 
        preds[idx] = get_nms_preds(clas, bbox, idx, anchors)
    
    w, h = 90, 90
    pools = []
    numboxes = bbox.size()[0]
    side = math.sqrt(numboxes)

    for idx in range(numboxes): 
        i, j = idx//side, idx%side

        x = xmin + (j)*w        # 0 + j*224
        y = ymax - (i+1)*h

        for pred in preds[idx]:
            objx = x + ((pred['x1'] + pred['x2']) / 2)*w
            objy = y + h - ((pred['y1'] + pred['y2']) / 2)*h
            pools.append({'x': objx, 'y': objy, 'category': pred['category'], 'score': pred['score']})

    if len(pools) > 0:
        #result = project(geometries=pools, in_sr=3857, out_sr=4326)
        for i, p in enumerate(pools):
            #p['SHAPE'] = dict(result[i])
            p['cycle'] = cycle

    return pools 
開發者ID:Esri,項目名稱:raster-deep-learning,代碼行數:39,代碼來源:util.py

示例4: load_image

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def load_image(file_path, input_height=128, input_width=None, output_height=128, output_width=None,
              crop_height=None, crop_width=None, is_random_crop=True, is_mirror=True, is_gray=False):
    
    if input_width is None:
      input_width = input_height
    if output_width is None:
      output_width = output_height
    if crop_width is None:
      crop_width = crop_height
    
    img = Image.open(file_path)
    if is_gray is False and img.mode is not 'RGB':
      img = img.convert('RGB')
    if is_gray and img.mode is not 'L':
      img = img.convert('L')
      
    if is_mirror and random.randint(0,1) is 0:
      img = ImageOps.mirror(img)    
      
    if input_height is not None:
      img = img.resize((input_width, input_height),Image.BICUBIC)
      
    if crop_height is not None:
      [w, h] = img.size
      if is_random_crop:
        #print([w,cropSize])
        cx1 = random.randint(0, w-crop_width)
        cx2 = w - crop_width - cx1
        cy1 = random.randint(0, h-crop_height) 
        cy2 = h - crop_height - cy1
      else:
        cx2 = cx1 = int(round((w-crop_width)/2.))
        cy2 = cy1 = int(round((h-crop_height)/2.))
      img = ImageOps.crop(img, (cx1, cy1, cx2, cy2))      
   
    img = img.resize((output_width, output_height),Image.BICUBIC)
    return img 
開發者ID:hhb072,項目名稱:IntroVAE,代碼行數:39,代碼來源:dataset.py

示例5: load_video_image

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def load_video_image(file_path, input_height=128, input_width=None, output_height=128, output_width=None,
              crop_height=None, crop_width=None, is_random_crop=True, is_mirror=True,
              is_gray=False, scale=1.0, is_scale_back=False):
    
    if input_width is None:
      input_width = input_height
    if output_width is None:
      output_width = output_height
    if crop_width is None:
      crop_width = crop_height
    
    img = Image.open(file_path)
    if is_gray is False and img.mode is not 'RGB':
      img = img.convert('RGB')
    if is_gray and img.mode is not 'L':
      img = img.convert('L')
      
    if is_mirror and random.randint(0,1) is 0:
      img = ImageOps.mirror(img)    
      
    if input_height is not None:
      img = img.resize((input_width, input_height),Image.BICUBIC)
      
    if crop_height is not None:
      [w, h] = img.size
      if is_random_crop:
        #print([w,cropSize])
        cx1 = random.randint(0, w-crop_width)
        cx2 = w - crop_width - cx1
        cy1 = random.randint(0, h-crop_height) 
        cy2 = h - crop_height - cy1
      else:
        cx2 = cx1 = int(round((w-crop_width)/2.))
        cy2 = cy1 = int(round((h-crop_height)/2.))
      img = ImageOps.crop(img, (cx1, cy1, cx2, cy2))
      
    #print(scale)
    img = img.resize((output_width, output_height),Image.BICUBIC)
    img_lr = img.resize((int(output_width/scale),int(output_height/scale)),Image.BICUBIC)
    if is_scale_back:
      return img_lr.resize((output_width, output_height),Image.BICUBIC), img
    else:
      return img_lr, img 
開發者ID:hhb072,項目名稱:WaveletSRNet,代碼行數:45,代碼來源:dataset.py

示例6: test_sanity

# 需要導入模塊: from PIL import ImageOps [as 別名]
# 或者: from PIL.ImageOps import crop [as 別名]
def test_sanity(self):

        ImageOps.autocontrast(hopper("L"))
        ImageOps.autocontrast(hopper("RGB"))

        ImageOps.autocontrast(hopper("L"), cutoff=10)
        ImageOps.autocontrast(hopper("L"), ignore=[0, 255])

        ImageOps.colorize(hopper("L"), (0, 0, 0), (255, 255, 255))
        ImageOps.colorize(hopper("L"), "black", "white")

        ImageOps.pad(hopper("L"), (128, 128))
        ImageOps.pad(hopper("RGB"), (128, 128))

        ImageOps.crop(hopper("L"), 1)
        ImageOps.crop(hopper("RGB"), 1)

        ImageOps.deform(hopper("L"), self.deformer)
        ImageOps.deform(hopper("RGB"), self.deformer)

        ImageOps.equalize(hopper("L"))
        ImageOps.equalize(hopper("RGB"))

        ImageOps.expand(hopper("L"), 1)
        ImageOps.expand(hopper("RGB"), 1)
        ImageOps.expand(hopper("L"), 2, "blue")
        ImageOps.expand(hopper("RGB"), 2, "blue")

        ImageOps.fit(hopper("L"), (128, 128))
        ImageOps.fit(hopper("RGB"), (128, 128))

        ImageOps.flip(hopper("L"))
        ImageOps.flip(hopper("RGB"))

        ImageOps.grayscale(hopper("L"))
        ImageOps.grayscale(hopper("RGB"))

        ImageOps.invert(hopper("L"))
        ImageOps.invert(hopper("RGB"))

        ImageOps.mirror(hopper("L"))
        ImageOps.mirror(hopper("RGB"))

        ImageOps.posterize(hopper("L"), 4)
        ImageOps.posterize(hopper("RGB"), 4)

        ImageOps.solarize(hopper("L"))
        ImageOps.solarize(hopper("RGB"))

        ImageOps.exif_transpose(hopper("L"))
        ImageOps.exif_transpose(hopper("RGB")) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:53,代碼來源:test_imageops.py


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