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-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 
007 * Visit http://imagingbook.com for additional details.
008 *******************************************************************************/
009
010package imagingbook.pub.threshold.global;
011
012import ij.process.ByteProcessor;
013import imagingbook.pub.threshold.Thresholder;
014
015public abstract class GlobalThresholder extends Thresholder {
016        
017        // must be implemented by concrete subclasses
018        protected abstract int getThreshold(int[] h);
019        
020        public int getThreshold(ByteProcessor bp) {
021                int[] h = bp.getHistogram();
022                return getThreshold(h);
023        }
024        
025        public boolean threshold(ByteProcessor ip) {
026                int q = getThreshold(ip);
027                if (q > 0) {
028                        ip.threshold(q);
029                        return true;
030                }
031                else {
032                        return false;
033                }
034        }
035        
036}