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


Python misc.imrotate函数代码示例

本文整理汇总了Python中scipy.misc.imrotate函数的典型用法代码示例。如果您正苦于以下问题:Python imrotate函数的具体用法?Python imrotate怎么用?Python imrotate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: build_rotations

def build_rotations(path,pathdir,files,labels,all_count,size):
    train_labels=labels
    barr=len(labels)

    # train_dates={label:[] for label in train_labels}
    train_dates={}
    for label in train_labels:
        '''每一个label都扩充成4倍,
        原来的原来的是原来的label,
        下一轮是rotate 90的,再下一轮是180的,最后一伦施270的'''
        train_dates[int(label)]=[]
        train_dates[int(label)+barr]=[]
        train_dates[int(label)+2*barr]=[]
        train_dates[int(label)+3*barr]=[]

    for file in files:
        label=file[-11:-7]
        if label in train_labels:
            train_dates[int(label)].append(0.001*(255-np.float32(imresize(imread(file,1),size))))
            train_dates[int(label)+barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),90),size)))))
            train_dates[int(label)+2*barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),180),size)))))
            train_dates[int(label)+3*barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),270),size)))))

    if cnn_only:
        return train_dates
开发者ID:shincling,项目名称:Deep-Rein4cement,代码行数:25,代码来源:image_all_1200_rotate.py

示例2: build_rotations

def build_rotations(path,pathdir,files,labels,all_count,size):
    train_labels=labels
    barr=len(labels)
    barr_test=len(labels_eval)

    # train_dates={label:[] for label in train_labels}
    train_dates={}
    test_dates={}
    for label in train_labels:
        '''每一个label都扩充成4倍,
        原来的原来的是原来的label,
        下一轮是rotate 90的,再下一轮是180的,最后一伦施270的'''
        train_dates[int(label)]=[]
        train_dates[int(label)+barr]=[]
        train_dates[int(label)+2*barr]=[]
        train_dates[int(label)+3*barr]=[]

    for label in labels_eval:
        test_dates[int(label)]=[]
        test_dates[int(label)+barr_test]=[]
        test_dates[int(label)+2*barr_test]=[]
        test_dates[int(label)+3*barr_test]=[]

    print 'files_total:',len(files)
    for file in files:
        label=file[-11:-7]
        # print label
        if label in train_labels:
            # print 'train_data:',label
            train_dates[int(label)].append(0.001*(255-np.float32(imresize(imread(file,1),size))))
            train_dates[int(label)+barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),90),size)))))
            train_dates[int(label)+2*barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),180),size)))))
            train_dates[int(label)+3*barr].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),270),size)))))
        else:
            test_dates[int(label)].append(0.001*(255-np.float32(imresize(imread(file,1),size))))
            test_dates[int(label)+barr_test].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),90),size)))))
            test_dates[int(label)+2*barr_test].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),180),size)))))
            test_dates[int(label)+3*barr_test].append(0.001*(255-np.float32((imresize(imrotate(imread(file,1),270),size)))))
            # print 'test_data:',label

    if cnn_only:
        return train_dates

    x_train,y_train=get_sequence_images(train_dates,train_labels,path_length,total_labels_per_seq,size,total_roads)

    # x_train,y_train=get_sequence_images(train_dates,train_labels,path_length,total_labels_per_seq,size,total_roads)
    x_test,y_test=get_sequence_images(test_dates,labels_eval,path_length,total_labels_per_seq,size,total_roads)
    return x_train,y_train,x_test,y_test
开发者ID:shincling,项目名称:Deep-Rein4cement,代码行数:48,代码来源:image_allall_rotate.py

示例3: copy_incorrect

def copy_incorrect(in_folder, out_folder, incorrect_files="snapshotVGG1-5-test.txt"):
    from scipy.misc import imread, imsave, imrotate
    print(incorrect_files)
    if os.path.exists(incorrect_files):
        f = open(incorrect_files, "r")
        print("File found")
    else:
        f = open(os.path.join(in_folder, "stats", incorrect_files), "r")
    page = f.read()

    sources = page.split('\n')
    print(sources)
    print(len(sources))
    count = 0
    for source in sources:
        if source.find("jpg") >= 0:
            fileinfo = source
            if source.find(",") >= 0:
                fileinfo = source.split(", ")[0]
                rotation = source.split(", ")[1]
                image = imread(fileinfo)
                image = imrotate(image, int(rotation))
            else:
                image = imread(fileinfo)
            if count == 0:
                print(fileinfo)
            count += 1
            destination = os.path.split(fileinfo.replace(in_folder, out_folder))[0]
            if not os.path.exists(destination):
                os.makedirs(destination)
            filename = os.path.split(fileinfo)[1]
            # print(os.path.join(destination, filename))
            imsave(os.path.join(destination, filename), image)
    print("Moved " + str(count) + " files")
