Example #1
0
def magnitude(I, point):
  """
  Input : Image I, point point
  Output: outputs the magnitude
  """
  w = h.create_window(I, point, 3)
  mag = math.sqrt((w[1][0] - w[1][2])**2 + (w[0][1] - w[2][1])**2)
  return(mag)
Example #2
0
def magnitude(I, point):
    """
  Input : Image I, point point
  Output: outputs the magnitude
  """
    w = h.create_window(I, point, 3)
    mag = math.sqrt((w[1][0] - w[1][2])**2 + (w[0][1] - w[2][1])**2)
    return (mag)
Example #3
0
def orientation(I, point):
  """
  Input : Image I, point point
  Output: orientation of image
  """
  w = h.create_window(I, point, 3)
  Ly = w[0][1] - w[2][1]
  Lx = w[1][0] - w[1][2]
  theta = 0.5 * math.pi - math.atan2(Lx, Ly)
  theta = math.degrees(theta % (2 * math.pi))
  return(theta)
Example #4
0
def orientation(I, point):
    """
  Input : Image I, point point
  Output: orientation of image
  """
    w = h.create_window(I, point, 3)
    Ly = w[0][1] - w[2][1]
    Lx = w[1][0] - w[1][2]
    theta = 0.5 * math.pi - math.atan2(Lx, Ly)
    theta = math.degrees(theta % (2 * math.pi))
    return (theta)
