def gauss(array, mode, sigma):
    """
    Фильтр Гаусса
    array: двумерный массив
    mode: тип экстраполяции
    sigma: радиус размытия
    result: двумерный массив
    """
    kernel = gauss_filter1d(sigma)
    tmp = convolve1d(array, kernel, mode, axis = 1)
    result = convolve1d(tmp, kernel, mode, axis = 0)
    return result
 def test_convolve1d_rep_y(self):
     array = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]
     kernel = [1, 2, 3, 4]
     output = tolist(
         filters.convolve1d(array, kernel, axis=0, mode='nearest'))
     result = conv.convolve1d(array, kernel, mode='rep', axis=0)
     self.assertEqual(output, result)
 def test_convolve1d_odd_y(self):
     array = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
     kernel = [1, 2, 3]
     output = tolist(
         filters.convolve1d(array, kernel, axis=0, mode='reflect'))
     result = conv.convolve1d(array, kernel, mode='even', axis=0)
     self.assertEqual(output, result)
 def test_convolve1d_1d_odd2(self):
     kernel_odd_size = [1, 2, 3, 4]
     output = tolist(
         filters.convolve1d(self.array1d, kernel_odd_size, mode='reflect'))
     result = conv.convolve1d(self.array1d,
                              kernel_odd_size,
                              mode='even',
                              axis=-1)
     self.assertEqual(output, result)
 def test_convolve1d_1d_rep_1(self):
     kernel_even_size = [1, 2, 3]
     output = tolist(
         filters.convolve1d(self.array1d, kernel_even_size, mode='nearest'))
     result = conv.convolve1d(self.array1d,
                              kernel_even_size,
                              mode='rep',
                              axis=-1)
     self.assertEqual(output, result)
示例#6
0
def sobel(array, mode, direction):
    """
    Фильтр собеля,применямый к двумерному массиву array.
    Алгоритм реализуется применением одномерный сверток по строкам и по столбцам.
    array: двумерный массив, для которого вычисляются градиенты
    mode: тип продолжения
        rep - дублирование граничных пикселей
        odd - четное продолжение
        even - нечетное продолжение
    direction:
        x - горизонтальные контуры
        y - вертикальные контуры
    result: двумерный массив 
    """
    if direction == "x":
        tmp_by_rows = convolve1d(array, [1, 0, -1], mode=mode, axis=1)
        return convolve1d(tmp_by_rows, [1, 2, 1], mode=mode, axis=0)
    elif direction == "y":
        tmp_by_rows = convolve1d(array, [1, 2, 1], mode=mode, axis=1)
        return convolve1d(tmp_by_rows, [1, 0, -1], mode=mode, axis=0)
    else:
        raise ValueError("Unsupported direction : " + direction)
示例#7
0
def _proccess_y(array, mode, sigma):
    derivative_kernel = _gauss_derivative_filter(sigma)
    gauss_kernel = gauss_filter1d(sigma)
    tmp = convolve1d(array, derivative_kernel, mode, axis = 0)
    return convolve1d(tmp, gauss_kernel, mode, axis = 1)
 def test_convolve1d_1d_even(self):
     array = [1, 2, 3, 4]
     kernel = [1, 2, 3, 4]
     output = [14, 20, 29, 37]
     result = conv.convolve1d(array, kernel, mode='odd', axis=-1)
     self.assertEqual(output, result)