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


Python Image.FLIP_LEFT_RIGHT属性代码示例

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


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

示例1: flip_and_save

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def flip_and_save(self, image_path):
        """
        flip the image by the path and save the flipped image with suffix 'flip'
        :param path: the path of specific image
        :return: the path of saved image
        """
        [image_name, image_ext] = os.path.splitext(os.path.basename(image_path))
        image_dir = os.path.dirname(image_path)
        saved_image_path = os.path.join(image_dir, image_name + '_flip' + image_ext)
        try:
            flipped_image = Image.open(saved_image_path)
        except:
            flipped_image = Image.open(image_path)
            flipped_image = flipped_image.transpose(Image.FLIP_LEFT_RIGHT)
            flipped_image.save(saved_image_path, 'png')
        return saved_image_path 
开发者ID:tonysy,项目名称:Deep-Feature-Flow-Segmentation,代码行数:18,代码来源:imdb.py

示例2: flip_and_save_func

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def flip_and_save_func(image_path):
    """
    flip the image by the path and save the flipped image with suffix 'flip'
    :param path: the path of specific image
    :return: the path of saved image
    """
    [image_name, image_ext] = os.path.splitext(os.path.basename(image_path))
    image_dir = os.path.dirname(image_path)
    saved_image_path = os.path.join(image_dir, image_name + '_flip' + image_ext)
    try:
        flipped_image = Image.open(saved_image_path)
    except:
        flipped_image = Image.open(image_path)
        flipped_image = flipped_image.transpose(Image.FLIP_LEFT_RIGHT)
        flipped_image.save(saved_image_path, 'png')
    return saved_image_path 
开发者ID:tonysy,项目名称:Deep-Feature-Flow-Segmentation,代码行数:18,代码来源:image.py

示例3: update_orientation

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def update_orientation(image):
    exif_orientation_tag = 0x0112
    if hasattr(image, '_getexif'):
        exif = image._getexif()
        if exif != None and exif_orientation_tag in exif:
            orientation = exif.get(exif_orientation_tag, 1)
            log_msg('Image has EXIF Orientation: ' + str(orientation))
            # orientation is 1 based, shift to zero based and flip/transpose based on 0-based values
            orientation -= 1
            if orientation >= 4:
                image = image.transpose(Image.TRANSPOSE)
            if orientation == 2 or orientation == 3 or orientation == 6 or orientation == 7:
                image = image.transpose(Image.FLIP_TOP_BOTTOM)
            if orientation == 1 or orientation == 2 or orientation == 5 or orientation == 6:
                image = image.transpose(Image.FLIP_LEFT_RIGHT)
    return image 
开发者ID:Azure-Samples,项目名称:Custom-vision-service-iot-edge-raspberry-pi,代码行数:18,代码来源:predict-amd64.py

示例4: pil_random_crop

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def pil_random_crop(img, scale_size, output_size, params=None):
    img = pilresize(img, scale_size)
    th = output_size
    tw = output_size
    if params is None:
        w, h = img.size
        if w == tw and h == th:
            return img
        i = random.randint(0, h - th)
        j = random.randint(0, w - tw)
        flip = random.random()<0.5
    else:
        i,j,flip = params
    img = img.crop((j, i, j + tw, i + th))
    if flip:
        img = img.transpose(Image.FLIP_LEFT_RIGHT)

    return img, [i, j, flip] 
开发者ID:gurkirt,项目名称:2D-kinectics,代码行数:20,代码来源:kinetics.py

示例5: FlipImgs

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def FlipImgs(xmb, ymb):
    bs, ci, hi, wi = xmb.shape	
    xmb_out = np.zeros((bs,ci,hi,wi),dtype='uint8')
    ymb_out = np.zeros((bs,ci,hi,wi),dtype='uint8')
    for i in xrange(bs):
        x_img = xmb[i,:,:,:]
        y_img = ymb[i,:,:,:]
        if np.random.rand(1) > 0.5:
            x_img = convert_img_back(x_img)
            y_img = convert_img_back(y_img)

            x_img = Image.fromarray(x_img)	
            y_img = Image.fromarray(y_img)	
		
            x_img = x_img.transpose(Image.FLIP_LEFT_RIGHT)
            y_img = y_img.transpose(Image.FLIP_LEFT_RIGHT)
		
            x_img = convert_img(np.array(x_img))
            y_img = convert_img(np.array(y_img))
	xmb_out[i,:,:,:] = x_img 
	ymb_out[i,:,:,:] = y_img 
    xmb_out = xmb_out.reshape([bs,ci,hi,wi]) 
    ymb_out = ymb_out.reshape([bs,ci,hi,wi]) 
    return xmb_out, ymb_out 
开发者ID:WANG-Chaoyue,项目名称:EvolutionaryGAN,代码行数:26,代码来源:data_utils.py

示例6: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, img, labelmap=None, maskmap=None):
        assert isinstance(img, Image.Image)
        assert labelmap is None or isinstance(labelmap, Image.Image)
        assert maskmap is None or isinstance(maskmap, Image.Image)

        if random.random() > self.ratio:
            return img, labelmap, maskmap

        img = img.transpose(Image.FLIP_LEFT_RIGHT)
        if labelmap is not None:
            labelmap = labelmap.transpose(Image.FLIP_LEFT_RIGHT)

        if maskmap is not None:
            maskmap = maskmap.transpose(Image.FLIP_LEFT_RIGHT)

        return img, labelmap, maskmap 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:18,代码来源:pil_aug_transforms.py

