Exemplo n.º 1
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """

    # Get the Ix and Iy derivatives of the image using the filters [1, 0, −1], [1, 0, −1]T respectively :
    conovlve_der = np.array([[1, 0, -1]])
    x_der = convolve2d(im, conovlve_der, mode='same', boundary='symm')
    y_der = convolve2d(im, conovlve_der.T, mode='same', boundary='symm')

    # Blur the images: ix2,iy2,ixiy with kernel size 3
    ix2 = sol4_utils.blur_spatial(np.multiply(x_der, x_der), KERNEL_FOR_BLUR)
    iy2 = sol4_utils.blur_spatial(np.multiply(y_der, y_der), KERNEL_FOR_BLUR)
    ixiy = sol4_utils.blur_spatial(np.multiply(x_der, y_der), KERNEL_FOR_BLUR)

    # measure how big the eigenvalues of this matrix :
    det_m = (ix2 * iy2) - (ixiy * ixiy)
    trace_m = ix2 + iy2
    result_R = det_m - (K_FOR_EIGAN_VAL * (trace_m * trace_m))

    # finding the corners :
    corners = np.argwhere(non_maximum_suppression(result_R))

    # flipping the coordinates :
    return np.fliplr(corners)
Exemplo n.º 2
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    dx = convolve(im, DERIVATIVE_FILTER)
    dy = convolve(im, DERIVATIVE_FILTER.transpose())

    ix_sqr = sol4_utils.blur_spatial(np.square(dx), KERNEL_SIZE)
    iy_sqr = sol4_utils.blur_spatial(np.square(dy), KERNEL_SIZE)
    ix_iy = sol4_utils.blur_spatial(np.multiply(dx, dy), KERNEL_SIZE)

    m1 = np.dstack([ix_sqr, ix_iy])
    m2 = np.dstack([ix_iy, iy_sqr])
    m = np.concatenate([m1[..., np.newaxis], m2[..., np.newaxis]], axis=3)

    response = np.linalg.det(m) - HCD_K * np.square(
        np.trace(m, axis1=2, axis2=3))
    bin_response = non_maximum_suppression(response)

    # preparing indices in [x,y] format
    idx = np.indices(im.shape)
    idx = np.dstack([idx[1], idx[0]])

    max_idx = idx[bin_response != 0]
    return max_idx
Exemplo n.º 3
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    i_x = convolve(im, CONVOLUTION_DER.reshape(1, 3))
    i_y = convolve(im, (CONVOLUTION_DER.T).reshape(3, 1))
    i_x_2 = sol4_utils.blur_spatial(np.multiply(i_x, i_x), DEFAULT_KERNEL_SIZE)
    i_x_i_y = sol4_utils.blur_spatial(np.multiply(i_x, i_y),
                                      DEFAULT_KERNEL_SIZE)
    i_y_2 = sol4_utils.blur_spatial(np.multiply(i_y, i_y), DEFAULT_KERNEL_SIZE)

    det = np.multiply(i_x_2, i_y_2) - np.multiply(i_x_i_y, i_x_i_y)
    trace = i_x_2 + i_y_2

    # R = det(M ) − k(trace(M ))2
    r = det - (K_COEFFICIENT * (np.multiply(trace, trace)))

    binary_max = non_maximum_suppression(r)

    max_matrix = np.array(np.nonzero(binary_max)).T

    return np.flip(max_matrix)
Exemplo n.º 4
0
def calculate_matrix(im):
    der_x_im, der_y_im = util.conv_der(im)
    matrix_1 = util.blur_spatial(der_x_im * der_x_im, 3)
    matrix_2 = util.blur_spatial(der_x_im * der_y_im, 3)
    matrix_3 = util.blur_spatial(der_y_im * der_x_im, 3)
    matrix_4 = util.blur_spatial(der_y_im * der_y_im, 3)
    return matrix_1,matrix_2,matrix_3,matrix_4
Exemplo n.º 5
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of
    the ith corner points.
    """
    # calculate derivative
    Ix = convolve(im, DERIVATIVE_FILTER)
    Iy = convolve(im, DERIVATIVE_FILTER.T)

    # create matrix M
    M = np.array([[
        sol4_utils.blur_spatial(Ix * Ix, KERNEL_SIZE),
        sol4_utils.blur_spatial(Ix * Iy, KERNEL_SIZE)
    ],
                  [
                      sol4_utils.blur_spatial(Iy * Ix, KERNEL_SIZE),
                      sol4_utils.blur_spatial(Iy * Iy, KERNEL_SIZE)
                  ]])

    det_M = (M[0, 0] * M[1, 1]) - (M[0, 1] * M[1, 0])
    trace_M = M[0, 0] + M[1, 1]
    R = det_M - K * (np.power(trace_M, POWER))

    bool_im = non_maximum_suppression(R.T)
    corners = np.where(bool_im)
    corners_arr = np.stack(corners, axis=1)
    return corners_arr
