Skip to content

Commit

Permalink
Workaround issue with minNumInliers occasionally being ignored by RAN…
Browse files Browse the repository at this point in the history
…SAC filter - included new test so that Stephan can take a look at the root cause of the problem.
  • Loading branch information
trautmane committed Nov 13, 2017
1 parent b6654be commit af38b9f
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ public List<PointMatch> filterMatches(final List<PointMatch> candidates,
LOG.warn("failed to filter outliers", e);
}

// TODO: remove this extra check once RANSAC filter issue is fixed
if ((inliers.size() > 0) && (inliers.size() < minNumInliers)) {
LOG.warn("removing {} inliers that mysteriously did not get removed with minNumInliers value of {}",
inliers.size(), minNumInliers);
inliers.clear();
}

if ((maxNumInliers != null) && (maxNumInliers > 0) && (inliers.size() > maxNumInliers)) {
LOG.info("filterMatches: randomly selecting {} of {} inliers", maxNumInliers, inliers.size());
// randomly select maxNumInliers elements by shuffling and then remove excess elements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* License: GPL
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.janelia.alignment.match;

import java.util.ArrayList;
import java.util.List;

import mpicbg.models.AffineModel2D;
import mpicbg.models.NotEnoughDataPointsException;
import mpicbg.models.PointMatch;

import org.junit.Assert;
import org.junit.Test;

public class CanvasFeatureMatcherTest {

@Test
public void testRANSACFilter() throws Exception {

final CanvasMatches canvasMatches = CanvasMatches.fromJson(SCALED_MATCH_JSON);

final List<PointMatch> candidates =
CanvasFeatureMatchResult.convertMatchesToPointMatchList(canvasMatches.getMatches());

testRANSACFilterWithMinValue(candidates, 6, 6);
testRANSACFilterWithMinValue(candidates, 10, 0);

// TODO: uncomment this test to see bug
// testRANSACFilterWithMinValue(candidates, 8, 0);
}

private void testRANSACFilterWithMinValue(final List<PointMatch> candidates,
final int minNumInliers,
final int expectedInliersSizeAfterFilter)
throws NotEnoughDataPointsException {

final List<PointMatch> inliers = new ArrayList<>();

final int iterations = 1000;
final float maxEpsilon = 20f;
final float minInlierRatio = 0.0f;
final float maxTrust = 3.0f;

final AffineModel2D model = new AffineModel2D();

model.filterRansac(candidates,
inliers,
iterations,
maxEpsilon,
minInlierRatio,
minNumInliers,
maxTrust);

Assert.assertEquals("invalid number of inliers found with min " + minNumInliers,
expectedInliersSizeAfterFilter, inliers.size());
}

private static final String SCALED_MATCH_JSON =
"{\n" +
" \"pGroupId\" : \"1022.0\",\n" +
" \"pId\" : \"20170502214026065_295434_5LC_0064_01_001022_0_64_95.1022.0\",\n" +
" \"qGroupId\" : \"1024.0\",\n" +
" \"qId\" : \"20170502231609141_295434_5LC_0064_01_001024_0_62_96.1024.0\",\n" +
" \"matches\" : {\n" +
" \"p\" : [\n" +
" [\n" +
" 971.5635096815266, 406.18530507329615, 788.7555030553078, 505.43042821601364, 698.9889106528376, 411.66370767928254, 1107.6351942280949, 784.7469606154469,\n" +
" 207.07901738866306, 485.11885402400856, 24.38534641247882, 800.6852276637328, 1143.1431169071232, 462.52438822195876, 34.61821287541544, 34.61821287541544,\n" +
" 655.2903387362293, 100.23622892419567, 624.2693631054228, 203.36708129045283, 7.143312107020934, 905.5911143048423, 238.2201045421518, 843.3824117300322,\n" +
" 299.0329284307101, 722.8706621786835, 802.8156561366477, 1037.9640253715907, 104.39790111353395, 165.87546233020402, 46.513882628895395, 14.894525616448714,\n" +
" 470.38591300335736, 986.4635110854169, 359.7907580283982, 1136.7867675429775, 914.8457024927822, 1082.6370171906835, 373.4746633463183, 811.5017686036161,\n" +
" 1063.7228346355653, 548.1727040577681, 1136.5782293708694, 1082.5504917550097, 1040.6922712447686, 127.73818452754995, 906.1842672116476, 203.36418867732775,\n" +
" 726.3774540616758, 360.97022277819855, 361.24482483611615\n" +
" ],\n" +
" [\n" +
" 1135.5403303257467, 1132.4212455346005, 1123.4405237051137, 1122.525178193339, 1117.4839236575208, 1106.080317069112, 1093.2899072471428, 1085.0958085400878,\n" +
" 711.5935549144543, 665.0063568768769, 545.4168634028753, 53.284700274105, 8.73445197098604, 1155.8195123186003, 1140.879193534938, 1140.879193534938,\n" +
" 1136.7754229354107, 1101.2183095284556, 1001.3111610383688, 477.2114010015788, 398.34751782904596, 14.630158261944215, 1147.073190810212, 1139.4601397768386,\n" +
" 1122.8951520374962, 1111.4347560454864, 1103.449845587202, 1080.1779421853364, 903.1236469358091, 757.4488262634661, 738.1698639778386, 689.2662942563832,\n" +
" 650.214478040045, 474.3498882215986, 366.322779846882, 208.75955009047755, 209.34279126762877, 93.43062667794383, 38.981050362783165, 28.741645558840858,\n" +
" 13.589454807170334, 173.7071505744456, 1136.1757042551187, 1121.6511048766006, 1122.0177751082779, 656.8979847788298, 1152.307691502368, 1132.6669422546126,\n" +
" 494.8860678452787, 288.3572170485793, 47.809681998368035\n" +
" ]\n" +
" ],\n" +
" \"q\" : [\n" +
" [\n" +
" 492.91075159963106, 534.1398676237902, 587.2530363881108, 258.6176551907437, 772.7348508149224, 863.610081284062, 907.4887332611133, 372.1697392833021,\n" +
" 783.7025459844309, 1065.5459518277305, 766.170175983817, 39.933701523330775, 1142.4007706832247, 478.41263930716224, 99.14734361636002, 58.13174658039076,\n" +
" 1001.2729338347921, 179.76604444212416, 907.5701827999726, 784.3291649978775, 214.39322310795674, 26.212674540265674, 1051.0943820596112, 726.0380003969502,\n" +
" 1121.8232554388085, 1130.8998178473546, 439.8091220829684, 727.918542388592, 486.2801329782762, 741.5663957012663, 865.5789577051905, 15.988030392843879,\n" +
" 513.957473123443, 1040.5853084277744, 934.5968503390732, 774.8039450746868, 410.021160702928, 891.5263573284391, 943.7588493846305, 36.65285615113653,\n" +
" 46.58708652287428, 1110.790333635018, 598.962345277499, 959.1729453643538, 780.2850707568189, 702.8950227072174, 516.9146035937649, 170.38676506103792,\n" +
" 840.961810328694, 935.5510798088196, 385.68481540271284\n" +
" ],\n" +
" [\n" +
" 1141.410853329002, 1125.0350710836835, 1130.3056797409834, 1133.3628661888188, 1121.8315106730329, 1112.346646113387, 1112.3750170476687, 1009.6612136765405,\n" +
" 991.2833290121271, 943.6560133678336, 19.473797339168552, 340.9470427572029, 6.838789415725136, 1154.908558867874, 1143.9867531271009, 1104.3371698913913,\n" +
" 1116.2107233687457, 1011.2217799005674, 31.083980221682477, 751.1876522029828, 1141.5197633183702, 256.37051380310953, 1128.6676190482665, 1139.626656337162,\n" +
" 60.75265745796865, 1051.8017564375896, 1070.238263218028, 245.74408246148357, 40.90515362953398, 1035.7449380568376, 412.2935109951934, 680.7063906539936,\n" +
" 685.5362793831916, 1080.1479710252597, 639.6933914190129, 1096.3634967368835, 491.31526168255306, 327.25810330658123, 320.4650088952018, 191.43683588797296,\n" +
" 1138.5877662842022, 517.8356833659197, 1142.359389416605, 1122.7216431952395, 1133.9217682713556, 937.2135308652838, 1154.0982051178187, 1134.2889064179035,\n" +
" 435.5531647101994, 568.3548546366479, 551.7561836471724\n" +
" ]\n" +
" ],\n" +
" \"w\" : [\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,\n" +
" 1.0, 1.0, 1.0\n" +
" ]\n" +
" }\n" +
"}";

}

0 comments on commit af38b9f

Please sign in to comment.