# Path: moonlight/vision/hough.py
# def hough_lines(image, thetas):
# def hough_peaks(hough_bins, thetas, minval=0, invalidate_distance=0):
# def _bincount_2d(values, num_values):


import numpy as np
import tensorflow as tf
from moonlight.vision import hough
    hough_bins = hough.hough_lines(image, thetas)
    peak_rho_t, peak_theta_t = hough.hough_peaks(hough_bins, thetas)
    with self.test_session() as sess:
      peak_rho, peak_theta = sess.run((peak_rho_t, peak_theta_t))
    # Vertical line
    self.assertEqual(peak_rho[0], 1)
    self.assertAlmostEqual(peak_theta[0], 0)
    # Rotated line
    self.assertEqual(peak_rho[1], 3)
    self.assertAlmostEqual(peak_theta[1], -np.pi / 8, places=1)

  def testHoughPeaks_minval(self):
    image = np.asarray(
        [[0, 0, 0, 0, 0],
         [0, 1, 1, 1, 0],
         [0, 0, 0, 0, 0]])  # pyformat: disable
    thetas = np.linspace(0, np.pi / 2, 17)
    hough_bins = hough.hough_lines(image, thetas)
    peak_rho_t, peak_theta_t = hough.hough_peaks(hough_bins, thetas, minval=2)
    with self.test_session() as sess:
      peak_rho, peak_theta = sess.run((peak_rho_t, peak_theta_t))
      self.assertEqual(peak_rho.shape, (1,))
      self.assertEqual(peak_theta.shape, (1,))

  def testHoughPeaks_minvalTooLarge(self):
    image = np.asarray(
        [[0, 0, 0, 0, 0],
         [0, 1, 1, 1, 0],
         [0, 0, 0, 0, 0]])  # pyformat: disable
    thetas = np.linspace(0, np.pi / 2, 17)

# Path: moonlight/vision/hough.py
# def hough_lines(image, thetas):
# def hough_peaks(hough_bins, thetas, minval=0, invalidate_distance=0):
# def _bincount_2d(values, num_values):


# Path: moonlight/vision/hough_test.py
import numpy as np
import tensorflow as tf
from moonlight.vision import hough

    hough_bins = hough.hough_lines(image, thetas)
    peak_rho_t, peak_theta_t = hough.hough_peaks(hough_bins, thetas)
    with self.test_session() as sess:
      peak_rho, peak_theta = sess.run((peak_rho_t, peak_theta_t))
    # Vertical line
    self.assertEqual(peak_rho[0], 1)
    self.assertAlmostEqual(peak_theta[0], 0)
    # Rotated line
    self.assertEqual(peak_rho[1], 3)
    self.assertAlmostEqual(peak_theta[1], -np.pi / 8, places=1)

  def testHoughPeaks_minval(self):
    image = np.asarray(
        [[0, 0, 0, 0, 0],
         [0, 1, 1, 1, 0],
         [0, 0, 0, 0, 0]])  # pyformat: disable
    thetas = np.linspace(0, np.pi / 2, 17)
    hough_bins = hough.hough_lines(image, thetas)
    peak_rho_t, peak_theta_t = hough.hough_peaks(hough_bins, thetas, minval=2)
    with self.test_session() as sess:
      peak_rho, peak_theta = sess.run((peak_rho_t, peak_theta_t))
      self.assertEqual(peak_rho.shape, (1,))
      self.assertEqual(peak_theta.shape, (1,))

  def testHoughPeaks_minvalTooLarge(self):
    image = np.asarray(
        [[0, 0, 0, 0, 0],
         [0, 1, 1, 1, 0],
         [0, 0, 0, 0, 0]])  # pyformat: disable
    thetas = np.linspace(0, np.pi / 2, 17)

    hough_bins = hough.hough_lines(image, thetas)