示例7: transform_xy

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def transform_xy(self, x, y, rng):
        if rng.uniform(0.0, 1.0) < self.chance:

            x = x if not isinstance(x, ImageType) else x.transpose(Image.FLIP_LEFT_RIGHT)
            y = y if not isinstance(y, ImageType) else y.transpose(Image.FLIP_LEFT_RIGHT)
         
        return x, y 
开发者ID:mme,项目名称:vergeml,代码行数:9,代码来源:flip_horizontal.py

示例8: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, sample):
        img = sample['image']
        mask = sample['label']
        if random.random() < 0.5:
            img = img.transpose(Image.FLIP_LEFT_RIGHT)
            mask = mask.transpose(Image.FLIP_LEFT_RIGHT)

        return {'image': img,
                'label': mask} 
开发者ID:songdejia,项目名称:DeepLab_v3_plus,代码行数:11,代码来源:transform.py

示例9: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [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

示例10: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, img):
        """
        Args:
            img (PIL.Image): Image to be flipped.

        Returns:
            PIL.Image: Randomly flipped image.
        """
        if random.random() < 0.5:
            return np.array(img[:, :, ::-1]) #.transpose(Image.FLIP_LEFT_RIGHT)
        return img 
开发者ID:uci-cbcl,项目名称:DeepLung,代码行数:13,代码来源:transforms.py

示例11: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, sample):
        image, depth = sample['image'], sample['depth']

        if not _is_pil_image(image):
            raise TypeError(
                'img should be PIL Image. Got {}'.format(type(img)))
        if not _is_pil_image(depth):
            raise TypeError(
                'img should be PIL Image. Got {}'.format(type(depth)))

        if random.random() < 0.5:
            image = image.transpose(Image.FLIP_LEFT_RIGHT)
            depth = depth.transpose(Image.FLIP_LEFT_RIGHT)

        return {'image': image, 'depth': depth} 
开发者ID:JunjH,项目名称:Visualizing-CNNs-for-monocular-depth-estimation,代码行数:17,代码来源:nyu_transform.py

示例12: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, imgmap):
        if self.consistent:
            if random.random() < self.threshold:
                return [i.transpose(Image.FLIP_LEFT_RIGHT) for i in imgmap]
            else:
                return imgmap
        else:
            result = []
            for i in imgmap:
                if random.random() < self.threshold:
                    result.append(i.transpose(Image.FLIP_LEFT_RIGHT))
                else:
                    result.append(i) 
            assert len(result) == len(imgmap)
            return result 
开发者ID:TengdaHan,项目名称:DPC,代码行数:17,代码来源:augmentation.py

示例13: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, images, mask):
        """Randomly flips image and their mask left to right.

        Args:
          images: the PIL.Image images to transform.
          mask: the PIL.Image mask to transform.

        Returns:
          The PIL.Image (images, mask) tuple with either images and mask flipped or none of them flipped.
        """

        if random.random() < self.p:
            return [v.transpose(Image.FLIP_LEFT_RIGHT) for v in images], mask.transpose(Image.FLIP_LEFT_RIGHT)
        else:
            return images, mask 
开发者ID:mapbox,项目名称:robosat,代码行数:17,代码来源:transforms.py

示例14: train_mapper

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def train_mapper(sample):
    img_path, label, crop_size, resize_size = sample
    try:
        img = Image.open(img_path)
        # 统一图片大小
        img = img.resize((resize_size, resize_size), Image.ANTIALIAS)
        # 随机水平翻转
        r1 = random.random()
        if r1 > 0.5:
            img = img.transpose(Image.FLIP_LEFT_RIGHT)
        # 随机垂直翻转
        r2 = random.random()
        if r2 > 0.5:
            img = img.transpose(Image.FLIP_TOP_BOTTOM)
        # 随机角度翻转
        r3 = random.randint(-3, 3)
        img = img.rotate(r3, expand=False)
        # 随机裁剪
        r4 = random.randint(0, int(resize_size - crop_size))
        r5 = random.randint(0, int(resize_size - crop_size))
        box = (r4, r5, r4 + crop_size, r5 + crop_size)
        img = img.crop(box)
        # 把图片转换成numpy值
        img = np.array(img).astype(np.float32)
        # 转换成CHW
        img = img.transpose((2, 0, 1))
        # 转换成BGR
        img = img[(2, 1, 0), :, :] / 255.0
        return img, int(label)
    except:
        print("%s 该图片错误,请删除该图片并重新创建图像数据列表" % img_path)


# 获取训练的reader 
开发者ID:yeyupiaoling,项目名称:LearnPaddle2,代码行数:36,代码来源:reader.py

示例15: __call__

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import FLIP_LEFT_RIGHT [as 别名]
def __call__(self, img, mask):
        if random.random() < 0.5:
            return img.transpose(Image.FLIP_LEFT_RIGHT), mask.transpose(Image.FLIP_LEFT_RIGHT)
        return img, mask 
开发者ID:zhechen,项目名称:PLARD,代码行数:6,代码来源:augmentations.py


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