Example #5
0
def sift_orientation(I_name, points):
    window_size = 16
    """
  Input : image I, interest points, size of window
  Output: assigns an orientation to the interest points
  """
    k_con = math.sqrt(2)
    k = math.sqrt(2)
    """
  sigma1 = np.array([k_con/2, 1.0, k_con , k_con ** 2, k_con ** 3, \
                     k_con, k_con ** 2, k_con ** 3, k_con ** 4, k_con ** 5, \
                     k_con ** 3, k_con ** 4, k_con ** 5, k_con ** 6, k_con ** 7, \
                     k_con ** 5, k_con ** 6, k_con ** 7, k_con ** 8, k_con ** 9])
  """

    sigma1 = np.array([1.3, 1.6, 1.6 * k, 1.6 * k ** 2, 1.6 * k ** 3, \
    1.6 * k, 1.6 * k ** 2, 1.6 * k ** 3, 1.6 * k ** 4, 1.6 * k ** 5, \
    1.6 * k ** 3, 1.6 * k ** 4, 1.6 * k ** 5, 1.6 * k ** 6, 1.6 * k ** 7, \
    1.6 * k ** 5, 1.6 * k ** 6, 1.6 * k ** 7, 1.6 * k ** 8, 1.6 * k ** 9, \
    1.6 * k ** 7, 1.6 * k ** 8, 1.6 * k ** 9, 1.6 * k ** 10, 1.6 * k ** 11])

    I = cv2.imread(I_name).astype(float)
    I_show = cv2.imread(I_name).astype(float)

    I0 = cv2.imread(I_name, 0).astype(float)
    I1 = misc.imresize(I0, 50, 'bilinear').astype(float)
    I2 = misc.imresize(I0, 25, 'bilinear').astype(float)
    I3 = misc.imresize(I0, 1 / 8.0, 'bilinear').astype(float)
    I4 = misc.imresize(I0, 1 / 16.0, 'bilinear').astype(float)

    o0sc = np.zeros((5, I0.shape[0], I0.shape[1]))
    o1sc = np.zeros((5, I1.shape[0], I1.shape[1]))
    o2sc = np.zeros((5, I2.shape[0], I2.shape[1]))
    o3sc = np.zeros((5, I3.shape[0], I3.shape[1]))
    o4sc = np.zeros((5, I4.shape[0], I4.shape[1]))

    for i in range(0, 5):
        """
    o1sc[i,:,:] = cv2.filter2D(I0, -1, h.gauss(9, sigma1[i]))
    o2sc[i,:,:] = misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 5])), 50, 'bilinear').astype(float)
    o3sc[i,:,:] = misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 10])), 25, 'bilinear').astype(float)
    o4sc[i,:,:] = misc.imresize(misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 15])), 25, 'bilinear').astype(float), 50, 'bilinear').astype(float)
    """

        o0sc[i, :, :] = ndimage.filters.gaussian_filter(I0, sigma1[i])
        o1sc[i, :, :] = misc.imresize(
            ndimage.filters.gaussian_filter(I0, sigma1[i]), 50, 'bilinear')
        o2sc[i, :, :] = misc.imresize(
            ndimage.filters.gaussian_filter(I0, sigma1[i]), 25, 'bilinear')
        o3sc[i, :, :] = misc.imresize(
            ndimage.filters.gaussian_filter(I0, sigma1[i]), 1 / 8.0,
            'bilinear')
        o4sc[i, :, :] = misc.imresize(
            ndimage.filters.gaussian_filter(I0, sigma1[i]), 1 / 16.0,
            'bilinear')

    I = [o0sc[0], o0sc[1], o0sc[2], o0sc[3], o0sc[4], o1sc[0], o1sc[1], o1sc[2], o1sc[3], o1sc[4], \
         o2sc[0], o2sc[1], o2sc[2], o2sc[3], o2sc[4], o3sc[0], o3sc[1], o3sc[2], o3sc[3], o3sc[4], \
         o4sc[1], o4sc[2], o4sc[3], o4sc[4], o4sc[4]]

    # point with orientation; [y, x, s, o]

    final_points = []
    ret_points = []

    # length of outer list
    o = 0
    for p in points:
        counter = 1
        max_size_y = len(I[int(p[2])]) - (window_size)
        max_size_x = len(I[int(p[2])][0]) - (window_size)
        min_size_y = window_size
        min_size_x = window_size
        if ((p[0] < max_size_y) and (min_size_y < p[0]) and \
            (p[1] < max_size_x and min_size_x < p[1])):
            if (p[2] > 5 and p[2] < 8):
                cv2.circle(I_show, (int(p[1] * 2), int(p[0] * 2)), 12,
                           (0, 255, 0), 2)
            if (p[2] > 10 and p[2] < 13):
                cv2.circle(I_show, (int(p[1] * 4), int(p[0] * 4)), 24,
                           (255, 0, 0), 2)
            if (p[2] > 15 and p[2] < 18):
                cv2.circle(I_show, (int(p[1] * 8), int(p[0] * 8)), 30,
                           (125, 125, 0), 2)

            final_points.append(p)
            o += 1
    cv2.imwrite("points.jpg", I_show)

    # size of all usable points o

    print("length of usable points, orientation", o)
    i = 0
    for p in final_points:
        bins = np.zeros([36])
        window_size = 16
        gauss_window = h.gauss(window_size, 1.5 * p[2])
        ip_window = h.create_window(I[int(p[2])], p, window_size + 2)
        orien_of_bin = []

        # creates bin for each point
        hold_mag = np.empty((window_size, window_size))
        hold_ori = np.empty((window_size, window_size))
        for y in range(0, window_size):
            for x in range(0, window_size):
                magnitude_p = magnitude(ip_window, [y + 1, x + 1])
                orientation_p = orientation(ip_window, [y + 1, x + 1])
                orientation_p = math.floor(orientation_p / 10.0)
                hold_mag[y, x] = magnitude_p
                hold_ori[y, x] = orientation_p

        hold_mag = np.multiply(hold_mag, gauss_window)
        hold_mag = np.reshape(hold_mag, -1)
        hold_ori = np.reshape(hold_ori, -1)

        for j in range(0, len(hold_ori)):
            bins[hold_ori[j]] += hold_mag[j]

        # index of max element in bin
        max_index = bins.argmax()

        max_val = bins[max_index]

        for j in range(0, 35):
            if (bins[j] >= max_val * 0.8):
                orien_of_bin.append(j)

        new_orien = list(orien_of_bin)

        cc = 0
        for i in new_orien:
            if (i == 1):
                A = 0
                B = bins[i]
                C = bins[i + 1]
            if (i == 35):
                A = bins[i - 1]
                B = bins[i]
                C = 0
            else:
                A = bins[i - 1]
                B = bins[i]
                C = bins[i + 1]
            a = A + (C - A) / 2.0 - B
            b = (C - A) / 2.0
            c = B
            if (b == 0 or a == 0):
                toppoint = 0
            else:
                toppoint = -b / (2 * a)
            degree = (toppoint * 10) + i * 10
            #print(degree)

            if (degree < 0):
                degree = 360.0 + degree
            ret_points.append([p[0], p[1], p[2], degree])
            cc += 1

            if (cc == 1):
                break

        counter += 1

    ret_points = np.array(ret_points)
    return (ret_points)
