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 *******************************************************************************/ 009package imagingbook.lib.image; 010 011import ij.process.Blitter; 012import ij.process.ImageProcessor; 013 014 015/** 016 * This class provides some static utility methods for ImageJ's ImageProcessors. 017 * 2013-08-23: static methods converted to use generics. 018 */ 019public abstract class ImageMath { 020 021// public static FloatProcessor sqr(FloatProcessor fp) { 022// fp.sqr(); 023// return fp; 024// } 025 026 public static <T extends ImageProcessor> T abs(T ip) { 027 @SuppressWarnings("unchecked") 028 T ip2 = (T) ip.duplicate(); 029 ip2.abs(); 030 return ip2; 031 } 032 033 public static <T extends ImageProcessor> T sqr(T ip) { 034 @SuppressWarnings("unchecked") 035 T ip2 = (T) ip.duplicate(); 036 ip2.sqr(); 037 return ip2; 038 } 039 040 public static <T extends ImageProcessor> T sqrt(T ip) { 041 @SuppressWarnings("unchecked") 042 T ip2 = (T) ip.duplicate(); 043 ip2.sqrt(); 044 return ip2; 045 } 046 047 public static<T extends ImageProcessor> T add(T ip1, T ip2) { 048 @SuppressWarnings("unchecked") 049 T ip3 = (T) ip1.duplicate(); 050 ip3.copyBits(ip2, 0, 0, Blitter.ADD); 051 return ip3; 052 } 053 054 public static<T extends ImageProcessor> T mult(T ip1, T ip2) { 055 @SuppressWarnings("unchecked") 056 T ip3 = (T) ip1.duplicate(); 057 ip3.copyBits(ip2, 0, 0, Blitter.MULTIPLY); 058 return ip3; 059 } 060 061// @Deprecated 062// public static FloatProcessor multOld (FloatProcessor fp1, FloatProcessor fp2) { 063// fp1.copyBits(fp2, 0, 0, Blitter.MULTIPLY); 064// return fp1; 065// } 066 067}