def test_show_image_mixed_figure_layer_np(self): bg_img = np.ones((150, 150, 3), dtype=np.uint8) * 255 boxes = np.array([[0, 0, 10, 20], [10, 20, 30, 50], [40, 70, 200, 200]]) fig, axis = plt.subplots(1, 1, figsize=(6.4, 4.8)) fe.util.show_image(bg_img, fig=fig, axis=axis) fe.util.show_image(boxes, fig=fig, axis=axis) fe.util.show_image("apple", fig=fig, axis=axis) obj1 = fig_to_rgb_array(fig) obj2 = self.mixed_img_ans self.assertTrue(check_img_similar(obj1, obj2))
def test_show_image_color_tf(self): img = np.zeros((90, 90, 3), dtype=np.uint8) img[:, 0:30, :] = np.array([255, 0, 0]) img[:, 30:60, :] = np.array([0, 255, 0]) img[:, 60:90, :] = np.array([0, 0, 255]) img = tf.convert_to_tensor(img) fig, axis = plt.subplots(1, 1, figsize=(6.4, 4.8)) fe.util.show_image(img, fig=fig, axis=axis) obj1 = fig_to_rgb_array(fig) obj2 = self.color_img_ans self.assertTrue(check_img_similar(obj1, obj2))
def test_show_image_color_torch(self): img = np.zeros((90, 90, 3), dtype=np.uint8) img[:, 0:30, :] = np.array([255, 0, 0]) img[:, 30:60, :] = np.array([0, 255, 0]) img[:, 60:90, :] = np.array([0, 0, 255]) img = torch.from_numpy(img.transpose((2, 0, 1))) fig, axis = plt.subplots(1, 1) fe.util.show_image(img, fig=fig, axis=axis) obj1 = fig_to_rgb_array(fig) obj2 = self.color_img_ans self.assertTrue(check_img_similar(obj1, obj2))
def test_show_image_bounding_box_np(self): bg_img = np.zeros((150, 150)) boxes = np.array([[0, 0, 10, 20, "apple"], [10, 20, 30, 50, "dog"], [40, 70, 200, 200, "cat"], [0, 0, 0, 0, "shouldn't shown"], [0, 0, -50, -30, "shouldn't shown2"]]) fig, axis = plt.subplots(1, 1, figsize=(6.4, 4.8)) fe.util.show_image(bg_img, fig=fig, axis=axis) fe.util.show_image(boxes, fig=fig, axis=axis) obj1 = fig_to_rgb_array(fig) obj2 = self.bb_img_ans self.assertTrue(check_img_similar(obj1, obj2))
def test_show_image_color_np(self): img = np.zeros((90, 90, 3), dtype=np.uint8) img[:, 0:30, :] = np.array([255, 0, 0]) img[:, 30:60, :] = np.array([0, 255, 0]) img[:, 60:90, :] = np.array([0, 0, 255]) fig, axis = plt.subplots(1, 1) fe.util.show_image(img, fig=fig, axis=axis) # Now we can save it to a numpy array. obj1 = fig_to_rgb_array(fig) obj2 = self.color_img_ans self.assertTrue(check_img_similar(obj1, obj2))
def test_paint_figure(self): fig = self.img_data.paint_figure() output = img_to_rgb_array(self.output_img) output_test = fig_to_rgb_array(fig) self.assertTrue(check_img_similar(output, output_test))