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


Python transform.rotate方法代码示例

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


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

示例1: handle_alphabet

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def handle_alphabet(folder):
    print('{}...'.format(folder.split('/')[-1]))
    for rotate in [0, 90, 180, 270]:
        # Create new folders for each augmented alphabet
        mkdir(f'{folder}.{rotate}')
        for root, character_folders, _ in os.walk(folder):
            for character_folder in character_folders:
                # For each character folder in an alphabet rotate and resize all of the images and save
                # to the new folder
                handle_characters(folder, root + '/' + character_folder, rotate)
                # return

    # Delete original alphabet
    rmdir(folder)


# Clean up previous extraction 
开发者ID:oscarknagg,项目名称:few-shot,代码行数:19,代码来源:prepare_omniglot.py

示例2: _rotate_bboxes

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _rotate_bboxes(self, bbox_list, r_angle, hm):
        """ rotate augmentation
        """ 
        #   angle 2 radian
        radian = r_angle * math.pi / 180
        #   rotation matrix
        rotation_mat = np.array([[np.cos(radian), np.sin(radian)],
                                    [-np.sin(radian), np.cos(radian)]])
        #   rotate the bounding box
        del_ind = []
        for ind in range(bbox_list.shape[0]):
            rel_pos = np.dot(
                rotation_mat, bbox_list[ind, :2]-np.round(np.array(hm.shape[:2])/2.0))
            bbox_list[ind, :2] = rel_pos + np.round(np.array(hm.shape[:2])/2.0)
            bbox_list[ind, 2:4] = np.dot(
                np.abs(rotation_mat), bbox_list[ind, 2:4])
            if (bbox_list[ind] < 0).any() or (bbox_list[ind, :2] > hm.shape[:2]).any():
                del_ind.append(ind)
        bbox_list = np.delete(bbox_list, del_ind, 0)
        return bbox_list 
开发者ID:mpskex,项目名称:Convolutional-Pose-Machine-tf,代码行数:22,代码来源:datagen.py

示例3: _augment

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _augment(self, img, hm, mask, max_rotation=30, angle=None):
        """ # TODO : IMPLEMENT DATA AUGMENTATION
        """
        if random.choice([0, 1]):
            if angle==None:
                r_angle = np.random.randint(-1 * max_rotation, max_rotation)
            else:
                r_angle = angle
            '''
            #   old version
            img = transform.rotate(img, r_angle, preserve_range=True)
            hm = transform.rotate(hm, r_angle)
            rmask = transform.rotate(rmask, r_angle)
            '''
            img = self._rotate_img(img, r_angle)
            hm = self._rotate_hm(hm, r_angle)
            mask = self._rotate_mask(mask, r_angle)
        return img, hm, mask

    # ----------------------- Batch Generator ---------------------------------- 
开发者ID:mpskex,项目名称:Convolutional-Pose-Machine-tf,代码行数:22,代码来源:datagen_coco.py

示例4: polar_transform

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def polar_transform(img, mask, img_size, mode='train'):
    random_rotate_seed = 3 * 90
    width_shift = 0
    heigth_shift = 0

    if mode == 'train':
        random_rotate_seed = random.randint(0,3) * 90
        width_shift = random.randint(0,40) - 20
        heigth_shift = random.randint(0,40) - 20
    img = rotate(cv2.linearPolar(img, (img_size / 2 + width_shift, img_size / 2 + heigth_shift), img_size / 2 - 20,
                                 cv2.WARP_FILL_OUTLIERS), random_rotate_seed)

    mask = rotate(cv2.linearPolar(mask, (img_size / 2 + width_shift, img_size / 2 + heigth_shift), img_size / 2 - 20,
                                  cv2.WARP_FILL_OUTLIERS), random_rotate_seed)

    return img, mask 
开发者ID:EmmaW8,项目名称:pOSAL,代码行数:18,代码来源:data_generator.py

示例5: transform_img__

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def transform_img__(self, img, fn, emotion):
        self.images[fn] = {'Image': img, 'Emotion': emotion}                                            # Store original
        counter = 0

        self.images["Trans" + str(counter) + "_" + fn] = {'Image': np.fliplr(img), 'Emotion': emotion}  # FLIP the image
        counter += 1

        for deg in range(-10, 15, 5):                                        # ROTATE to be robust to camera orientation
            if deg == 0:
                continue

            self.images["Trans" + str(counter) + "_" + fn] = {'Image': tf.rotate(img, deg), 'Emotion': emotion}
            counter += 1

        lenX, lenY = img.shape                                                           # CROP based on rough heuristic
        for crop_size in range(8, 14, 2):
            cropped = img[lenX / crop_size: - lenX / crop_size, lenY / crop_size: - lenY / crop_size]
            self.images["Trans" + str(counter) + "_" + fn] = {'Image': cropped, 'Emotion': emotion}
            counter += 1

        for i in range(2):                                           # SCALE down images (random factor btw 1.1 to 1.21)
            scale_factor = math.sqrt(1.1) ** np.random.randint(2, 5)
            scaled_img = tf.warp(img, tf.AffineTransform(scale=(scale_factor, scale_factor)))
            self.images["Trans" + str(counter) + "_" + fn] = {'Image': scaled_img, 'Emotion': emotion}
            counter += 1 