Exemplo n.º 6
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """

    # 1) let us create the derevatives:
    kernel = np.array([[1, 0, -1]]).astype(np.float64)
    Ix = convolve(im, kernel)
    Iy = convolve(im, kernel.T)

    # 2) Create M
    Ix2 = ut.blur_spatial(Ix * Ix, 3)
    Iy2 = ut.blur_spatial(Iy * Iy, 3)
    Ixy = ut.blur_spatial(Iy * Ix, 3)
    # M = np.stack((Ix2, Ixy, Ixy, Iy2), axis=-1).reshape((im.shape[0], im.shape[1], 2, 2))

    # Det(M) - K * (trace(M)) ^ 2
    R = ((Ix2 * Iy2) - (Ixy * Ixy)) - (0.04 * np.square(Ix2 + Iy2))
    points = np.array(np.where(non_maximum_suppression(R)))

    # Return the relevant indices as (col, row) and NOT (row, col) as usual.
    return np.array([points[1], points[0]]).T
Exemplo n.º 7
0
def harris_corner_detector(im):
    """
  Detects harris corners.
  Make sure the returned coordinates are x major!!!
  :param im: A 2D array representing an image.
  :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
  """
    k = 0.04
    filter = np.reshape(np.asarray([1, 0, -1]), (1, 3))
    filter_transpose = np.reshape(filter, (3, 1))
    I_x = convolve(im, filter)
    I_y = convolve(im, filter_transpose)
    I_xx = np.multiply(I_x, I_x)
    I_yy = np.multiply(I_y, I_y)
    I_xy = np.multiply(I_x, I_y)
    blur_x = sol4_utils.blur_spatial(I_xx, 3)
    blur_y = sol4_utils.blur_spatial(I_yy, 3)
    blur_xy = sol4_utils.blur_spatial(I_xy, 3)

    det_M = blur_x * blur_y - np.square(blur_xy)
    trace = blur_x + blur_y
    R = det_M - k * np.square(trace)
    maxima_points = non_maximum_suppression(R)
    corner_points_arr = np.argwhere(maxima_points.T)
    return corner_points_arr
Exemplo n.º 8
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    x_der_vec = np.array([1, 0, -1])[np.newaxis, :]
    y_der_vec = x_der_vec.T
    I_x = convolve2d(im, x_der_vec, mode='same', boundary='symm')
    I_y = convolve2d(im, y_der_vec, mode='same', boundary='symm')
    I_xx = I_x * I_x
    I_yy = I_y * I_y
    I_xy = I_x * I_y
    blur_I_xx = sol4_utils.blur_spatial(I_xx, 3)
    blur_I_yy = sol4_utils.blur_spatial(I_yy, 3)
    blur_I_xy = sol4_utils.blur_spatial(I_xy, 3)
    det = blur_I_xx * blur_I_yy - blur_I_xy * blur_I_xy
    trace = blur_I_xx + blur_I_yy
    R = det - 0.04 * (trace**2)
    corners = non_maximum_suppression(R)
    cor_arr = np.where(corners > 0)
    points = np.dstack((cor_arr[1], cor_arr[0]))[0]

    return points
Exemplo n.º 9
0
def harris_corner_detector(im):
    """
  Detects harris corners.
  Make sure the returned coordinates are x major!!!
  :param im: A 2D array representing an image.
  :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
  """
    d_filter = np.array([[1], [0], [-1]])

    # Get the Ix and Iy derivatives of the image using the filters
    i_x = scipy.ndimage.filters.convolve(im, d_filter.transpose())
    i_y = scipy.ndimage.filters.convolve(im, d_filter)

    # Blur the images: Ix 2 , Iy 2 , Ix Iy and create matrix m for each pixel
    m = np.zeros((im.shape[0], im.shape[1], 2, 2))
    m[:, :, 0, 0] = sol4_utils.blur_spatial((i_x * i_x), 3)
    m[:, :, 1, 1] = sol4_utils.blur_spatial((i_y * i_y), 3)
    m[:, :, 1, 0] = sol4_utils.blur_spatial((i_y * i_x), 3)
    m[:, :, 0, 1] = sol4_utils.blur_spatial((i_y * i_x), 3)

    # find response image R
    k = 0.04
    r = np.linalg.det(m) - k * np.square(np.trace(m, axis1=2, axis2=3))

    # find the corners - the local maximum points of R
    max_r = non_maximum_suppression(r)
    corners = np.array(np.nonzero(max_r))

    # create array with shape (N,2) of [x,y] key point locations in im.
    return np.array([corners[1], corners[0]]).transpose()
Exemplo n.º 10
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """

    conv_vec = np.array([[1, 0, -1]])

    x_der = convolve(im, conv_vec)
    y_der = convolve(im, conv_vec.transpose())

    x_der_2 = sol4_utils.blur_spatial(x_der * x_der, 3)

    y_der_2 = sol4_utils.blur_spatial(y_der * y_der, 3)
    x_y_der = sol4_utils.blur_spatial(x_der * y_der, 3)
    y_x_der = sol4_utils.blur_spatial(y_der * x_der, 3)
    response = (x_der_2 * y_der_2 -
                x_y_der * y_x_der) - K * (x_der_2 + y_der_2)**2
    bool_response = non_maximum_suppression(response)
    coor_arr = np.where(bool_response)
    coor_arr = [coor_arr[1], coor_arr[0]]
    coor_arr = np.column_stack(coor_arr)

    return coor_arr
