def test_show_selected_label(): """Test color of labels when filtering to selected labels""" np.random.seed(0) data = np.random.randint(20, size=(10, 15)) layer = Labels(data) original_color = layer.get_color(1) layer.show_selected_label = True original_background_color = layer.get_color(layer._background_label) none_color = layer.get_color(None) layer.selected_label = 1 # color of selected label has not changed assert np.allclose(layer.get_color(layer.selected_label), original_color) current_background_color = layer.get_color(layer._background_label) # color of background is background color assert current_background_color == original_background_color # color of all others is none color other_labels = np.unique(layer.data)[2:] other_colors = np.array( list(map(lambda x: layer.get_color(x), other_labels)) ) assert np.allclose(other_colors, none_color)
def test_add_large_colors(): label_array = (5e6 * np.ones((2, 2, 2))).astype(np.uint64) label_array[0, :, :] = [[0, 1], [2, 3]] layer = Labels(label_array) assert len(layer._all_vals) == layer.num_colors layer.show_selected_label = True layer.selected_label = int(5e6) assert layer._all_vals.size < 1026
def test_add_colors(): """Test adding new colors""" data = np.random.randint(20, size=(40, 40)) layer = Labels(data) assert len(layer._all_vals) == layer.num_colors layer.selected_label = 51 assert len(layer._all_vals) == 52 layer.show_selected_label = True layer.selected_label = 53 assert len(layer._all_vals) == 54