|
12 | 12 |
|
13 | 13 | from nose.tools import assert_true
|
14 | 14 | import numpy as np
|
15 |
| -from numpy.testing import assert_equal, assert_raises, dec, assert_allclose |
| 15 | +from numpy.testing import assert_equal, assert_raises, dec, assert_allclose, assert_array_equal |
16 | 16 |
|
17 | 17 | from .. import (read_geometry, read_morph_data, read_annot, read_label,
|
18 | 18 | write_geometry, write_morph_data, write_annot)
|
@@ -356,3 +356,22 @@ def test_label():
|
356 | 356 | labels, scalars = read_label(label_path, True)
|
357 | 357 | assert_true(np.all(labels == label))
|
358 | 358 | assert_true(len(labels) == len(scalars))
|
| 359 | + |
| 360 | + |
| 361 | +def test_write_annot_maxstruct(): |
| 362 | + """Test writing ANNOT files with repeated labels""" |
| 363 | + with InTemporaryDirectory(): |
| 364 | + nlabels = 3 |
| 365 | + names = ['label {}'.format(l) for l in range(1, nlabels + 1)] |
| 366 | + # max label < n_labels |
| 367 | + labels = np.array([1, 1, 1], dtype=np.int32) |
| 368 | + rgba = np.array(np.random.randint(0, 255, (nlabels, 4)), dtype=np.int32) |
| 369 | + annot_path = 'c.annot' |
| 370 | + |
| 371 | + write_annot(annot_path, labels, rgba, names) |
| 372 | + # Validate the file can be read |
| 373 | + rt_labels, rt_ctab, rt_names = read_annot(annot_path) |
| 374 | + # Check round-trip |
| 375 | + assert_array_equal(labels, rt_labels) |
| 376 | + assert_array_equal(rgba, rt_ctab[:, :4]) |
| 377 | + assert_equal(names, [n.decode('ascii') for n in rt_names]) |
0 commit comments