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


Python interpolation.rotate方法代码示例

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


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

示例1: xy_rotate_box

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def xy_rotate_box(cx,cy,w,h,angle):
    """
    绕 cx,cy点 w,h 旋转 angle 的坐标
    x_new = (x-cx)*cos(angle) - (y-cy)*sin(angle)+cx
    y_new = (x-cx)*sin(angle) + (y-cy)*sin(angle)+cy
    """
    
    cx    = float(cx)
    cy    = float(cy)
    w     = float(w)
    h     = float(h)
    angle = float(angle)
    x1,y1 = rotate(cx-w/2,cy-h/2,angle,cx,cy)
    x2,y2 = rotate(cx+w/2,cy-h/2,angle,cx,cy)
    x3,y3 = rotate(cx+w/2,cy+h/2,angle,cx,cy)
    x4,y4 = rotate(cx-w/2,cy+h/2,angle,cx,cy)
    return x1,y1,x2,y2,x3,y3,x4,y4 
开发者ID:bing1zhi2,项目名称:chinese_ocr,代码行数:19,代码来源:image.py

示例2: get_aligned_face

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def get_aligned_face(self, i, l_factor = 1.3):
        '''
        The second core function that converts the data from self.coordinates into an face image.
        '''
        frame = self.get(i)
        if i in self.coordinates:
            c, l, r = self.coordinates[i]
            l = int(l) * l_factor # fine-tuning the face zoom we really want
            dl_ = floor(np.sqrt(2) * l / 2) # largest zone even when rotated
            patch = self.get_image_slice(frame,
                                    floor(c[0] - dl_),
                                    floor(c[0] + dl_),
                                    floor(c[1] - dl_),
                                    floor(c[1] + dl_))
            rotated_patch = rotate(patch, -r, reshape=False)
            # note : dl_ is the center of the patch of length 2dl_
            return self.get_image_slice(rotated_patch,
                                    floor(dl_-l//2),
                                    floor(dl_+l//2),
                                    floor(dl_-l//2),
                                    floor(dl_+l//2))
        return frame


## Face prediction 
开发者ID:DariusAf,项目名称:MesoNet,代码行数:27,代码来源:pipeline.py

示例3: _augmentInstance

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def _augmentInstance(self, x0):
        # xy flip
        xf_x = np.flip(x0, 1)
        xf_y = np.flip(x0, 2)
        xf_xy = np.flip(xf_x, 2)
        # xy shift
        xs1 = scipy.ndimage.shift(x0, (0, 4, 4), mode='constant')
        xs2 = scipy.ndimage.shift(x0, (0, -4, 4), mode='constant')
        xs3 = scipy.ndimage.shift(x0, (0, 4, -4), mode='constant')
        xs4 = scipy.ndimage.shift(x0, (0, -4, -4), mode='constant')

        # small rotations
        R = []
        for ang in range(6, 360, 6):
            R.append(rotate(x0, ang, axes=(1, 2), mode='reflect', reshape=False))
        X = [x0, xf_x, xf_y, xf_xy, xs1, xs2, xs3, xs4] + R

        # remove instances which are cropped out of bounds of scan
        Res = []
        for x in X:
            if (x.shape[0] != 0) and (x.shape[1] != 0) and (x.shape[2] != 0):
                Res.append(x)
        return Res 
开发者ID:ymirsky,项目名称:CT-GAN,代码行数:25,代码来源:datasetBuilder.py

示例4: get_rorate

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def get_rorate(boxes,im,degree=0):
    """
    获取旋转角度后的box及im
    """
    imgW,imgH = im.size
    newBoxes = []       
    for line in boxes:
         cx0,cy0 = imgW/2.0,imgH/2.0 
         x1,y1,x2,y2,x3,y3,x4,y4 = xy_rotate_box(**line)
         x1,y1  = rotate(x1,y1,-degree/180*np.pi,cx0,cy0)
         x2,y2  = rotate(x2,y2,-degree/180*np.pi,cx0,cy0)
         x3,y3  = rotate(x3,y3,-degree/180*np.pi,cx0,cy0)
         x4,y4  = rotate(x4,y4,-degree/180*np.pi,cx0,cy0)
         box = (x1,y1,x2,y2,x3,y3,x4,y4)
         degree_,w_,h_,cx_,cy_ = solve(box)
         newLine = {'angle':degree_,'w':w_,'h':h_,'cx':cx_,'cy':cy_}
         newBoxes.append(newLine)
    return im.rotate(degree,center=(imgW/2.0,imgH/2.0 )),newBoxes 
开发者ID:bing1zhi2,项目名称:chinese_ocr,代码行数:20,代码来源:image.py

示例5: __call__

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def __call__(self, img):
        """
        Args:
            img (numpy.ndarray (H x W x C)): Image to be rotated.

        Returns:
            img (numpy.ndarray (H x W x C)): Rotated image.
        """

        # order=0 means nearest-neighbor type interpolation
        return itpl.rotate(img, self.angle, reshape=False, prefilter=False, order=0) 
开发者ID:miraiaroha,项目名称:ACAN,代码行数:13,代码来源:transforms.py

示例6: augment

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def augment(sample, target, bboxes, coord, ifflip = True, ifrotate=True, ifswap = True):
    #                     angle1 = np.random.rand()*180
    if ifrotate:
        validrot = False
        counter = 0
        while not validrot:
            newtarget = np.copy(target)
            angle1 = np.random.rand()*180
            size = np.array(sample.shape[2:4]).astype('float')
            rotmat = np.array([[np.cos(angle1/180*np.pi),-np.sin(angle1/180*np.pi)],[np.sin(angle1/180*np.pi),np.cos(angle1/180*np.pi)]])
            newtarget[1:3] = np.dot(rotmat,target[1:3]-size/2)+size/2
            if np.all(newtarget[:3]>target[3]) and np.all(newtarget[:3]< np.array(sample.shape[1:4])-newtarget[3]):
                validrot = True
                target = newtarget
                sample = rotate(sample,angle1,axes=(2,3),reshape=False)
                coord = rotate(coord,angle1,axes=(2,3),reshape=False)
                for box in bboxes:
                    box[1:3] = np.dot(rotmat,box[1:3]-size/2)+size/2
            else:
                counter += 1
                if counter ==3:
                    break
    if ifswap:
        if sample.shape[1]==sample.shape[2] and sample.shape[1]==sample.shape[3]:
            axisorder = np.random.permutation(3)
            sample = np.transpose(sample,np.concatenate([[0],axisorder+1]))
            coord = np.transpose(coord,np.concatenate([[0],axisorder+1]))
            target[:3] = target[:3][axisorder]
            bboxes[:,:3] = bboxes[:,:3][:,axisorder]
            
    if ifflip:
#         flipid = np.array([np.random.randint(2),np.random.randint(2),np.random.randint(2)])*2-1
        flipid = np.array([1,np.random.randint(2),np.random.randint(2)])*2-1
        sample = np.ascontiguousarray(sample[:,::flipid[0],::flipid[1],::flipid[2]])
        coord = np.ascontiguousarray(coord[:,::flipid[0],::flipid[1],::flipid[2]])
        for ax in range(3):
            if flipid[ax]==-1:
                target[ax] = np.array(sample.shape[ax+1])-target[ax]
                bboxes[:,ax]= np.array(sample.shape[ax+1])-bboxes[:,ax]
    return sample, target, bboxes, coord 
开发者ID:uci-cbcl,项目名称:DeepLung,代码行数:42,代码来源:data.py

示例7: testtime_augmentation

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def testtime_augmentation(image, label):
    labels = []
    images = []
    rotations = [0]
    flips = [[0,0],[1,0],[0,1],[1,1]]
    shifts = [[0,0]]
    zooms = [1]

    for r in rotations:
        for f in flips:
            for s in shifts:
                for z in zooms:
                    image2 = np.array(image)
                    if f[0]:
                        image2[:,:] = image2[::-1,:]
                    if f[1]:
                        image2 = image2.transpose(1,0)
                        image2[:,:] = image2[::-1,:]
                        image2 = image2.transpose(1,0)
                    #rotate(image2, r, reshape=False, output=image2)
                    #image3 = zoom(image2, [z,z])
                    #image3 = crop_or_pad(image3, P.INPUT_SIZE, 0)
                    #image2 = image3
                    # #shift(image2, [s[0],s[1]], output=image2)
                    images.append([image2]) #Adds color channel dimension!
                    labels.append(label)

    return images, labels 
开发者ID:gzuidhof,项目名称:luna16,代码行数:30,代码来源:augment.py

示例8: data_augmentation

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def data_augmentation(image):
    # Input should be ONE image with shape: (L, W, CH)
    options = ["gaussian_smooth", "rotate", "zoom", "adjust_gamma"]  
    # Probabilities for each augmentation were arbitrarily assigned 
    which_option = np.random.choice(options)
    if which_option == "gaussian_smooth": 
        sigma = np.random.uniform(0.2, 1.0)
        image = gaussian_filter(image, sigma)
    elif which_option == "zoom": 
      # Assumes image is square
        min_crop = int(image.shape[0]*0.85)
        max_crop = int(image.shape[0]*0.95)
        crop_size = np.random.randint(min_crop, max_crop) 
        crop = crop_center(image, crop_size, crop_size)
        if crop.shape[-1] == 1: crop = crop[:,:,0]
        image = scipy.misc.imresize(crop, image.shape) 
    elif which_option == "rotate":
        angle = np.random.uniform(-15, 15)
        image = rotate(image, angle, reshape=False)
    elif which_option == "adjust_gamma": 
        image = image / 255. 
        image = exposure.adjust_gamma(image, np.random.uniform(0.75,1.25))
        image = image * 255. 
    if len(image.shape) == 2: image = np.expand_dims(image, axis=2)
    return image 

# == I/O == # 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:29,代码来源:TrainClassifierEnsemble.py

示例9: data_augmentation

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def data_augmentation(image):
    # Input should be ONE image with shape: (L, W, CH)
    options = ["gaussian_smooth", "vertical_flip", "rotate", "zoom", "adjust_gamma"] 
    # Probabilities for each augmentation were arbitrarily assigned 
    which_option = np.random.choice(options)
    if which_option == "vertical_flip":
        image = np.fliplr(image)
    if which_option == "horizontal_flip": 
        image = np.flipud(image) 
    elif which_option == "gaussian_smooth": 
        sigma = np.random.uniform(0.2, 1.0)
        image = gaussian_filter(image, sigma)
    elif which_option == "zoom": 
      # Assumes image is square
        min_crop = int(image.shape[0]*0.85)
        max_crop = int(image.shape[0]*0.95)
        crop_size = np.random.randint(min_crop, max_crop) 
        crop = crop_center(image, crop_size, crop_size)
        if crop.shape[-1] == 1: crop = crop[:,:,0]
        image = scipy.misc.imresize(crop, image.shape) 
    elif which_option == "rotate":
        angle = np.random.uniform(-15, 15)
        image = rotate(image, angle, reshape=False)
    elif which_option == "adjust_gamma": 
        image = image / 255. 
        image = exposure.adjust_gamma(image, np.random.uniform(0.75,1.25))
        image = image * 255. 
    if len(image.shape) == 2: image = np.expand_dims(image, axis=2)
    return image 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:31,代码来源:PredictOneClassifier.py

示例10: image_rotate

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def image_rotate(images, angles):
    rotated_images = np.zeros_like(images)
    for i in range(images.shape[0]):
        rotated_images[i] = rotate(images[i], angles[i]*180.0/np.pi, axes=(1, 0),
                                   reshape=False, order=0,
                                   mode='constant', cval=0.0, prefilter=False)
    return rotated_images 
开发者ID:AshishBora,项目名称:ambient-gan,代码行数:9,代码来源:im_rotate.py

示例11: image_rotate_grad

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def image_rotate_grad(op, grad):
    images = op.inputs[0] # the first argument (normally you need those to calculate the gradient, like the gradient of x^2 is 2x. )
    angles = op.inputs[1] # the second argument
    grad_reshaped = tf.reshape(grad, images.get_shape())
    return tf.contrib.image.rotate(grad_reshaped, -angles), None 
开发者ID:AshishBora,项目名称:ambient-gan,代码行数:7,代码来源:im_rotate.py

示例12: __call__

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def __call__(self, img):
        """
        Args:
            img (numpy.ndarray (C x H x W)): Image to be rotated.

        Returns:
            img (numpy.ndarray (C x H x W)): Rotated image.
        """

        # order=0 means nearest-neighbor type interpolation
        return itpl.rotate(img, self.angle, reshape=False, prefilter=False, order=0) 
开发者ID:dwofk,项目名称:fast-depth,代码行数:13,代码来源:transforms.py

示例13: estimate_skew_angle

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def estimate_skew_angle(self, image, angles):
        
        estimates = []
        
        for a in angles:
            v = mean(interpolation.rotate(
                image, a, order=0, mode='constant'), axis=1)
            v = var(v)
            estimates.append((v, a))
        if self.parameter['debug'] > 0:
            plot([y for x, y in estimates], [x for x, y in estimates])
            ginput(1, self.parameter['debug'])
        _, a = max(estimates)
        return a 
开发者ID:OCR-D,项目名称:ocrd_anybaseocr,代码行数:16,代码来源:ocrd_anybaseocr_deskew.py

示例14: skew_correct

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def skew_correct(self, ):
        best_score = -1
        for a in np.linspace(-2, 2, 21):
            data = inter.rotate(self.imgarr, a, reshape=0, order=0)
            hist = np.sum(data, axis=1)
            score = np.sum((hist[1:] - hist[:-1]) ** 2)
            if score > best_score:
                self.angle = float(a)
                self.imgarr = data
                best_score = score

        print("Angle: ", self.angle)
        self.ht, self.wd = self.imgarr.shape
        self.img = im.fromarray(255 * (1 - self.imgarr).astype("uint8")).convert("RGB") 
开发者ID:rakeshvar,项目名称:chamanti_ocr,代码行数:16,代码来源:line_seperate.py

示例15: random_rotation

# 需要导入模块: from scipy.ndimage import interpolation [as 别名]
# 或者: from scipy.ndimage.interpolation import rotate [as 别名]
def random_rotation(image, angle_range=(0, 180)):
    h, w, _ = image.shape
    angle = np.random.randint(*angle_range)
    image = rotate(image, angle)
    image = resize(image, (h, w))
    return image 
开发者ID:xkumiyu,项目名称:numpy-data-augmentation,代码行数:8,代码来源:process_image.py


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