开发者ID:Sabrewarrior,项目名称:PhotoOrientation,代码行数:34,代码来源:misc.py

示例4: _create_feature_glyph

def _create_feature_glyph(feature, vbs):
    r"""
    Create glyph of feature pixels.

    Parameters
    ----------
    feature : (N, D) ndarray
        The feature pixels to use.
    vbs: int
        Defines the size of each block with vectors of the glyph image.
    """
    # vbs = Vector block size
    num_bins = feature.shape[2]
    # construct a "glyph" for each orientation
    block_image_temp = np.zeros((vbs, vbs))
    # Create a vertical line of ones, to be the first vector
    block_image_temp[:, round(vbs / 2) - 1:round(vbs / 2) + 1] = 1
    block_im = np.zeros((block_image_temp.shape[0],
                         block_image_temp.shape[1],
                         num_bins))
    # First vector as calculated above
    block_im[:, :, 0] = block_image_temp
    # Number of bins rotations to create an 'asterisk' shape
    for i in range(1, num_bins):
        block_im[:, :, i] = imrotate(block_image_temp, -i * vbs)

    # make pictures of positive feature_data by adding up weighted glyphs
    feature[feature < 0] = 0
    glyph_im = np.sum(block_im[None, None, :, :, :] *
                      feature[:, :, None, None, :], axis=-1)
    glyph_im = np.bmat(glyph_im.tolist())
    return glyph_im
开发者ID:Amos-zq,项目名称:menpo,代码行数:32,代码来源:image.py

示例5: rotate_aa

def rotate_aa (frame):
  step = frame/frames
  fft = np.zeros((size, size), np.complex)
  fft[0][0] = freq_mag #*step #255

  loc = cmath.rect(5, 2*np.pi*step)

  xloc = loc.real
  yloc = loc.imag
  #import pdb;pdb.set_trace()

  s = 0
  for dx in fiter(xloc):
    for dy in fiter(yloc):
      xpart = 1 - abs(dx - xloc)
      ypart = 1 - abs(dy - yloc)
      pct = xpart*ypart
      s += pct
      fft[dy,dx] = cmath.rect(pct*freq_mag/4, 0 if dx%2 == dy%2 else np.pi)
      fft[-dy,-dx] = cmath.rect(pct*freq_mag/4, 0 if dx%2 == dy%2 else np.pi)

  ifft = np.fft.ifft2(fft)

  refft = np.fft.fft2(np.abs(ifft))

  #small_img = imresize(np.abs(ifft), 0.5, interp="nearest", mode='F')
  small_img = (imrotate(np.abs(ifft), step*360)/255)[25:-25,25:-25]
  small_refft = np.fft.fft2(small_img)

  return fft, ifft, refft, small_img, small_refft
开发者ID:glennimoss,项目名称:fft,代码行数:30,代码来源:fft.py

示例6: crawl_directory

def crawl_directory(directory, augment_with_rotations=False,
                    first_label=0):
  """Crawls data directory and returns stuff."""
  label_idx = first_label
  images = []
  labels = []
  info = []

  # traverse root directory
  for root, _, files in os.walk(directory):
    logging.info('Reading files from %s', root)
    fileflag = 0
    for file_name in files:
      full_file_name = os.path.join(root, file_name)
      img = imread(full_file_name, flatten=True)
      for i, angle in enumerate([0, 90, 180, 270]):
        if not augment_with_rotations and i > 0:
          break

        images.append(imrotate(img, angle))
        labels.append(label_idx + i)
        info.append(full_file_name)

      fileflag = 1

    if fileflag:
      label_idx += 4 if augment_with_rotations else 1

  return images, labels, info
开发者ID:Hukongtao,项目名称:models,代码行数:29,代码来源:data_utils.py