Example #6
0
def decriptor_representation(Img, points_orientations):

  I = cv2.imread(Img, 0)

  window_size = 16
  max_point_size_y = len(I) - (window_size + 2)
  min_point_size_y = window_size
  max_point_size_x = len(I[0]) - (window_size + 5)
  min_point_size_x = window_size 
  gauss_window = h.gauss(window_size, 8)
  points = points_orientations

  final_points = []
  orien_of_bin = []

  len_of_desc = len(points)

  mag_bin = numpy.zeros([len_of_desc, 16, 4, 4])
  ori_bin = numpy.zeros([len_of_desc, 16, 4, 4])
  final_desc = numpy.zeros([len_of_desc, 128])

  incrementeur = 0
  for p in points:

    hold_mag = h.create_window(I, [35,35], window_size)
    hold_ori = h.create_window(I, [35,35], window_size)

    ip_window = h.create_window(I, p, window_size + 2) 

    # creates bin for each point
    for y in range(0, window_size):
      for x in range(0, window_size):
        magnitude_p = magnitude(ip_window, [y + 1, x + 1])
        orientation_p = orientation(ip_window, [y + 1, x + 1])
        hold_mag[y][x] = magnitude_p
        hold_ori[y][x] = orientation_p

    hold_mag = numpy.multiply(hold_mag, gauss_window)
    hold_mag = numpy.reshape(hold_mag, -1)
    hold_ori = numpy.reshape(hold_ori, -1)

    holder = numpy.zeros([4,4])
    v = 0
    for w in range(0, 4):
      for i in range(0, 13, 4):
        for j in range(0, 4):
          for k in range(0, 4):
            mag_bin[incrementeur][v][j][k] = hold_mag[k + i + j * 16 + w * 64]
            ori = math.floor((360 - hold_ori[k + i + j * 16 + w * 64]) / 45.0) - 1
            #print(hold_ori[k + i + j * 16 + w * 64]) / 45.0))
            ori_bin[incrementeur][v][j][k] = ori

        v += 1

    #with open('file2.txt','a') as f_handle:
    #  numpy.savetxt(f_handle, ori_bin[incrementeur], delimiter=" ", fmt="%s")

    #numpy.savetxt('file2.txt', d_bin[incrementeur], delimiter=" ", fmt="%s")
    incrementeur += 1

  mag_val = 0
  ori_val = 0
  #print("\n\n\n")
  for w in range(0, len(points)):
    for i in range(0, 16):
      for j in range(0, 4):
        for k in range(0, 4):
          mag_val = mag_bin[w][i][k][j]
          ori_val = ori_bin[w][i][k][j]
          #print(ori_val, ori_val + 8*i)
          #print("\n\n")
          final_desc[w][8*i + ori_val] += mag_val
  
  for vec_i in range(0, len(final_desc)):
    final_desc[vec_i] = final_desc[vec_i] / numpy.linalg.norm(final_desc[vec_i])
    final_desc[vec_i] = numpy.clip(final_desc[vec_i], 0, 0.2)
    final_desc[vec_i] = final_desc[vec_i] / numpy.linalg.norm(final_desc[vec_i])


  
  oo = open("descriptor.txt", "w")
  for ff in final_desc:
    for j in range(0,128):
      oo.write(str(ff[j]) + "\n")
    oo.write("\n\n")
  oo.close()



  return(final_desc)