Exemplo n.º 11
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    # setting up k var as instructed in exercise
    k = 0.04
    # calculating deriv in x and y orientation
    dx = ndimage.filters.convolve(im, deriv_vec, mode='nearest')
    dy = ndimage.filters.convolve(im, np.transpose(deriv_vec), mode='nearest')
    #TODO: check if multiplication is element-wise (np.multiply) or regular (np.dot)
    dx_pow = sol4_utils.blur_spatial(np.multiply(dx, dx), KERNEL_SIZE)
    dy_pow = sol4_utils.blur_spatial(np.multiply(dy, dy), KERNEL_SIZE)
    dx_dy_mul = sol4_utils.blur_spatial(np.multiply(dx, dy), KERNEL_SIZE)
    dy_dx_mul = sol4_utils.blur_spatial(np.multiply(dy, dx), KERNEL_SIZE)
    # calculating trace and it's power
    trace = np.add(dx_pow, dy_pow)
    trace_pow = np.multiply(trace, trace)
    # calculating determinant of matrix M
    det_ad = np.multiply(dx_pow, dy_pow)
    det_bc = np.multiply(dx_dy_mul, dy_dx_mul)
    det_M = np.subtract(det_ad, det_bc)
    # calculating response for each pixel in the image
    response_im = np.subtract(det_M, k * trace_pow)

    max_response = non_maximum_suppression(response_im)

    return np.stack(np.flip(np.where(max_response), axis=0), axis=-1)
Exemplo n.º 12
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    im_derivative_x = get_derivative(im, axis=0)
    im_derivative_y = get_derivative(im, axis=1)

    # Construct matrix M
    blurred_der_x_squared = sol4_utils.blur_spatial(im_derivative_x**2, 3)
    blurred_der_y_squared = sol4_utils.blur_spatial(im_derivative_y**2, 3)
    blurred_der_xy = sol4_utils.blur_spatial(im_derivative_x * im_derivative_y,
                                             3)
    blurred_der_yx = sol4_utils.blur_spatial(im_derivative_y * im_derivative_x,
                                             3)

    # Calculate det and tr matrices and then R
    det_m = blurred_der_x_squared * blurred_der_y_squared - blurred_der_xy * blurred_der_yx
    trace_m = blurred_der_x_squared + blurred_der_y_squared
    R = non_maximum_suppression(det_m - (harris_k * (trace_m**2)))

    result = np.argwhere(R.T)
    return result
