コード例 #1
0
ファイル: data_models.py プロジェクト: MinTTT/ColiCoords
    def rotate(self, theta):
        """
        Rotate all data elements and return a new ``Data`` object with rotated data elements.

        Parameters
        ----------
        theta : :obj:`float`
            Rotation angle in degrees.

        Returns
        -------
        data : :class:`colicoords.data_models.Data`
            Rotated ``Data``
        """

        data = Data()
        for v in self.data_dict.values():
            if v.dclass == 'storm':
                rotated = _rotate_storm(v, -theta, shape=self.shape)
            else:

                rotated = scipy_rotate(v,
                                       -theta,
                                       mode='nearest',
                                       axes=(-2, -1))  #todo check dis

            data.add_data(rotated, v.dclass, name=v.name, metadata=v.metadata)
        return data
コード例 #2
0
 def test_rotation(self):
     data_rotated = self.data[:2].rotate(60)
     rotated = scipy_rotate(self.data.binary_img[:2],
                            -60,
                            mode='nearest',
                            axes=(-1, -2))
     self.assertArrayEqual(rotated, data_rotated.binary_img)
     self.assertEqual(len(data_rotated), 2)
コード例 #3
0
def rotate_image(image, angle, reshape=False):
    """
        Rotate a tensor with a certain angle.
        If true, expands the output image to make it large enough to hold the entire rotated image.
        Else it keeps the same size
        Depreciated...
    """
    #image = image.squeeze()
    if len(image.size()) == 3:  # Case of a single image.
        axes = ((1, 2))
    elif len(image.size()) == 4:  # Case of a batch of images
        axes = ((2, 3))
    else:
        print("Dimension of images must be 4 or 5.")
        return
    im = scipy_rotate(image.numpy(), angle=angle, reshape=reshape, axes=axes)
    im_t = torch.FloatTensor(im)
    return (im_t, 360 - angle)
コード例 #4
0
def rotate_mask(mask, angle, reshape=False):
    """
        This function take a prediction from the model [batch_size,21,513,513] 
        and rotate, by an angle add as a parameters, the prediction.
        To make sure there is no error it is preferable to use new_angle returned by the function 'rotate_image'.
    """
    with torch.no_grad():
        if len(mask.size()) == 3:  # Case of a single mask.
            axes = ((1, 2))
        elif len(mask.size()) == 4:  # Case of a batch of masks
            axes = ((2, 3))
        else:
            print("Size must be 4 or 5.")
            return
        m = scipy_rotate(mask.numpy(),
                         angle=angle,
                         reshape=reshape,
                         axes=axes,
                         mode='nearest')
        mask_t = torch.FloatTensor(m)
        return mask_t
コード例 #5
0
def rotate_radar_images(radar_image_matrix, ccw_rotation_angle_deg):
    """Rotates each radar image in the xy-plane.

    :param radar_image_matrix: See doc for
        `deep_learning_utils.check_radar_images`.
    :param ccw_rotation_angle_deg: Each image will be rotated counterclockwise
        by this angle (degrees).
    :return: rotated_image_matrix: Same as `radar_image_matrix`, but after
        rotation.  The shapes of the two numpy arrays are the same.
    """

    dl_utils.check_radar_images(radar_image_matrix=radar_image_matrix,
                                min_num_dimensions=3,
                                max_num_dimensions=5)
    error_checking.assert_is_geq(ccw_rotation_angle_deg, -180.)
    error_checking.assert_is_leq(ccw_rotation_angle_deg, 180.)

    return scipy_rotate(input=radar_image_matrix,
                        angle=-ccw_rotation_angle_deg,
                        axes=(1, 2),
                        reshape=False,
                        order=1,
                        mode='constant',
                        cval=PADDING_VALUE)
コード例 #6
0
    def getModeMatrix(self, npola=1, shift=None, angle=None):
        '''
        	Returns the matrix containing the mode profiles. 
            Note that while you can set two polarizations, the modes profiles are obtained under a scalar apporoximation.
        	
        	Parameters
        	----------
        	
        	npola : int (1 or 2)
        		number of polarizations considered. For npola = 2, the mode matrix will be a block diagonal matrix.
        		
            shift : list or None
                (slow) value of a coordinate offset, allows to return the mode matrix for a fiber with the center shifted with regard
                to the center of the observation window.
                defaults to None
                
            rotation: float or None
                (slow) angle in radians, allows to rotate the mode matrix with an arbitrary angle.
                Note that the rotation is applied BEFORE the transverse shift.
                defaults to None
                
                
        	Returns
        	-------
        	
        	M : numpy array
    		the matrix representing the basis of the propagating modes.
        '''
        assert (self.profiles)
        if shift is not None:
            assert (len(shift) == 2)

        N = self.profiles[0].shape[0]
        M = np.zeros((N * npola, npola * self.number), dtype=np.complex128)
        angle = angle / np.pi * 180. if (angle is not None) else None

        for pol in range(npola):

            for ind, modeProfile in enumerate(self.profiles):

                if (shift is None and angle is None):
                    M[pol * N:(pol + 1) * N, pol * self.number +
                      ind] = modeProfile  #.reshape(1,self._npoints**2)
                else:
                    mode2D = modeProfile.reshape([self.indexProfile.npoints] *
                                                 2)

                    if angle is not None:
                        mode2D = \
                            scipy_rotate(mode2D.real,angle,reshape=False) + \
                            complex(0,1)*scipy_rotate(mode2D.imag,angle,reshape=False)

                    if shift is not None:

                        mode2D = \
                            scipy_shift(input=mode2D.real,shift=shift) \
                            + complex(0,1)*scipy_shift(input=mode2D.imag,shift=shift)

                    M[pol * N:(pol + 1) * N,
                      pol * self.number + ind] = mode2D.flatten()

        self.modeMatrix = M

        return M
コード例 #7
0
def rotate_custom(image, phi, reshape=True, **kwargs):
    # need to fill in holes from scipy
    return scipy_rotate(image, phi, reshape=reshape, **kwargs)