示例7: add_shape

	def add_shape(self, f):
		#Create shape
		S = Shape(f, self.R, self.SHAPE_R)
	
		#Add to shape list
		S.shape_num = len(self.shape_list)
		self.shape_list.append(S)
		
		row = []
		for k in range(len(self.shape_list)):
			T = self.shape_list[k]
			ift = real(ipfft(pft_mult(pft_rotate(S.pft, 2.*pi/6.), T.pft), 2*self.SHAPE_R+1,2*self.SHAPE_R+1))
			Spad = imrotate(cpad(S.indicator, array([2*self.SHAPE_R+1,2*self.SHAPE_R+1])), 360./6.)
			Tpad = cpad(T.indicator, array([2*self.SHAPE_R+1,2*self.SHAPE_R+1]))
			pind = real(fftconvolve(Spad, Tpad, mode='same'))
			imshow(pind)
			imshow(ift)
			obst = to_ind(pind, 0.001)
			imshow(obst)
			cutoff = best_cutoff(ift, obst, S.radius + T.radius)
			print cutoff
			imshow(to_ind(ift, cutoff))
			row.append(cutoff * self.tarea)
		self.cutoff_matrix.append(row)

		return S
开发者ID:mikolalysenko,项目名称:Collisions,代码行数:26,代码来源:fourier_obstacle.py

示例8: getAlignImg

def getAlignImg(t,label = None):#!!!notice, only take uint8 type for the imrotate function!!!
    f = lambda x:np.asarray([float(a) for a in x]);
    o = f(t.ImageOrientationPatient);
    o1 = o[:3];
    o2 = o[3:];
    oh = np.cross(o1,o2);
    or1 = np.asarray([0.6,0.6,-0.2]);
    o2new = np.cross(oh,or1);
    theta = np.arccos(np.dot(o2,o2new)/np.sqrt(np.sum(o2**2)*np.sum(o2new**2)))*180/3.1416;
    theta = theta * np.sign(np.dot(oh,np.cross(o2,o2new)));
    im_max = np.percentile(t.pixel_array.flatten(),99);
    res = imrotate(np.array(np.clip(np.array(t.pixel_array,dtype=np.float)/im_max*256,0,255),dtype=np.uint8),theta);
    if label is None:
        return res;
    else:
        lab = imrotate(label,theta);
        return res,lab
开发者ID:01bui,项目名称:diagnose-heart,代码行数:17,代码来源:heart.py

示例9: correct_rotation

 def correct_rotation(self, img, amin, amax, step = 1):
     results = []
     for a in range(int(amin / step), int(amax / step) + 1):
         rot = misc.imrotate(img, a * step)
         corr = self._corr(rot)
         print a * step, corr
         results.append((corr, rot))
     return max(results, key = lambda x: x[0])[1]
开发者ID:KWMalik,项目名称:tau,代码行数:8,代码来源:alignment.py

示例10: rotate_images

def rotate_images(images, angle):
    images_list = [None] * images.shape[0]
    for i in range(images.shape[0]):
        images_list[i] = misc.imrotate(images[i,:,:,:], angle)
    images_rot = np.stack(images_list,axis=0)
    sz1 = images_rot.shape[1]/2
    sz2 = FLAGS.image_size/2
    images_crop = images_rot[:,(sz1-sz2):(sz1+sz2),(sz1-sz2):(sz1+sz2),:]
    return images_crop
开发者ID:TianweiXing,项目名称:facenet,代码行数:9,代码来源:test_invariance_on_lfw.py

示例11: rotate_gen

def rotate_gen(imgin, num_seq, seq_len, patch_size,
                rgw0=30., rga0=2.):
    """
    Generate rotation patches from imgin(non-flattened).  

    Parameters
    ----------
    imgin: double
        The non-flattened single-channel input image.
    num_seq: int
        Number of sequences to generate. 
    seq_len: int
        The length of the output patch sequence.
    patch_size: int
        The length of side of the output pathes.
    rgw0: double
        Range of initial values of angular velocity.
    rga0: double
        Range of initial values of angular acceleration.

    Returns
    -------
    patch_seq: double (num_seq, seq_len * patch_size**2)
        Output patch sequences.
    """

    img_shape = imgin.shape
    crops = patch_size/2            # crop after rotation
    crope = patch_size/2+patch_size # crop after rotation
    
    thetas = [None] * seq_len  
    seqs = numpy.zeros((num_seq, seq_len*(patch_size**2)))

    for i in range(num_seq):

        # compute the rotation angle for each time step
        theta = 0.
        w = numpy.random.uniform(-rgw0, rgw0)
        a = numpy.random.uniform(-rga0, rga0)
        for t in range(seq_len):
            thetas[t] = theta
            theta += w
            w += a

        # sample a 2 times larger patch for rotation purpose
        row = numpy.random.randint(high=img_shape[0]-2*patch_size, 
                                    low=0)  
        col = numpy.random.randint(high=img_shape[1]-2*patch_size, 
                                    low=0)  
        patch_large = imgin[row:row+2*patch_size, col:col+2*patch_size]

        seqs[i, :] = numpy.concatenate([misc.imrotate(patch_large, theta)\
                    [crops:crope, crops:crope].flatten() 
                    for theta in thetas], axis=1)
    return seqs
