Esempio n. 1
0
def findDerivatives(I_gray):

    # 2D Gaussian kernel
    G = utils.GaussianPDF_2D(0, 1, 10, 10)

    # Deviation vectors/filter for horizontal and vertical direction (to compute gradient of Gaussian)
    dx = [[1.0, 0.0, -1.0]]
    dy = [[1.0], [0.0], [-1.0]]

    # Perform convolution of Gaussian and filters, get gradient of Gaussian (10 by 10)
    Gx = signal.convolve2d(G, dx, mode='same', boundary='symm')
    Gy = signal.convolve2d(G, dy, mode='same', boundary='symm')

    # Perform convolution of original image matrix and gradient matrix
    ix = signal.convolve2d(I_gray, Gx, mode='same', boundary='symm')
    iy = signal.convolve2d(I_gray, Gy, mode='same', boundary='symm')

    # Compute magnitude of the gradient
    im = np.sqrt(np.square(ix) + np.square(iy))

    # Get gradient of the image
    idx = signal.convolve2d(I_gray, dx, mode='same')
    idy = signal.convolve2d(I_gray, dy, mode='same')

    # Get orientation of the edge
    orientation = np.arctan(np.divide(idy, idx))

    return im, ix, iy, orientation
Esempio n. 2
0
def findDerivatives(I_gray):

    ## ==========Filter out noise
    img = ndimage.gaussian_filter(I_gray, sigma=1.5, order=0)
    # plt.imshow(img, cmap='gray', vmin=0, vmax=255)
    # plt.show()

    ## ==========Compute derivative
    dx, dy = np.gradient(utils.GaussianPDF_2D(0, 0.5, 5, 5), axis=(1, 0))
    Ix = signal.convolve2d(img, dx, 'same')
    Iy = signal.convolve2d(img, dy, 'same')
    # plt.imshow(Ix, cmap='gray')
    # plt.show()
    # plt.imshow(Iy, cmap='gray')
    # plt.show()

    ## ==========Compute the magnitude
    Mag = np.sqrt(Ix * Ix + Iy * Iy)
    # plt.imshow(Mag, cmap='gray')
    # plt.show()

    ## =========Compute orientation
    Ori = np.arctan2(Iy, Ix + 0.0001)

    return Mag, Ix, Iy, Ori
def findDerivatives(I_gray):
    # TODO: your code here
    Gausian = utils.GaussianPDF_2D(0.1, 0.5, 5, 5)
    dx, dy = np.gradient(Gausian, axis=(1, 0))
    Ix = signal.convolve2d(I_gray, dx, 'same')
    Iy = signal.convolve2d(I_gray, dy, 'same')
    Im = np.sqrt(Ix * Ix + Iy * Iy)
    Ori = np.arctan(Iy / Ix)
    return Im, Ix, Iy, Ori
Esempio n. 4
0
def findDerivatives(I_gray):
    #G_1D = utils.GaussianPDF_1D(0,0.5,10)
    G_2D = utils.GaussianPDF_2D(0, 0.5, 10, 10)
    dx, dy = np.gradient(G_2D)

    Magx = signal.convolve2d(I_gray, dx, 'same')
    Magy = signal.convolve2d(I_gray, dy, 'same')
    Mag = np.sqrt(Magx * Magx + Magy * Magy)
    Ori = np.arctan(Magy, Magx)

    return Mag, Magx, Magy, Ori
Esempio n. 5
0
def findDerivatives(I_gray):
  # TODO: your code here
  mu=0
  sigma=2
  G=utils.GaussianPDF_2D(mu, sigma, 3,3)#form 2d gussian
  dx,dy=np.gradient(G, axis=(1,0))#form 2d gussian derivative in x and y direction
  
  Magx=signal.convolve2d(I_gray,dx,'same')
  Magy=signal.convolve2d(I_gray,dy,'same')
  
  Mag=np.sqrt(Magx*Magx+Magy*Magy)
  Ori=np.arctan2(Magy,Magx,out=None)

  return [Mag,Magx,Magy,Ori]