开发者ID:muxspace,项目名称:facial_expressions,代码行数:27,代码来源:JN721.py

示例6: augmentation

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def augmentation(image, org_width=160,org_height=224, width=190, height=262):
    max_angle=20
    image=resize(image,(width,height))

    angle=np.random.randint(max_angle)
    if np.random.randint(2):
        angle=-angle
    image=rotate(image,angle,resize=True)

    xstart=np.random.randint(width-org_width)
    ystart=np.random.randint(height-org_height)
    image=image[xstart:xstart+org_width,ystart:ystart+org_height]

    if np.random.randint(2):
        image=cv2.flip(image,1)
    
    if np.random.randint(2):
        image=cv2.flip(image,0)
    # image=resize(image,(org_width,org_height))

    print(image.shape)
    plt.imshow(image)
    plt.show() 
开发者ID:yihui-he,项目名称:u-net,代码行数:25,代码来源:submission.py

示例7: rotate_images

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def rotate_images(file_path, degrees_of_rotation, lst_imgs):
    '''
    Rotates image based on a specified amount of degrees

    INPUT
        file_path: file path to the folder containing images.
        degrees_of_rotation: Integer, specifying degrees to rotate the
        image. Set number from 1 to 360.
        lst_imgs: list of image strings.

    OUTPUT
        Images rotated by the degrees of rotation specififed.
    '''

    for l in lst_imgs:
        img = io.imread(file_path + str(l) + '.jpeg')
        img = rotate(img, degrees_of_rotation)
        io.imsave(file_path + str(l) + '_' + str(degrees_of_rotation) + '.jpeg', img) 
开发者ID:llSourcell,项目名称:AI_in_Medicine_Clinical_Imaging_Classification,代码行数:20,代码来源:rotate_images.py

示例8: deskew

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def deskew(self):

        img = io.imread(self.input_file)
        res = self.skew_obj.process_single_file()
        angle = res['Estimated Angle']

        if angle >= 0 and angle <= 90:
            rot_angle = angle - 90 + self.r_angle
        if angle >= -45 and angle < 0:
            rot_angle = angle - 90 + self.r_angle
        if angle >= -90 and angle < -45:
            rot_angle = 90 + angle + self.r_angle

        rotated = rotate(img, rot_angle, resize=True)

        if self.display_image:
            self.display(rotated)

        if self.output_file:
            self.saveImage(rotated*255) 
开发者ID:kakul,项目名称:Alyn,代码行数:22,代码来源:deskew.py

示例9: augment_inplane_gen

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def augment_inplane_gen(xyz_id,img,img_r,depth_rend,mask,isYCB=False,step=10):
    depth_mask = (depth_rend>0).astype(np.float)
    for rot in np.arange(step,360,step):
        xyz_fn =  os.path.join(xyz_dir,"{:06d}_{:03d}.npy".format(xyz_id,rot))
        img_r_rot = rotate((img_r/255).astype(np.float32), rot,resize=True,cval=0)*255
        img_rot = rotate((img/255).astype(np.float32), rot,resize=True,cval=0.5)*255
        depth_rot = rotate(depth_mask, rot,resize=True)

        if(isYCB):
            mask_rot = rotate(mask.astype(np.float32), rot,resize=True)
        vu_box = np.where(depth_rot>0)
        bbox_t = np.array([np.min(vu_box[0]),np.min(vu_box[1]),np.max(vu_box[0]),np.max(vu_box[1])])
        if(isYCB):img_npy = np.zeros((bbox_t[2]-bbox_t[0],bbox_t[3]-bbox_t[1],7),np.uint8)
        else:img_npy = np.zeros((bbox_t[2]-bbox_t[0],bbox_t[3]-bbox_t[1],6),np.uint8)
        img_npy[:,:,:3]=[128,128,128]
        img_npy[:,:,:3]=img_rot[bbox_t[0]:bbox_t[2],bbox_t[1]:bbox_t[3]]
        img_npy[:,:,3:6]=img_r_rot[bbox_t[0]:bbox_t[2],bbox_t[1]:bbox_t[3]]
        if(isYCB):
            img_npy[:,:,6]=mask_rot[bbox_t[0]:bbox_t[2],bbox_t[1]:bbox_t[3]]
        
        data=img_npy
        max_axis=max(data.shape[0],data.shape[1])
        if(max_axis>128):                
                scale = 128.0/max_axis 
                new_shape=np.array([data.shape[0]*scale+0.5,data.shape[1]*scale+0.5]).astype(np.int) 
                new_data = np.zeros((new_shape[0],new_shape[1],data.shape[2]),data.dtype)
                new_data[:,:,:3] = resize( (data[:,:,:3]/255).astype(np.float32),(new_shape[0],new_shape[1]))*255
                new_data[:,:,3:6] = resize( (data[:,:,3:6]/255).astype(np.float32),(new_shape[0],new_shape[1]))*255
                if(data.shape[2]>6):
                    new_data[:,:,6:] = (resize(data[:,:,6:],(new_shape[0],new_shape[1]))>0.5).astype(np.uint8)
        else:
            new_data=data
        np.save(xyz_fn,new_data) 
