MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / RankFilters

Class RankFilters

ij/src/main/java/ij/plugin/filter/RankFilters.java:24–953  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 // Uses AtomicIntegers. Top-hat filter added
23
24public class RankFilters implements ExtendedPlugInFilter, DialogListener {
25 public static final int MEAN=0, MIN=1, MAX=2, VARIANCE=3, MEDIAN=4, OUTLIERS=5, DESPECKLE=6, REMOVE_NAN=7,
26 OPEN=8, CLOSE=9, TOP_HAT=10; //when adding a new filter, set HIGHEST_FILTER below.
27 public static final int BRIGHT_OUTLIERS = 0, DARK_OUTLIERS = 1;
28 private static final String[] outlierStrings = {"Bright","Dark"};
29 private static int HIGHEST_FILTER = TOP_HAT;
30 // Filter parameters
31 private int filterType;
32 private double radius;
33 private double threshold; //this and the next for 'remove outliers' only
34 private int whichOutliers;
35 private boolean lightBackground = Prefs.get("bs.background", true); //this and the next for top hat only
36 private boolean dontSubtract;
37 // Remember filter parameters for the next time
38 private static double[] lastRadius = new double[HIGHEST_FILTER+1]; //separate for each filter type
39 private static double lastThreshold = 50.;
40 private static int lastWhichOutliers = BRIGHT_OUTLIERS;
41 private static boolean lastLightBackground = false;
42 private static boolean lastDontSubtract = false;
43 //
44 // F u r t h e r c l a s s v a r i a b l e s
45 int flags = DOES_ALL|SUPPORTS_MASKING|KEEP_PREVIEW;
46 private ImagePlus imp;
47 private int nPasses = 1; // The number of passes (color channels * stack slices)
48 private PlugInFilterRunner pfr;
49 private int pass;
50 private boolean previewing = false;
51 // M u l t i t h r e a d i n g - r e l a t e d
52 private int numThreads = Prefs.getThreads();
53 // The current state of multithreaded processing is in class variables.
54 // Thus, stack parallelization must be done ONLY with one thread for the image
55 // (not using these class variables).
56 // Atomic objects are used to avoid caching (i.e., to ensure that always the current state of the variable is read).
57 private AtomicInteger highestYinCache = new AtomicInteger(Integer.MIN_VALUE); // the highest line read into the cache so far
58 private AtomicInteger nThreadsWaiting = new AtomicInteger(0); // number of threads waiting until they may read data
59 private AtomicBoolean copyingToCache = new AtomicBoolean(false); // whether a thread is currently copying data to the cache
60
61 /** OPEN, CLOSE, TOPHAT need more than one run of the underlying filter */
62 private boolean isMultiStepFilter(int filterType) {
63 return filterType>=OPEN && filterType<=TOP_HAT;
64 }
65
66 /** Setup of the PlugInFilter. Returns the flags specifying the capabilities and needs
67 * of the filter.
68 *
69 * @param arg Defines type of filter operation
70 * @param imp The ImagePlus to be processed
71 * @return Flags specifying further action of the PlugInFilterRunner
72 */
73 public int setup(String arg, ImagePlus imp) {
74 this.imp = imp;
75 if (arg.equals("mean"))
76 filterType = MEAN;
77 else if (arg.equals("min"))
78 filterType = MIN;
79 else if (arg.equals("max"))
80 filterType = MAX;
81 else if (arg.equals("variance")) {

Callers

nothing calls this directly

Calls 2

getMethod · 0.95
getThreadsMethod · 0.95

Tested by

no test coverage detected