Example #7
0
def sift_orientation(I, points, window_size):
  window_size = 16
  """
  Input : image I, interest points, size of window
  Output: assigns an orientation to the interest points
  """

  # point with orientation; [[y, x],[o1, o2, o3]]
  pwo = []
  max_point_size_y = len(I[0]) - (window_size + 2)
  min_point_size_y = window_size
  max_point_size_x = len(I[0][0]) - (window_size + 5)
  min_point_size_x = window_size 

  hold_mag = h.create_window(I[0], [35,35], window_size)
  hold_ori = h.create_window(I[0], [35,35], window_size)
  final_points = []
  orien_of_bin = []
  

  # length of outer list
  o = 0
  for p in points:
    if ((p[0] < max_point_size_y and min_point_size_y < p[0]) and \
        (p[1] < max_point_size_x and min_point_size_x < p[1])):
      final_points.append(p)
      o += 1

  # size of all usable points o
  bins = numpy.zeros([o,  1, 36])

  i = 0
  for p in final_points:
    # if a point is too close to the border of the image, it is discarded
    if ((p[0] < max_point_size_y and p[0] > min_point_size_y) and \
        (p[1] < max_point_size_x and p[1] > min_point_size_x)):

      # the sigma value for the gauss window, is 1.5 * scale
      # NOTE! Only works for first octave
      gauss_window = h.gauss(window_size, 1.5 + (1 * p[2]))
      print(p)
      ip_window = h.create_window(I[p[2]], p, window_size + 2) 

      # creates bin for each point
      for y in range(0, window_size):
        for x in range(0, window_size):
          magnitude_p = magnitude(ip_window, [y + 1, x + 1])
          orientation_p = orientation(ip_window, [y + 1, x + 1])
          orientation_p = math.floor(orientation_p/10.0)
          hold_mag[y][x] = magnitude_p
          hold_ori[y][x] = orientation_p

      hold_mag = numpy.multiply(hold_mag, gauss_window)
      hold_mag = numpy.reshape(hold_mag, -1)
      hold_ori = numpy.reshape(hold_ori, -1)

      for j in range(0, len(hold_ori)):
        bins[i][0][hold_ori[j]] += hold_mag[j]

      hold_mag = h.create_window(I[0], [35,35], window_size)
      hold_ori = h.create_window(I[0], [35,35], window_size)

      bin_i = bins[i][0]
        
      # index of max element in bin
      max_index = max(bin_i)
      max_index = [k for k, j in enumerate(bin_i) if j == max_index]
        
      # finds points within 80% of interest point

      holder_bin = []
      holder_bin.append(max_index[0])
      max_val = bin_i[max_index]

      for j in range(0, 35):
        if (bin_i[j] >= max_val * 0.8 and j != max_index[0]):
          holder_bin.append(j)
      orien_of_bin.append(holder_bin)
    i += 1

  new_orien = list(orien_of_bin)
  for i in range(0, len(orien_of_bin)):
    holder = []
    for j in orien_of_bin[i]:
      if (j == 1):
        A = 0
        B = bins[i][0][j] 
        C = bins[i][0][j]
      if (j == 35):
        A = bins[i][0][j-1]
        B = bins[i][0][j]
        C = 0
      else:
        A = bins[i][0][j - 1]
        B = bins[i][0][j]
        C = bins[i][0][j + 1]
      a = A + (C-A)/2.0 -B
      b = (C-A)/2.0
      c = B
      toppoint = -b / (2 * a)
      point = toppoint * 10 + j * 10

      if (point < 0):
        point = 360.0 + point
      holder.append(point)
    new_orien[i] = holder

  o = open('orients.txt', 'w')
  for i in  range(0, len(orien_of_bin)):
    o.write(str(orien_of_bin[i]) + "\t" + str(new_orien[i]) + "\n")
  o.close()


  #print([final_points,new_orien])
  final_points2 = []
  for i in range(0, len(final_points)):
    for o in new_orien[i]:
      final_points2.append([final_points[i][0], final_points[i][1], o])

  oo = open('interest_p_ori_mag.txt', 'w')
  for pp in final_points2:
    oo.write(str(pp[0]) + " " + str(pp[1]) + " " + str(pp[2]) + "\n")
  oo.close()

  #print(final_points2)
  return (final_points2)