开发者ID:andrubrown,项目名称:video-modeling,代码行数:55,代码来源:patch_gen.py

示例12: rotate_dataset

def rotate_dataset(X, Y):
    """
    This produces a dataset 2 times bigger than the original one,
    by rptating the 28x28 images in 10 degrees clockwise and counter clockwise
    """
    angles = [-10, 10]

    rotate = lambda x, w: imrotate(x.reshape((28, 28)), w).ravel()
    X = np.concatenate([X] + [np.apply_along_axis(rotate, 1, X, angle) for angle in angles])
    Y = np.concatenate([Y for _ in range(3)], axis=0)
    return X, Y
开发者ID:kenterao,项目名称:kaggle-digit,代码行数:11,代码来源:utils.py

示例13: augment_image

def augment_image(im, aug_code):
    '''
    0: no augmentation, 1-3: rotation, 4-5: flip
    TODO: 6-8: jitter R, G, B channels
    '''
    if aug_code == 0:
        return im
    elif aug_code == 1:
        im_aug = misc.imrotate(im, 90)
    elif aug_code == 2:
        im_aug = misc.imrotate(im, 180)
    elif aug_code == 3:
        im_aug = misc.imrotate(im, 270)
    elif aug_code == 4:
        im_aug = np.fliplr(im)
    elif aug_code == 5:
        im_aug = np.flipud(im)
    else:
        raise Exception("Wrong augmentation code")

    return im_aug
开发者ID:lun5,项目名称:tissue-component-classification,代码行数:21,代码来源:task.py

示例14: rotate_image

 def rotate_image(self,image,rotate=None):
     """rotates and overwrites image.
            - rotate is angle in degrees"""
     if rotate == None:
         rotate = self.header['aspect'][0]
     print 'Rotate:  ',rotate
     img_max = np.max(image)
     if rotate != 0.0:
         image = misc.imrotate(image,rotate)
         maxout = float(np.max(image))
         image = img_max*image/maxout
     return image
开发者ID:jtollefs,项目名称:pyplanet,代码行数:12,代码来源:img.py

示例15: align

    def align(self, img, f5pt):
        ec_mc_y = 48.0
        crop_size = 128
        ec_y = 40
        
        ang_tan = (f5pt[0,1]-f5pt[1,1])/(f5pt[0,0]-f5pt[1,0])
        ang = atan(ang_tan) / pi * 180
        img_rot = imrotate(img, ang, 'bicubic')


        # eye center
        x = (f5pt[0,0]+f5pt[1,0])/2;
        y = (f5pt[0,1]+f5pt[1,1])/2;

        ang = -ang/180*pi;
        xx,yy = transform(x,y,ang,img.shape,img_rot.shape)

        eyec = NP.array([xx, yy]).astype(long)

        x = (f5pt[3,0]+f5pt[4,0])/2;
        y = (f5pt[3,1]+f5pt[4,1])/2;
        [xx, yy] = transform(x, y, ang, img.shape, img_rot.shape)
        mouthc = NP.array([xx, yy]).astype(long)

        resize_scale = ec_mc_y/(mouthc[1]-eyec[1])

        img_resize = imresize(img_rot, resize_scale);


        eyec2 = eyec*resize_scale 
        eyec2 = NP.round(eyec2);
        img_crop = NP.zeros((crop_size, crop_size,3),dtype='uint8')
        # crop_y = eyec2(2) -floor(crop_size/3.0);
        crop_y = eyec2[1] - ec_y
        crop_y_end = crop_y + crop_size
        crop_x = eyec2[0]-int(crop_size/2)
        crop_x_end = crop_x + crop_size
        
        
        box = NP.array([crop_x, crop_x_end, crop_y, crop_y_end])
        box[box<0] = 0
        box[1] = min(box[1], img_resize.shape[1])
        box[3] = min(box[3], img_resize.shape[0])
        try:
            img_crop[(box[2]-crop_y):(box[3]-crop_y), (box[0]-crop_x):(box[1]-crop_x),:] = \
                 img_resize[box[2]:box[3],box[0]:box[1],:]
        except:
            print box, crop_y, crop_x, img_resize.shape
            raise

        return img_crop,img_resize,dlib.rectangle(int(box[0]), int(box[2]),int(box[1]),int(box[3]))          
开发者ID:oran28,项目名称:video_face_recognise,代码行数:51,代码来源:faceProc.py


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