def test_gradient_profile(self): img = os.path.join(os.path.dirname(__file__), "data", "eglise_zoom2.jpg") rootrem = os.path.normpath(os.path.abspath( os.path.join(os.path.dirname(rootfile), '..'))) _, res = self.profile(lambda: _calcule_gradient( img, color=0), rootrem=rootrem) short = "\n".join(res.split('\n')[:15]) self.assertIn("_calcule_gradient", short)
def test_gradient(self): temp = get_temp_folder(__file__, "temp_segment_gradient") img = os.path.join(temp, "..", "data", "eglise_zoom2.jpg") grad = _calcule_gradient(img, color=0) self.assertEqual(grad.shape, (308, 408, 2)) for d in [-2, -1, 0, 1, 2]: imgrad = plot_gradient(img, grad, direction=d) grfile = os.path.join(temp, "gradient-%d.png" % d) imgrad.save(grfile) self.assertExists(grfile) with open(os.path.join(temp, "..", "data", "gradient--2.png"), 'rb') as f: c1 = f.read() with open(os.path.join(temp, "..", "data", "gradient--2b.png"), 'rb') as f: c1b = f.read() with open(os.path.join(temp, "gradient--2.png"), 'rb') as f: c2 = f.read() self.assertIn(c2, (c1, c1b))