Example #8
0
def sift_orientation(I_name, points):
  window_size = 16
  """
  Input : image I, interest points, size of window
  Output: assigns an orientation to the interest points
  """
  k_con = math.sqrt(2)
  k = math.sqrt(2)
  """
  sigma1 = np.array([k_con/2, 1.0, k_con , k_con ** 2, k_con ** 3, \
                     k_con, k_con ** 2, k_con ** 3, k_con ** 4, k_con ** 5, \
                     k_con ** 3, k_con ** 4, k_con ** 5, k_con ** 6, k_con ** 7, \
                     k_con ** 5, k_con ** 6, k_con ** 7, k_con ** 8, k_con ** 9])
  """

  sigma1 = np.array([1.3, 1.6, 1.6 * k, 1.6 * k ** 2, 1.6 * k ** 3, \
  1.6 * k, 1.6 * k ** 2, 1.6 * k ** 3, 1.6 * k ** 4, 1.6 * k ** 5, \
  1.6 * k ** 3, 1.6 * k ** 4, 1.6 * k ** 5, 1.6 * k ** 6, 1.6 * k ** 7, \
  1.6 * k ** 5, 1.6 * k ** 6, 1.6 * k ** 7, 1.6 * k ** 8, 1.6 * k ** 9, \
  1.6 * k ** 7, 1.6 * k ** 8, 1.6 * k ** 9, 1.6 * k ** 10, 1.6 * k ** 11])

  I = cv2.imread(I_name).astype(float)
  I_show = cv2.imread(I_name).astype(float)

  I0 = cv2.imread(I_name, 0).astype(float)
  I1 = misc.imresize(I0, 50, 'bilinear').astype(float)
  I2 = misc.imresize(I0, 25, 'bilinear').astype(float)
  I3 = misc.imresize(I0, 1/8.0, 'bilinear').astype(float)
  I4 = misc.imresize(I0, 1/16.0, 'bilinear').astype(float)

  o0sc = np.zeros((5, I0.shape[0],I0.shape[1]))
  o1sc = np.zeros((5, I1.shape[0],I1.shape[1]))
  o2sc = np.zeros((5, I2.shape[0],I2.shape[1]))
  o3sc = np.zeros((5, I3.shape[0],I3.shape[1]))
  o4sc = np.zeros((5, I4.shape[0],I4.shape[1]))

  for i in range(0,5):
    """
    o1sc[i,:,:] = cv2.filter2D(I0, -1, h.gauss(9, sigma1[i]))
    o2sc[i,:,:] = misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 5])), 50, 'bilinear').astype(float)
    o3sc[i,:,:] = misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 10])), 25, 'bilinear').astype(float)
    o4sc[i,:,:] = misc.imresize(misc.imresize(cv2.filter2D(I0, -1, h.gauss(9,sigma1[i + 15])), 25, 'bilinear').astype(float), 50, 'bilinear').astype(float)
    """

    o0sc[i,:,:] = ndimage.filters.gaussian_filter(I0, sigma1[i])
    o1sc[i,:,:] = misc.imresize(ndimage.filters.gaussian_filter(I0, sigma1[i]), 50, 'bilinear')
    o2sc[i,:,:] = misc.imresize(ndimage.filters.gaussian_filter(I0, sigma1[i]), 25, 'bilinear')
    o3sc[i,:,:] = misc.imresize(ndimage.filters.gaussian_filter(I0, sigma1[i]), 1/8.0, 'bilinear')
    o4sc[i,:,:] = misc.imresize(ndimage.filters.gaussian_filter(I0, sigma1[i]), 1/16.0, 'bilinear')

  I = [o0sc[0], o0sc[1], o0sc[2], o0sc[3], o0sc[4], o1sc[0], o1sc[1], o1sc[2], o1sc[3], o1sc[4], \
       o2sc[0], o2sc[1], o2sc[2], o2sc[3], o2sc[4], o3sc[0], o3sc[1], o3sc[2], o3sc[3], o3sc[4], \
       o4sc[1], o4sc[2], o4sc[3], o4sc[4], o4sc[4]]
       

  # point with orientation; [y, x, s, o]

  final_points = []
  ret_points = []
  

  # length of outer list
  o = 0
  for p in points:
    counter = 1
    max_size_y = len(I[int(p[2])]) - (window_size)
    max_size_x = len(I[int(p[2])][0]) - (window_size)
    min_size_y = window_size
    min_size_x = window_size
    if ((p[0] < max_size_y) and (min_size_y < p[0]) and \
        (p[1] < max_size_x and min_size_x < p[1])):
      if (p[2] > 5 and p[2] < 8):
        cv2.circle(I_show, (int(p[1] * 2), int(p[0] * 2)), 12, (0,255,0),2)
      if (p[2] > 10 and p[2] < 13):
        cv2.circle(I_show, (int(p[1] * 4), int(p[0] * 4)), 24, (255,0,0),2)
      if (p[2] > 15 and p[2] < 18):
        cv2.circle(I_show, (int(p[1] * 8), int(p[0] * 8)), 30, (125,125,0),2)

      final_points.append(p)
      o += 1
  cv2.imwrite("points.jpg", I_show)


  # size of all usable points o

  print("length of usable points, orientation", o)
  i = 0
  for p in final_points:
    bins = np.zeros([36])
    window_size = 16
    gauss_window = h.gauss(window_size, 1.5 * p[2])
    ip_window = h.create_window(I[int(p[2])], p, window_size + 2) 
    orien_of_bin = []

    # creates bin for each point
    hold_mag = np.empty((window_size, window_size))
    hold_ori = np.empty((window_size, window_size))
    for y in range(0, window_size):
      for x in range(0, window_size):
        magnitude_p = magnitude(ip_window, [y + 1, x + 1])
        orientation_p = orientation(ip_window, [y + 1, x + 1])
        orientation_p = math.floor(orientation_p/10.0)
        hold_mag[y, x] = magnitude_p
        hold_ori[y, x] = orientation_p

    hold_mag = np.multiply(hold_mag, gauss_window)
    hold_mag = np.reshape(hold_mag, -1)
    hold_ori = np.reshape(hold_ori, -1)

    for j in range(0, len(hold_ori)):
      bins[hold_ori[j]] += hold_mag[j]

      
    # index of max element in bin
    max_index = bins.argmax()
      
    max_val = bins[max_index]


    for j in range(0, 35):
      if (bins[j] >= max_val * 0.8):
        orien_of_bin.append(j)

    new_orien = list(orien_of_bin)

    cc = 0
    for i in new_orien:
      if (i == 1):
        A = 0
        B = bins[i] 
        C = bins[i + 1]
      if (i == 35):
        A = bins[i-1]
        B = bins[i]
        C = 0
      else:
        A = bins[i - 1]
        B = bins[i]
        C = bins[i + 1]
      a = A + (C-A)/2.0 - B
      b = (C-A)/2.0
      c = B
      if (b == 0 or a == 0):
        toppoint = 0
      else: 
        toppoint = -b / (2 * a)
      degree = (toppoint * 10) + i * 10
      #print(degree)

      if (degree < 0):
        degree = 360.0 + degree
      ret_points.append([p[0], p[1], p[2], degree])
      cc += 1

      if (cc == 1):
        break

    counter += 1
  
  ret_points = np.array(ret_points)
  return (ret_points)