def get_R(im):
    Ix = scipy.signal.convolve2d(im, X_DER_CONV, mode="same", boundary="symm")
    Iy = scipy.signal.convolve2d(im, Y_DER_CONV, mode="same", boundary="symm")
    Ix2 = sol4_utils.blur_spatial(Ix * Ix, 3)
    Iy2 = sol4_utils.blur_spatial(Iy * Iy, 3)
    IxIy = sol4_utils.blur_spatial(Ix * Iy, 3)
    m_traces = Ix2 + Iy2
    m_dets = (Ix2 * Iy2) - (IxIy * IxIy)
    return m_dets - K * m_traces * m_traces
Exemplo n.º 14
0
def get_M(im):
    """
    :param im: grayscale image: numpy array of dtype float64
    :return: Ix^2, Iy^2, IxIy : numpy arrays of dtype float64
    """
    x_der = derivative(im, get_der(X_DEV))
    y_der = derivative(im, get_der(Y_DEV))
    Ixy = x_der * y_der

    return sol4_utils.blur_spatial(np.square(x_der), BLUR_SIZE),\
           sol4_utils.blur_spatial(np.square(y_der), BLUR_SIZE),\
           sol4_utils.blur_spatial(Ixy, BLUR_SIZE)
Exemplo n.º 15
0
def harris_corner_detector(im):
    der_array = np.array([1,0,-1]).reshape(3,1)
    Ix = scipy.ndimage.filters.convolve(im, der_array)
    Iy = scipy.ndimage.filters.convolve(im, np.transpose(der_array))
    kernel = sol4_utils.get_guassian(3)
    IxIx = sol4_utils.blur_spatial(Ix*Ix, kernel)
    IxIy = sol4_utils.blur_spatial(Ix*Iy, kernel)
    IyIx = sol4_utils.blur_spatial(Iy*Ix, kernel)
    IyIy = sol4_utils.blur_spatial(Iy*Iy, kernel)
    R = (IxIx*IyIy-IyIx*IxIy) - 0.04*((IxIx+IyIy)**2)
    binary_local_maximum = sol4_add.non_maximum_suppression(R)
    return np.transpose(np.roll(np.nonzero(binary_local_maximum), 1, axis=0))
def harris_mat(I_x, I_y, kernel_size):
    """
  genreate the harris matrix
  :param I_x:#x derivatives
  :param I_y:
  :param kernel_size:
  :return: harris matrix elements
  """
    I_x2 = sol4_utils.blur_spatial(I_x**2, kernel_size)
    I_y2 = sol4_utils.blur_spatial(I_y**2, kernel_size)
    I_yx = sol4_utils.blur_spatial(I_y * I_x, kernel_size)
    return I_x2, I_y2, I_yx
Exemplo n.º 17
0
def harris_corner_detector(im):
    div = (np.array([-1, 0, 1])).reshape(1, 3)
    Ix = convolve(im, div)
    Iy = convolve(im, np.transpose(div))
    IxIx = sol4_utils.blur_spatial(Ix * Ix, 3)
    IxIy = sol4_utils.blur_spatial(Ix * Iy, 3)
    IyIy = sol4_utils.blur_spatial(Iy * Iy, 3)
    k = 0.04
    M = np.dstack((IxIx, IxIy, IxIy, IyIy))
    M = M.reshape(M.shape[0], M.shape[1], 2, 2)
    R = np.linalg.det(M[:, :]) - k * (np.trace(M, axis1=2, axis2=3)**2)
    ret = np.dstack(np.where(sol4_add.non_maximum_suppression(R.transpose())))
    return ret.reshape(ret.shape[1], 2)
