def test_get_data_by_id(self): """ Test whether the `get_data_by_id` function works well. """ im, pdf = gzapi.get_data_by_id(self.test_id, False) self.assertEqual(im.ndim, 3) im = gzapi.get_data_by_id(self.test_id, True)[0] self.assertEqual(im.ndim, 2) expected_pdf = gzapi.solutions.ix[self.test_id].values expected_im = plt.imread(os.path.join(gzapi.TRAINING_IMAGES_DIR, str(self.test_id)+'.jpg'))[:,:,0] self.assertTrue(np.allclose(expected_im, im)) self.assertTrue(np.allclose(expected_pdf, pdf))
def test_clear_borders(self): x = gzapi.get_data_by_id(self.test_id, as_grey=True)[0] bw = gzapi.get_cleared_binary_image(x) top = bw[0,:] bottom = bw[bw.shape[0]-1,:] left = bw[:,0] right = bw[:,bw.shape[1]-1] for col in (top, bottom, left, right): self.assertTrue(np.allclose(col, np.zeros(col.shape)))
def test_thresholding(self): """ test whether the thresholding works :return: """ x = gzapi.get_data_by_id(self.test_id, as_grey=True)[0] bw = gzapi.get_thresholded_image(x) unique_levels = np.unique(bw) self.assertEqual(len(unique_levels), 2)