001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2023 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009package imagingbook.common.ransac; 010 011import imagingbook.common.geometry.basic.Pnt2d; 012import imagingbook.common.geometry.basic.Primitive2d; 013 014/** 015 * <p> 016 * Represents a single detection result returned by an implementation of {@link RansacDetector}. Implements the 017 * {@link Comparable} interface for sorting by detection score. See Sec. 12.1 of [1] for additional details. 018 * </p> 019 * <p> 020 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing – An Algorithmic Introduction</em>, 3rd ed, Springer 021 * (2022). 022 * </p> 023 * 024 * @param <T> generic primitive type 025 * @author WB 026 * @version 2022/11/19 027 */ 028public class RansacResult<T extends Primitive2d> implements Comparable<RansacResult<T>> { 029 030 private final T primitiveInit; 031 private final T primitiveFinal; 032 private final double score; 033 private final Pnt2d[] draw; 034 private final Pnt2d[] inliers; 035 036 // full constructor (initially inliers = null) 037 public RansacResult(Pnt2d[] draw, T primitiveInit, T primitiveFinal, double score, Pnt2d[] inliers) { 038 this.primitiveInit = primitiveInit; 039 this.primitiveFinal = primitiveFinal; 040 this.score = score; 041 this.draw = draw; 042 this.inliers = inliers; 043 } 044 045 /** 046 * Returns the initial primitive (e.g., a circle) obtained from the minimum number of randomly drawn points. 047 * 048 * @return the initial primitive 049 */ 050 public T getPrimitiveInit() { 051 return primitiveInit; 052 } 053 054 /** 055 * Returns the final primitive obtained after fitting numerically to the associated inlier points. 056 * @return the final primitive 057 */ 058 public T getPrimitiveFinal() { 059 return primitiveFinal; 060 } 061 062 /** 063 * Returns the score (number of inliers) associated with this result. 064 * @return the score 065 */ 066 public double getScore() { 067 return score; 068 } 069 070 /** 071 * Returns the randomly drawn points that lead to this result. 072 * @return array of points 073 */ 074 public Pnt2d[] getDraw() { 075 return draw; 076 } 077 078 /** 079 * Returns the set of inliers (points) associated with this result. 080 * @return array of points 081 */ 082 public Pnt2d[] getInliers() { 083 return inliers; 084 } 085 086 // --------------------------------------------------------------------------- 087 088 @Override 089 public int compareTo(RansacResult<T> other) { 090 return Double.compare(other.score, this.score); 091 } 092 093}