当前位置: 首页>>代码示例>>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;未经允许,请勿转载。