Exemplo n.º 1
0
def apply_double_mesh(matrix, mesh):
    shape = matrix.shape
    if len(shape) > 2:
        out = np.zeros(shape, dtype=np.int16)
        for i in range(shape[2]):
            out[:, :,
                i] = apply_double_mesh_one_dimension(matrix[:, :, i], mesh)
        return actions.linear_transform(out).astype(np.uint8)
    else:
        return actions.linear_transform(
            apply_double_mesh_one_dimension(matrix, mesh)).astype(np.uint8)
Exemplo n.º 2
0
def harris(matrix, threshold):
    if len(matrix.shape) == 3:
        matrix_to_op = actions.to_grayscale(matrix)
    else:
        matrix_to_op = matrix

    dx = sp.signal.convolve2d(matrix_to_op,
                              sobel_matrix,
                              boundary='symm',
                              mode='same')
    dy = sp.signal.convolve2d(matrix_to_op,
                              np.transpose(sobel_matrix),
                              boundary='symm',
                              mode='same')
    gm = mesh.gauss_mesh(7, 2)
    dx2 = sp.signal.convolve2d(np.power(dx, 2),
                               gm,
                               boundary='symm',
                               mode='same')
    dy2 = sp.signal.convolve2d(np.power(dy, 2),
                               gm,
                               boundary='symm',
                               mode='same')
    lxy = sp.signal.convolve2d(np.multiply(dx, dy),
                               gm,
                               boundary='symm',
                               mode='same')
    k = 0.04
    res = (np.multiply(dx2, dy2) -
           np.power(lxy, 2)) - k * np.power(np.add(dx2, dy2), 2)
    res = actions.linear_transform(res)
    return combine(matrix, thresholds.threshold(res, threshold))
Exemplo n.º 3
0
def multi_sobel(matrix):
    m1 = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
    out1 = mesh.apply_mesh_one_dimension(matrix, m1, 3)
    m2 = m1.transpose()
    out2 = mesh.apply_mesh_one_dimension(matrix, m2, 3)
    m3 = np.array([[-2, -1, 0], [-1, 0, 1], [0, 1, 2]])
    out3 = mesh.apply_mesh_one_dimension(matrix, m3, 3)
    m4 = m3.transpose()
    out4 = mesh.apply_mesh_one_dimension(matrix, m4, 3)
    out = np.zeros(matrix.shape, dtype=np.int16)
    for i in range(matrix.shape[0]):
        for j in range(matrix.shape[1]):
            out[i, j] = max(abs(out1[i, j]), abs(out2[i, j]), abs(out3[i, j]),
                            abs(out4[i, j]))

    return actions.linear_transform(out).astype(np.uint8)
Exemplo n.º 4
0
 def save(self, event):
     filename = filedialog.asksaveasfilename(parent=root)
     image = Image.fromarray(
         actions.linear_transform(np.array(self.true_image)))
     image.save(filename)
     print(filename)