Example #9
0
File: OR.py Project: chrisdawgr/BA
def sift_orientation(I, points, window_size):
  """
  Input : image I, interest points, size of window
  Output: assigns an orientation to the interest points
  """

  # point with orientation; [[y, x],[o1, o2, o3]]
  pwo = []
  max_point_size_y = len(I[0]) - (window_size + 2)
  min_point_size_y = window_size
  max_point_size_x = len(I[0][0]) - (window_size + 5)
  min_point_size_x = window_size 
  gauss_window = h.gauss(window_size, 1.5)
  hold_mag = h.create_window(I[0], [35,35], window_size)
  hold_ori = h.create_window(I[0], [35,35], window_size)
  final_points = []
  orien_of_bin = []
  

  # length of outer list
  o = 0
  for p in points:
    if ((p[0] < max_point_size_y and min_point_size_y < p[0]) and \
        (p[1] < max_point_size_x and min_point_size_x < p[1])):
      final_points.append(p)
      o += 1

  # size of all usable points o
  bins = numpy.zeros([o,  1, 36])
  #new 1
  bins1 = numpy.zeros([o,1,36])
  bins2 = numpy.zeros([o,1,36])
  bins3 = numpy.zeros([o,1,36])
  bins4 = numpy.zeros([o,1,36])
  bins5 = numpy.zeros([o,1,36])
  bins6 = numpy.zeros([o,1,36])
  bins7 = numpy.zeros([o,1,36])
  bins8 = numpy.zeros([o,1,36])
  bins9 = numpy.zeros([o,1,36])
  bins10 = numpy.zeros([o,1,36])
  bins11 = numpy.zeros([o,1,36])
  bins12 = numpy.zeros([o,1,36])
  bins13 = numpy.zeros([o,1,36])
  bins14 = numpy.zeros([o,1,36])
  bins15 = numpy.zeros([o,1,36])
  bins16 = numpy.zeros([o,1,36])
  #new 2

  i = 0
  for p in final_points:
    # if a point is too close to the border of the image, it is discarded
    if ((p[0] < max_point_size_y and p[0] > min_point_size_y) and \
        (p[1] < max_point_size_x and p[1] > min_point_size_x)):

      ip_window = h.create_window(I[p[2]], p, window_size + 2) 

      # creates bin for each point
      for y in range(0, window_size):
        for x in range(0, window_size):
          magnitude_p = magnitude(ip_window, [y + 1, x + 1])
          orientation_p = orientation(ip_window, [y + 1, x + 1])
          orientation_p = math.floor(orientation_p/10.0)
          hold_mag[y][x] = magnitude_p
          hold_ori[y][x] = orientation_p

      hold_mag = numpy.multiply(hold_mag, gauss_window)
      # new
      W1 = h.create_window(hold_mag, [2,2], 4)
      W2 = h.create_window(hold_mag, [2,6], 4)
      W3 = h.create_window(hold_mag, [2,10], 4)
      W4 = h.create_window(hold_mag, [2,14], 4)
      W5 = h.create_window(hold_mag, [6,2], 4)
      W6 = h.create_window(hold_mag, [6,6], 4)
      W7 = h.create_window(hold_mag, [6,10], 4)
      W8 = h.create_window(hold_mag, [6,14], 4)
      W9 = h.create_window(hold_mag, [10,2], 4)
      W10 = h.create_window(hold_mag, [10,6], 4)
      W11 = h.create_window(hold_mag, [10,10], 4)
      W12 = h.create_window(hold_mag, [10,14], 4)
      W13 = h.create_window(hold_mag, [14,2], 4)
      W14 = h.create_window(hold_mag, [14,6], 4)
      W15 = h.create_window(hold_mag, [14,10], 4)
      W16 = h.create_window(hold_mag, [14,14], 4)
      O1 = h.create_window(hold_ori, [2,2], 4)
      O2 = h.create_window(hold_ori, [2,6], 4)
      O3 = h.create_window(hold_ori, [2,10], 4)
      O4 = h.create_window(hold_ori, [2,14], 4)
      O5 = h.create_window(hold_ori, [6,2], 4)
      O6 = h.create_window(hold_ori, [6,6], 4)
      O7 = h.create_window(hold_ori, [6,10], 4)
      O8 = h.create_window(hold_ori, [6,14], 4)
      O9 = h.create_window(hold_ori, [10,2], 4)
      O10 = h.create_window(hold_ori, [10,6], 4)
      O11 = h.create_window(hold_ori, [10,10], 4)
      O12 = h.create_window(hold_ori, [10,14], 4)
      O13 = h.create_window(hold_ori, [14,2], 4)
      O14 = h.create_window(hold_ori, [14,6], 4)
      O15 = h.create_window(hold_ori, [14,10], 4)
      O16 = h.create_window(hold_ori, [14,14], 4)
      # new
      hold_mag = numpy.reshape(hold_mag, -1)
      hold_ori = numpy.reshape(hold_ori, -1)
      # new
      W1 = numpy.reshape(W1, -1)
      W2 = numpy.reshape(W2, -1)
      W3 = numpy.reshape(W3, -1)
      W4 = numpy.reshape(W4, -1)
      W5 = numpy.reshape(W5, -1)            
      W6 = numpy.reshape(W6, -1)
      W7 = numpy.reshape(W7, -1)
      W8 = numpy.reshape(W8, -1)
      W9 = numpy.reshape(W9, -1)
      W10 = numpy.reshape(W10, -1)
      W11 = numpy.reshape(W11, -1)
      W12 = numpy.reshape(W12, -1)
      W13 = numpy.reshape(W13, -1)
      W14 = numpy.reshape(W14, -1)
      W15 = numpy.reshape(W15, -1)
      W16 = numpy.reshape(W16, -1)
      O1 = numpy.reshape(O1, -1)
      O2 = numpy.reshape(O2, -1)
      O3 = numpy.reshape(O3, -1)
      O4 = numpy.reshape(O4, -1)
      O5 = numpy.reshape(O5, -1)            
      O6 = numpy.reshape(O6, -1)
      O7 = numpy.reshape(O7, -1)
      O8 = numpy.reshape(O8, -1)
      O9 = numpy.reshape(O9, -1)
      O10 = numpy.reshape(O10, -1)
      O11 = numpy.reshape(O11, -1)
      O12 = numpy.reshape(O12, -1)
      O13 = numpy.reshape(O13, -1)
      O14 = numpy.reshape(O14, -1)
      O15 = numpy.reshape(O15, -1)
      O16 = numpy.reshape(O16, -1)
      for j in range(0,len(O1)):
        bins1[i][0][O1[j]] += W1[j]
        bins2[i][0][O2[j]] += W2[j]
        bins3[i][0][O3[j]] += W3[j]
        bins4[i][0][O4[j]] += W4[j]
        bins5[i][0][O5[j]] += W5[j]
        bins6[i][0][O6[j]] += W6[j]
        bins7[i][0][O7[j]] += W7[j]
        bins8[i][0][O8[j]] += W8[j]
        bins9[i][0][O9[j]] += W9[j]
        bins10[i][0][O10[j]] += W10[j]
        bins11[i][0][O11[j]] += W11[j]
        bins12[i][0][O12[j]] += W12[j]
        bins13[i][0][O13[j]] += W13[j]
        bins14[i][0][O14[j]] += W14[j]
        bins15[i][0][O15[j]] += W15[j]
        bins16[i][0][O16[j]] += W16[j]
      # new
      
      for j in range(0, len(hold_ori)):
        bins[i][0][hold_ori[j]] += hold_mag[j]

      hold_mag = h.create_window(I[0], [35,35], window_size)
      hold_ori = h.create_window(I[0], [35,35], window_size)

      bin_i = bins[i][0]
      # new
      bin_i_1 = bins1[i][0]
      bin_i_2 = bins2[i][0]
      bin_i_3 = bins3[i][0]
      bin_i_4 = bins4[i][0]
      bin_i_5 = bins5[i][0]
      bin_i_6 = bins6[i][0]
      bin_i_7 = bins7[i][0]
      bin_i_8 = bins8[i][0]
      bin_i_9 = bins9[i][0]
      bin_i_10 = bins9[i][0]
      bin_i_11 = bins11[i][0]
      bin_i_12 = bins12[i][0]
      bin_i_13 = bins13[i][0]
      bin_i_14 = bins14[i][0]
      bin_i_15 = bins15[i][0]
      bin_i_16 = bins16[i][0]
      max_val1 = max(bin_i_1)
      max_index1 = [k for k, j in enumerate(bin_i_1) if j == max_val1]
      max_val2 = max(bin_i_2)
      max_index2 = [k for k, j in enumerate(bin_i_2) if j == max_val2]
      max_val3 = max(bin_i_3)
      max_index3 = [k for k, j in enumerate(bin_i_3) if j == max_val3]
      max_val4 = max(bin_i_4)
      max_index4 = [k for k, j in enumerate(bin_i_4) if j == max_val4]
      max_val5 = max(bin_i_5)
      max_index5 = [k for k, j in enumerate(bin_i_5) if j == max_val5]
      max_val6 = max(bin_i_6)
      max_index6 = [k for k, j in enumerate(bin_i_6) if j == max_val6]
      max_val7 = max(bin_i_7)
      max_index7 = [k for k, j in enumerate(bin_i_7) if j == max_val7]
      max_val8 = max(bin_i_8)
      max_index8 = [k for k, j in enumerate(bin_i_8) if j == max_val8]
      max_val9 = max(bin_i_9)
      max_index9 = [k for k, j in enumerate(bin_i_9) if j == max_val9]
      max_val10 = max(bin_i_10)
      max_index10 = [k for k, j in enumerate(bin_i_10) if j == max_val10]
      max_val11 = max(bin_i_11)
      max_index11 = [k for k, j in enumerate(bin_i_11) if j == max_val11]
      max_val12 = max(bin_i_12)
      max_index12 = [k for k, j in enumerate(bin_i_12) if j == max_val12]
      max_val13 = max(bin_i_13)
      max_index13 = [k for k, j in enumerate(bin_i_13) if j == max_val13]
      max_val14 = max(bin_i_14)
      max_index14 = [k for k, j in enumerate(bin_i_14) if j == max_val14]
      max_val15 = max(bin_i_15)
      max_index15 = [k for k, j in enumerate(bin_i_15) if j == max_val15]
      max_val16 = max(bin_i_16)
      max_index16 = [k for k, j in enumerate(bin_i_16) if j == max_val16]
      # new

        
      # index of max element in bin
      max_index = max(bin_i)
      max_index = [k for k, j in enumerate(bin_i) if j == max_index]
        
      # finds points within 80% of interest point

      holder_bin = []
      holder_bin.append(max_index5[0])
      max_val = bin_i[max_index5]

      for j in range(0, 35):
        if (bin_i[j] >= max_val * 0.8 and j != max_index5[0]):
          holder_bin.append(j)
      orien_of_bin.append(holder_bin)
    i += 1


  o = open('orientss.txt', 'w')
  for i in orien_of_bin:
    o.write(str(i) + "\n")
  o.close()