nussl/separation/spatial/duet.py
def _smooth_matrix(matrix, kernel):
        """Performs two-dimensional convolution in order to smooth the values of matrix elements.

        (similar to low-pass filtering)

        Parameters:
            matrix (np.array): a 2D Numpy matrix to be smoothed
            kernel (np.array): a 2D Numpy matrix containing kernel values
        Note:
            if Kernel is of size 1 by 1 (scalar), a Kernel by Kernel matrix of 1/Kernel**2 will be used as the matrix
            averaging kernel
        Output:
            smoothed_matrix (np.array): a 2D Numpy matrix containing a smoothed version of Mat (same size as Mat)
        """

        # check the dimensions of the Kernel matrix and set the values of the averaging
        # matrix, kernel_matrix
        kernel_matrix = np.ones((kernel[0], kernel[0])) / kernel[0] ** 2
        krow, kcol = np.shape(kernel_matrix)

        # adjust the matrix dimension for convolution
        copy_row = int(np.floor(krow / 2))  # number of rows to copy on top and bottom
        copy_col = int(np.floor(kcol / 2))  # number of columns to copy on either side

        # TODO: This is very ugly. Make this readable.
        # form the augmented matrix (rows and columns added to top, bottom, and sides)
        matrix = np.mat(matrix)  # make sure Mat is a Numpy matrix
        augmented_matrix = np.vstack(
            [
                np.hstack(
                    [matrix[0, 0] * np.ones((copy_row, copy_col)),
                     np.ones((copy_row, 1)) * matrix[0, :],
                     matrix[0, -1] * np.ones((copy_row, copy_col))
                     ]),
                np.hstack(
                    [matrix[:, 0] * np.ones((1, copy_col)),
                     matrix,
                     matrix[:, -1] * np.ones((1, copy_col))]),
                np.hstack(
                    [matrix[-1, 1] * np.ones((copy_row, copy_col)),
                     np.ones((copy_row, 1)) * matrix[-1, :],
                     matrix[-1, -1] * np.ones((copy_row, copy_col))
                     ]
                )
            ]
        )

        # perform two-dimensional convolution between the input matrix and the kernel
        smooted_matrix = signal.convolve2d(augmented_matrix, kernel_matrix[::-1, ::-1], mode='valid')

        return smooted_matrix
Performs two-dimensional convolution in order to smooth the values of matrix elements.

        (similar to low-pass filtering)

        Parameters:
            matrix (np.array): a 2D Numpy matrix to be smoothed
            kernel (np.array): a 2D Numpy matrix containing kernel values
        Note:
            if Kernel is of size 1 by 1 (scalar), a Kernel by Kernel matrix of 1/Kernel**2 will be used as the matrix
            averaging kernel
        Output:
            smoothed_matrix (np.array): a 2D Numpy matrix containing a smoothed version of Mat (same size as Mat)
        
Performs two-dimensional convolution in order to smooth the values of matrix elements.
(similar to low-pass filtering)
Performs two - dimensional convolution in order to smooth the values of matrix elements . ( similar to low - pass filtering )
def _smooth_matrix(matrix, kernel):
        kernel_matrix = np.ones((kernel[0], kernel[0])) / kernel[0] ** 2
        krow, kcol = np.shape(kernel_matrix)
        copy_row = int(np.floor(krow / 2))  
        copy_col = int(np.floor(kcol / 2))  
        matrix = np.mat(matrix)  
        augmented_matrix = np.vstack(
            [
                np.hstack(
                    [matrix[0, 0] * np.ones((copy_row, copy_col)),
                     np.ones((copy_row, 1)) * matrix[0, :],
                     matrix[0, -1] * np.ones((copy_row, copy_col))
                     ]),
                np.hstack(
                    [matrix[:, 0] * np.ones((1, copy_col)),
                     matrix,
                     matrix[:, -1] * np.ones((1, copy_col))]),
                np.hstack(
                    [matrix[-1, 1] * np.ones((copy_row, copy_col)),
                     np.ones((copy_row, 1)) * matrix[-1, :],
                     matrix[-1, -1] * np.ones((copy_row, copy_col))
                     ]
                )
            ]
        )
        smooted_matrix = signal.convolve2d(augmented_matrix, kernel_matrix[::-1, ::-1], mode='valid')
        return smooted_matrix
def _smooth_matrix ( matrix , kernel ) : kernel_matrix = np . ones ( ( kernel [ 0 ] , kernel [ 0 ] ) ) / kernel [ 0 ] ** 2 krow , kcol = np . shape ( kernel_matrix ) copy_row = int ( np . floor ( krow / 2 ) ) copy_col = int ( np . floor ( kcol / 2 ) ) matrix = np . mat ( matrix ) augmented_matrix = np . vstack ( [ np . hstack ( [ matrix [ 0 , 0 ] * np . ones ( ( copy_row , copy_col ) ) , np . ones ( ( copy_row , 1 ) ) * matrix [ 0 , : ] , matrix [ 0 , - 1 ] * np . ones ( ( copy_row , copy_col ) ) ] ) , np . hstack ( [ matrix [ : , 0 ] * np . ones ( ( 1 , copy_col ) ) , matrix , matrix [ : , - 1 ] * np . ones ( ( 1 , copy_col ) ) ] ) , np . hstack ( [ matrix [ - 1 , 1 ] * np . ones ( ( copy_row , copy_col ) ) , np . ones ( ( copy_row , 1 ) ) * matrix [ - 1 , : ] , matrix [ - 1 , - 1 ] * np . ones ( ( copy_row , copy_col ) ) ] ) ] ) smooted_matrix = signal . convolve2d ( augmented_matrix , kernel_matrix [ : : - 1 , : : - 1 ] , mode = 'valid' ) return smooted_matrix
Performs two-dimensional convolution in order to smooth the values of matrix elements.
Performs two - dimensional convolution in order to smooth the values of matrix elements .
"""Performs two-dimensional convolution in order to smooth the values of matrix elements.

        (similar to low-pass filtering)

        Parameters:
            matrix (np.array): a 2D Numpy matrix to be smoothed
            kernel (np.array): a 2D Numpy matrix containing kernel values
        Note:
            if Kernel is of size 1 by 1 (scalar), a Kernel by Kernel matrix of 1/Kernel**2 will be used as the matrix
            averaging kernel
        Output:
            smoothed_matrix (np.array): a 2D Numpy matrix containing a smoothed version of Mat (same size as Mat)
        """ # check the dimensions of the Kernel matrix and set the values of the averaging # matrix, kernel_matrix # adjust the matrix dimension for convolution # number of rows to copy on top and bottom # number of columns to copy on either side # TODO: This is very ugly. Make this readable. # form the augmented matrix (rows and columns added to top, bottom, and sides) # make sure Mat is a Numpy matrix # perform two-dimensional convolution between the input matrix and the kernel
matrix
a 2D Numpy matrix to be smoothed
a 2D Numpy matrix to be smoothed
kernel
a 2D Numpy matrix containing kernel values
a 2D Numpy matrix containing kernel values