Exemplo n.º 18
0
def harris_corner_detector(im):
    """
  Detects harris corners.
  Make sure the returned coordinates are x major!!!
  :param im: A 2D array representing an image.
  :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.  
  """
    der_im_x = scipy.ndimage.filters.convolve(im, X_DERIVATIVE)
    der_im_y = scipy.ndimage.filters.convolve(im, Y_DERIVATIVE)
    blur_im_x = sol4_utils.blur_spatial((der_im_x * der_im_x), 3)
    blur_im_y = sol4_utils.blur_spatial((der_im_y * der_im_y), 3)
    blur_xy = sol4_utils.blur_spatial((der_im_x * der_im_y), 3)
    R = blur_im_x * blur_im_y - blur_xy * blur_xy - K * np.power(
        (blur_im_x * blur_im_y), 2)
    bool_im = non_maximum_suppression(R)
    return np.argwhere(np.transpose(bool_im))
Exemplo n.º 19
0
def harris_corner_detector(im):
    #############################################################
    # implements harris method for corner detection
    #############################################################
    dx = np.array([[1, 0, -1]])
    dy = dx.transpose()
    Ix = sg.convolve2d(im, dx, mode="same")
    Iy = sg.convolve2d(im, dy, mode="same")

    Ix_blur = sut.blur_spatial(Ix**2, 3)
    Iy_blur = sut.blur_spatial(Iy**2, 3)
    IxIy_blur = sut.blur_spatial(Ix * Iy, 3)
    # compute determinant and trace of M
    det = Ix_blur * Iy_blur - IxIy_blur**2
    tr = Ix_blur + Iy_blur
    R = det - 0.04 * (tr**2)
    return np.transpose(np.nonzero(sad.non_maximum_suppression(R)))
