當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。