Esempio n. 6
0
def findDerivatives(I_gray):
    # TODO: your code here

    # Gaussian filter
    #G = np.array([[2, 4, 5, 4, 2], [4, 9, 12, 9, 4], [5, 12, 15, 12, 5], [4, 9, 12, 9, 4], [2, 4, 5, 4, 2]])
    #G = np.matrix('2,4,5,4,2; 4,9,12,9,4; 5,12,15,12,5; 4,9,12,9,4; 2,4,5,4,2') #sigma=1.4
    #G = G/159;
    #Ga = np.squeeze(np.asarray(G))

    #less sigma, more blurred edge
    mu = 0
    sigma = 0.4  #0.4
    Ga = utils.GaussianPDF_2D(mu, sigma, 5, 5)

    # Filter
    dx = np.array([[1, 0, -1]])  # Horizontal
    dy = np.array([[1], [0], [-1]])  # Vertical
    #dx = np.array([[1, -1]]) # Horizontal
    #dy = np.array([[1],[-1]]) # Vertical

    # Convolution of image
    #Gx = np.convolve(G, dx, 'same')
    #Gy = np.convolve(G, dy, 'same')
    #lx = np.convolve(I_gray, Gx, 'same')
    #ly = np.convolve(I_gray, Gy, 'same')

    Gx = scipy.signal.convolve2d(Ga, dx, boundary='fill', mode='same')
    Gy = scipy.signal.convolve2d(Ga, dy, boundary='fill', mode='same')
    lx = scipy.signal.convolve2d(I_gray, Gx, boundary='fill', mode='same')
    ly = scipy.signal.convolve2d(I_gray, Gy, boundary='fill', mode='same')

    # Magnitude
    Mag = np.sqrt(lx * lx + ly * ly)

    # Angle
    angle = np.arctan(ly / lx)
    angle[angle < 0] = math.pi + angle[angle < 0]
    angle[angle > 7 * math.pi / 8] = math.pi - angle[angle > 7 * math.pi / 8]
    '''
  # Edge angle discretization into 0, pi/4, pi/2, 3*pi/4
  angle[angle>=0 and angle<math.pi/8] = 0
  angle[angle>=math.pi/8 and angle<3*math.pi/8] = math.pi/4
  angle[angle>=3*math.pi/8 and angle<5*math.pi/8] = math.pi/2
  angle[angle>=5*math.pi/8 and angle<=7*math.pi/8] = 3*math.pi/4
  '''

    return Mag
Esempio n. 7
0
def feat_desc(img, x, y):
    pad = np.zeros([img.shape[0] + 80, img.shape[1] + 80])

    mu = 0
    sigma = 1  # 0.4
    # gau = np.matrix([[2, 4, 5, 4, 2], [4, 9, 12, 9, 4], [5, 12, 15, 12, 5], [4, 9, 12, 9, 4], [2, 4, 5, 4, 2]])
    # gau = np.asarray(gau)
    gau = utils.GaussianPDF_2D(mu, sigma, 10, 10)
    # gau = 1 / 159 * gau
    '''dx = np.matrix([1, 0, -1])
    dy = np.matrix([[1], [0], [-1]])
    dx = np.asarray(dx)
    dy = np.asarray(dy)
    Gx = signal.convolve2d(gau, dx, 'same')
    Gy = signal.convolve2d(gau, dy, 'same')'''

    lx = signal.convolve2d(img, gau, 'same')
    ly = signal.convolve2d(img, gau, 'same')

    blurImg = lx + ly
    #plt.imshow(blurImg)
    # plt.show()
    pad[40:img.shape[0] + 40, 40:img.shape[1] + 40] = blurImg
    offset = 40
    output = np.zeros([64, x.size])
    for i in range(x.size):
        windowB = pad[x[i][0] + offset - 20:x[i][0] + offset + 20, y[i][0] + offset - 20:y[i][0] + offset + 20]
        for j in range(0, 64):
            row = (j + 1) // 8
            if (j + 1) % 8 == 0:
                row = (j + 1) // 8 - 1
            col = (j + 1) % 8 - 1
            if col == -1:
                col = 7
            subB = windowB[0 + row*5:row*5 + 4, 0 + col*5:col*5+4]
            output[j, i] = subB.max()
        output_mean = np.sum(output[:, i]) / 64
        output_var = np.std(output[:, i])
        if output_var != 0:
            output[:, i] = (output[:, i] - output_mean) / output_var
        else:
            output[:, i] = 0
    return output
Esempio n. 8
0
def findDerivatives(I_gray):

  g=utils.GaussianPDF_2D(0.1,1,5,5)
  #print(g)

  x=np.array([[0,0,0],[1,0,-1],[0,0,0]])
  y=np.array([[0,1,0],[0,0,0],[0,-1,0]])
  #print(x.shape)
  #I_gray1=signal.convolve2d(I_gray,g,mode='same')


  dx=signal.convolve2d(g,x,mode='same')
  dy=signal.convolve2d(g,y,mode='same')

  i_gx=signal.convolve2d(I_gray,dx,'same')
  i_gy=signal.convolve2d(I_gray,dy,'same')


  #plt.imshow(i_gy,cmap='gray')

  M=np.sqrt(i_gx*i_gx + i_gy*i_gy)
  ang1=np.arctan2(i_gy,i_gx)
  return M,i_gx,i_gy,ang1