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 ******************************************************************************/ 009 010package imagingbook.common.corners; 011 012import ij.process.ImageProcessor; 013 014import static imagingbook.common.math.Arithmetic.sqr; 015import static java.lang.Math.sqrt; 016 017 018/** 019 * <p> 020 * This is an implementation of the Shi-Tomasi corner detector, as described in [1]. This class extends 021 * {@link GradientCornerDetector} (where most of the work is done) by defining a specific corner score function and 022 * associated threshold. See Sec. 6.3.1 of [2] for additional details. 023 * </p> 024 * <p> 025 * [1] J. Shi and C. Tomasi. Good features to track. In Proceedings of IEEE Conference on Computer Vision and Pattern 026 * Recognition, CVPR’94, pp. 593–600, Seattle, WA, USA (1994). 027 * <br> 028 * [2] W. Burger, M.J. Burge, <em>Digital Image Processing – An Algorithmic Introduction</em>, 3rd ed, Springer 029 * (2022). 030 * </p> 031 * 032 * @author WB 033 * @version 2022/03/30 034 */ 035public class ShiTomasiCornerDetector extends GradientCornerDetector { 036 037 public ShiTomasiCornerDetector(ImageProcessor ip, GradientCornerDetector.Parameters params) { 038 super(ip, params); 039 } 040 041 // -------------------------------------------------------------- 042 043 @Override 044 protected float getCornerScore(float A, float B, float C) { 045 double rootExpr = sqr((A - B) / 2) + sqr(C); 046 if (rootExpr < 0) { 047 return UndefinedScoreValue; 048 } 049 double lambda2 = (A + B) / 2 - sqrt(rootExpr); 050 return (float) lambda2; 051 } 052 053}