|
34 | 34 |
|
35 | 35 | package net.imglib2.algorithm.morphology.distance;
|
36 | 36 |
|
| 37 | +import static org.junit.Assert.assertArrayEquals; |
37 | 38 | import static org.junit.Assert.assertTrue;
|
38 | 39 | import static org.junit.Assert.fail;
|
39 | 40 |
|
@@ -501,6 +502,68 @@ public void testLabelPropagation()
|
501 | 502 |
|
502 | 503 | }
|
503 | 504 |
|
| 505 | + @Test |
| 506 | + public void testWeights() |
| 507 | + { |
| 508 | + final double tolerance = 1e-9; |
| 509 | + final double M = Double.MAX_VALUE; |
| 510 | + |
| 511 | + double[] data = new double[] { |
| 512 | + 0, M, M, M, |
| 513 | + M, 0, M, M |
| 514 | + }; |
| 515 | + ArrayImg<DoubleType, DoubleArray> dists = ArrayImgs.doubles(data, 4, 2); |
| 516 | + DistanceTransform.transform(dists, new EuclidianDistanceAnisotropic(0.1, 1.0)); |
| 517 | + |
| 518 | + final double[] expected = new double[] {0.0, 0.1, 0.4, 0.9, 0.1, 0.0, 0.1, 0.4 }; |
| 519 | + assertArrayEquals( expected, dists.getAccessType().getCurrentStorageArray(), tolerance ); |
| 520 | + } |
| 521 | + |
| 522 | + @Test |
| 523 | + public void testWeightsL1() |
| 524 | + { |
| 525 | + final double tolerance = 1e-9; |
| 526 | + final double M = Double.MAX_VALUE; |
| 527 | + |
| 528 | + double[] data = new double[] { |
| 529 | + 0, M, M, M, |
| 530 | + M, 0, M, M |
| 531 | + }; |
| 532 | + ArrayImg<DoubleType, DoubleArray> dists = ArrayImgs.doubles(data, 4, 2); |
| 533 | + DistanceTransform.transform(dists, DISTANCE_TYPE.L1, 0.1, 1.0 ); |
| 534 | + |
| 535 | + final double[] expected = new double[] {0.0, 0.1, 0.2, 0.3, 0.1, 0.0, 0.1, 0.2 }; |
| 536 | + assertArrayEquals( expected, dists.getAccessType().getCurrentStorageArray(), tolerance ); |
| 537 | + } |
| 538 | + |
| 539 | + @Test |
| 540 | + public void testLabelPropagationWeights() |
| 541 | + { |
| 542 | + final long[] labelData = new long[]{ |
| 543 | + 1, 0, 0, 0, |
| 544 | + 0, 2, 0, 0 }; |
| 545 | + |
| 546 | + final long[] expectedYClose = new long[] { |
| 547 | + 1, 2, 2, 2, |
| 548 | + 1, 2, 2, 2}; |
| 549 | + |
| 550 | + final long[] expectedXClose = new long[] { |
| 551 | + 1, 1, 1, 1, |
| 552 | + 2, 2, 2, 2}; |
| 553 | + |
| 554 | + double rx = 99.0; |
| 555 | + double ry = 0.01; |
| 556 | + ArrayImg<LongType, LongArray> labels = ArrayImgs.longs(Arrays.copyOf(labelData, 8), 4, 2); |
| 557 | + DistanceTransform.voronoiDistanceTransform(labels, 0, rx, ry); |
| 558 | + assertArrayEquals( expectedYClose,labels.getAccessType().getCurrentStorageArray()); |
| 559 | + |
| 560 | + rx = 0.01; |
| 561 | + ry = 99.0; |
| 562 | + ArrayImg<LongType, LongArray> labels2 = ArrayImgs.longs(Arrays.copyOf(labelData, 8), 4, 2); |
| 563 | + DistanceTransform.voronoiDistanceTransform(labels2, 0, rx, ry); |
| 564 | + assertArrayEquals( expectedXClose, labels2.getAccessType().getCurrentStorageArray()); |
| 565 | + } |
| 566 | + |
504 | 567 | /**
|
505 | 568 | * Creates an label and distances images with the requested number of dimensions (ndims),
|
506 | 569 | * and places nLabels points with non-zero label. Checks that the propagated labels correctly
|
|
0 commit comments