开发者ID:kirumang,项目名称:Pix2Pose,代码行数:35,代码来源:2_2_render_pix2pose_training.py

示例10: _load_sample

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _load_sample(self, sample, text_only):
        loader = PageXMLDatasetLoader(self.mode, self._non_existing_as_empty, self.text_index, self.skip_invalid)
        image_path, xml_path = sample

        img = None
        if self.mode == DataSetMode.PREDICT or self.mode == DataSetMode.TRAIN or self.mode == DataSetMode.PRED_AND_EVAL:
            img = np.array(Image.open(image_path))

        for sample in loader.load(image_path, xml_path):
            text = sample["text"]
            orientation = sample["orientation"]

            if not text_only and (self.mode == DataSetMode.PREDICT or self.mode == DataSetMode.TRAIN or self.mode == DataSetMode.PRED_AND_EVAL):
                ly, lx = img.shape[:2]

                line_img = PageXMLDataset.cutout(img, sample['coords'], lx / sample['img_width'])

                # rotate by orientation angle in clockwise direction to correct present skew
                # (skimage rotates in counter-clockwise direction)
                if orientation and orientation % 360 != 0:
                    line_img = rotate(line_img, orientation*-1, resize=True, mode='constant', cval=line_img.max(), preserve_range=True).astype(np.uint8)

                # add padding as required from normal files
                if self.args.get('pad', None):
                    pad = self.args['pad']
                    img = np.pad(img, pad, mode='constant', constant_values=img.max())
            else:
                line_img = None

            yield line_img, text 
开发者ID:Calamari-OCR,项目名称:calamari,代码行数:32,代码来源:dataset.py

示例11: handle_characters

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def handle_characters(alphabet_folder, character_folder, rotate):
    for root, _, character_images in os.walk(character_folder):
        character_name = root.split('/')[-1]
        mkdir(f'{alphabet_folder}.{rotate}/{character_name}')
        for img_path in character_images:
            # print(root+'/'+img_path)
            img = io.imread(root+'/'+img_path)
            img = transform.rotate(img, angle=rotate)
            img = transform.resize(img, output_shape, anti_aliasing=True)
            img = (img - img.min()) / (img.max() - img.min())
            # print(img.min(), img.max())
            # print(f'{alphabet_folder}.{rotate}/{character_name}/{img_path}')
            io.imsave(f'{alphabet_folder}.{rotate}/{character_name}/{img_path}', img)
            # return 
开发者ID:oscarknagg,项目名称:few-shot,代码行数:16,代码来源:prepare_omniglot.py

示例12: turn_filename_into_image

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def turn_filename_into_image(filenames, batch_size, width, height, img_dir):
    
    empty_x = []
    rot_value = random.randint(-20,20)
    flip_lr = bool(random.getrandbits(1))
    flip_ud = bool(random.getrandbits(1))
    
    for name in filenames:
        image_x = img_to_array(load_img(img_dir + name, target_size=(width, height)))
        image_x = np.array(image_x, dtype='float32')
        image_x = (1.0/(255./2))*image_x - 1
     
        image_x = rotate(image_x, rot_value, mode='reflect')

        if flip_lr:
            image_x = np.fliplr(image_x)
        
        empty_x.append(image_x)
        
    empty_x = np.array(empty_x, dtype='float32')
    lab_batch = rgb2lab(empty_x)
    X_batch = lab_batch[:,:,:,0] / 100
    X_batch = X_batch.reshape(X_batch.shape+(1,))
    Y_batch = lab_batch[:,:,:,1:] / 128
    
    return np.array(X_batch, dtype='float32'), np.array(Y_batch, dtype='float32') 
开发者ID:emilwallner,项目名称:Coloring-greyscale-images,代码行数:28,代码来源:data_utils.py

示例13: _rotate_img

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _rotate_img(self, img, r_angle):
        """ rotate augmentation
        """
        img = transform.rotate(img, r_angle, preserve_range=True)
        return img 
开发者ID:mpskex,项目名称:Convolutional-Pose-Machine-tf,代码行数:7,代码来源:datagen.py

示例14: _rotate_hm

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _rotate_hm(self, _map, r_angle):
        """ rotate augmentation
        """
        _map[:, :, :-1] = transform.rotate(_map[:, :, :-1], r_angle)
        _map[:, :, -1] = transform.rotate(_map[:, :, -1], r_angle, cval=1)

        return _map 
开发者ID:mpskex,项目名称:Convolutional-Pose-Machine-tf,代码行数:9,代码来源:datagen.py

示例15: _rotate_mask

# 需要导入模块: from skimage import transform [as 别名]
# 或者: from skimage.transform import rotate [as 别名]
def _rotate_mask(self, _map, r_angle):
        """ rotate augmentation
        """
        _map = transform.rotate(_map, r_angle)
        return _map 
开发者ID:mpskex,项目名称:Convolutional-Pose-Machine-tf,代码行数:7,代码来源:datagen.py


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