Exemplo n.º 20
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """

    con_der_vec = np.array([1, 0, -1]).reshape((1, 3))
    I_x = convolve(im, con_der_vec)
    I_y = convolve(im, con_der_vec.T)
    I_x_2 = sol4_utils.blur_spatial(I_x * I_x, 3)
    I_y_2 = sol4_utils.blur_spatial(I_y * I_y, 3)
    I_x_y = sol4_utils.blur_spatial(I_x * I_y, 3)
    R_mat = I_x_2 * I_y_2 - I_x_y * I_x_y - 0.04 * np.power(I_x_2 + I_y_2, 2)
    R_mat = non_maximum_suppression(R_mat)
    return np.argwhere(R_mat.T)
Exemplo n.º 21
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing a greyscale image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    Ix = get_image_derivative(im, X_DERIVATIVE)
    Iy = get_image_derivative(im, Y_DERIVATIVE)
    Ix2_blur = sol4_utils.blur_spatial((Ix * Ix), DERIVATIVES_BLUR_KERNEL_SIZE)
    Iy2_blur = sol4_utils.blur_spatial((Iy * Iy), DERIVATIVES_BLUR_KERNEL_SIZE)
    IxIy_blur = sol4_utils.blur_spatial((Ix * Iy),
                                        DERIVATIVES_BLUR_KERNEL_SIZE)
    IyIx = Iy * Ix
    R_matrix = calc_r_for_harris(Ix2_blur, IxIy_blur, IyIx, Iy2_blur)
    corners_im = non_maximum_suppression(R_matrix)
    return get_corners_coordinates(corners_im)
Exemplo n.º 22
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    dx = scipy.signal.convolve2d(im, der_vec, mode='same', boundary='symm')
    dy = scipy.signal.convolve2d(im, der_vec.T, mode='same', boundary='symm')
    blur_ix_squared = sol4_utils.blur_spatial(dx * dx, KERNEL_SIZE)
    blur_iy_squared = sol4_utils.blur_spatial(dy * dy, KERNEL_SIZE)
    blur_ix_iy = sol4_utils.blur_spatial(dx * dy, KERNEL_SIZE)
    det_m = blur_ix_squared * blur_iy_squared - blur_ix_iy * blur_ix_iy
    trace_m = blur_iy_squared + blur_ix_squared
    R = det_m - K * np.square(trace_m)
    R = non_maximum_suppression(R)
    return np.flip(np.argwhere(R).reshape(-1, 2), axis=1)
Exemplo n.º 23
0
def harris_corner_detector(im: np.ndarray) -> np.ndarray:
    """
    extract harris-corner key feature points
    :param im: the image to extract key points
    :return: An array with shape (N,2) of [x,y] key points locations in im.
    """
    ix = sol4_utils.sp_signal.convolve2d(im, DER_FILTER, 'same', 'wrap')
    iy = sol4_utils.sp_signal.convolve2d(im, DER_FILTER.T, 'same', 'wrap')
    ix_2 = sol4_utils.blur_spatial(ix**2, BLUR_SIZE)
    iy_2 = sol4_utils.blur_spatial(iy**2, BLUR_SIZE)
    ix_iy = sol4_utils.blur_spatial(ix * iy, BLUR_SIZE)
    r = ix_2 * iy_2 - ix_iy**2 - K * (ix_2 +
                                      iy_2)**2  # R - the response of the
    max_of_r = sol4_add.non_maximum_suppression(r)
    pos = np.transpose(np.nonzero(
        max_of_r))  # array of the indices of non-zero pixels in max_of_r
    pos_for_spread = np.transpose(np.array(
        [pos[:, 1], pos[:, 0]]))  # school function works with [yx]
    return pos_for_spread
Exemplo n.º 24
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing a gray scale image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    if len(im.shape) > 2:
        return
    # getting derivatives etc.
    dx, dy = convolve(im, X_DER), convolve(im, Y_DER)
    dx_2, dy_2, dxy = np.multiply(dx, dx), np.multiply(dy, dy), np.multiply(dx, dy)
    dx_2, dy_2, dxy = sol4_utils.blur_spatial(dx_2, 3), sol4_utils.blur_spatial(dy_2, 3), sol4_utils.blur_spatial(dxy, 3)
    # computing response
    r = (np.multiply(dx_2, dy_2) - np.multiply(dxy, dxy)) - K * ((dx_2 + dy_2) ** 2)
    arr = np.argwhere(non_maximum_suppression(r))
    fixed_arr = np.empty(arr.shape)
    fixed_arr[:, 1], fixed_arr[:, 0] = arr[:, 0], arr[:, 1]
    return fixed_arr
Exemplo n.º 25
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    deriv_vec = np.asarray([1, 0, -1]).reshape(1, 3)
    x_deriv = convolve(im, deriv_vec)
    y_deriv = convolve(im, deriv_vec.T)
    blur_x_squared = sol4_utils.blur_spatial(x_deriv * x_deriv, FILTER_SIZE)
    blur_y_squared = sol4_utils.blur_spatial(y_deriv * y_deriv, FILTER_SIZE)
    blur_xy = sol4_utils.blur_spatial(x_deriv * y_deriv, FILTER_SIZE)
    M_det = blur_x_squared * blur_y_squared - blur_xy * blur_xy
    M_trace = blur_y_squared + blur_y_squared
    R = M_det - 0.04 * (M_trace * M_trace)  # response image
    R_local_max = non_maximum_suppression(R)
    all_true_values = np.argwhere(R_local_max)
    return np.flip(all_true_values, axis=1)  # ordered as [column,row] i.e. [x,y]
Exemplo n.º 26
0
def harris_corner_detector(im):
    """
	Detects harris corners.
	Make sure the returned coordinates are x major!!!
	:param im: A 2D array representing an image.
	:return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
	"""
    dx = convolve(im, DERIVATIVE_X_DIRECTION, mode='wrap')
    dy = convolve(im, DERIVATIVE_Y_DIRECTION, mode='wrap')
    dx_2 = sol4_utils.blur_spatial(np.power(dx, 2), 3).flatten()
    dy_2 = sol4_utils.blur_spatial(np.power(dy, 2), 3).flatten()
    dxy = sol4_utils.blur_spatial(np.multiply(dx, dy), 3).flatten()
    m_matrix = (np.array((dx_2, dxy, dxy, dy_2)).T).reshape(dxy.shape[0], 2, 2)
    response_im = (
        np.linalg.det(m_matrix) -
        0.04 * np.power(np.matrix.trace(m_matrix, axis1=2), 2)).reshape(
            im.shape)
    points = np.argwhere(non_maximum_suppression(response_im))
    return np.flip(points, axis=1)
Exemplo n.º 27
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    ix = convolve2d(im, CONV_VEC, mode='same', boundary='symm')
    iy = convolve2d(im, CONV_VEC.T, mode='same', boundary='symm')
    ix_square = sol4_utils.blur_spatial(ix * ix, BLUR_KERNEL_SIZE)
    iy_square = sol4_utils.blur_spatial(iy * iy, BLUR_KERNEL_SIZE)
    ix_iy = sol4_utils.blur_spatial(ix * iy, BLUR_KERNEL_SIZE)
    det_m = ix_square * iy_square - ix_iy * ix_iy  # det of M for each pixel
    trace_m = ix_square + iy_square  # trace of M for each pixel
    r_matrix = det_m - HARRIS_K * (trace_m**2)  # response image of im
    corners = non_maximum_suppression(r_matrix)
    corners = np.nonzero(corners)
    return np.transpose(
        (corners[1], corners[0]))  # row is y coord and col is x coord
Exemplo n.º 28
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    i_x = convolve(im, np.array([[1, 0, -1]]))
    i_y = convolve(im, np.array([[1], [0], [-1]]))
    i_x_2 = sol4_utils.blur_spatial(i_x * i_x, 3)
    i_y_2 = sol4_utils.blur_spatial(i_y * i_y, 3)
    i_x_y = sol4_utils.blur_spatial(i_x * i_y, 3)
    i_y_x = sol4_utils.blur_spatial(i_y * i_x, 3)
    # determinant
    det = (i_x_2 * i_y_2) - (i_x_y * i_y_x)
    # trace
    trace = i_x_2 + i_y_2
    harris_response = det - 0.04 * (trace * trace)
    r_after_nms = np.transpose(non_maximum_suppression(harris_response))
    return np.argwhere(r_after_nms == 1)
Exemplo n.º 29
0
def harris_corner_detector(im):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner
    points.
    """
    d = np.array(DERIV_VEC).reshape(3, 1)
    Ix = scipy.signal.convolve2d(im, d, mode='same', boundary='symm')
    Iy = scipy.signal.convolve2d(im, d.T, mode='same', boundary='symm')
    Ix__blur = sol4_utils.blur_spatial(Ix**2, DERIV_VEC_SIZE)
    Iy_blur = sol4_utils.blur_spatial(Iy**2, DERIV_VEC_SIZE)
    Ixy_blur = sol4_utils.blur_spatial(Ix * Iy, DERIV_VEC_SIZE)
    detM = Ix__blur * Iy_blur - Ixy_blur**2
    traceM = Ix__blur + Iy_blur
    R = detM - K * (traceM**2)
    binary_im = non_maximum_suppression(R)
    xy_corners = np.where(binary_im)
    yx_corners = np.vstack((xy_corners[1], xy_corners[0]))
    return yx_corners.T
Exemplo n.º 30
0
def harris_corner_detector(im, M=None):
    """
    Detects harris corners.
    Make sure the returned coordinates are x major!!!
    :param im: A 2D array representing an image.
    :return: An array with shape (N,2), where ret[i,:] are the [x,y] coordinates of the ith corner points.
    """
    der_filter = np.array([1, 0, -1]).reshape(1, 3)

    Ix = convolve(im, der_filter)
    Iy = convolve(im, der_filter.T)
    Ix_sqaured = sol4_utils.blur_spatial(np.square(Ix), KERNEL_SIZE)
    Iy_sqaured = sol4_utils.blur_spatial(np.square(Iy), KERNEL_SIZE)
    Ix_y = sol4_utils.blur_spatial(Ix * Iy, KERNEL_SIZE)
    det_M = (Ix_sqaured * Iy_sqaured) - (np.square(Ix_y))
    trace_M = Ix_sqaured + Iy_sqaured
    # M = np.array([[Ix_sqaured, Ix_y],[Iy_x, Iy_sqaured]])
    R = det_M - (K * np.square(trace_M))
    bin_im = non_maximum_suppression(R)
    y, x = np.where(bin_im)
    return np.stack((x, y)).T