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 ImageJ_Demos;
010
011import ij.ImagePlus;
012import ij.ImageStack;
013import ij.plugin.filter.PlugInFilter;
014import ij.process.ImageProcessor;
015import imagingbook.core.jdoc.JavaDocHelp;
016
017/**
018 * <p>
019 * This ImageJ plugin demonstrates how to iterate over the frames (slices) of an image stack. In this case each frame is
020 * simply inverted. No new frames are added to the stack. Note that stack slices are numbered from 1,...,K (i.e., there
021 * is no slice 0)!
022 * </p>
023 * <p>
024 * If {@link PlugInFilter#STACK_REQUIRED} is omitted in {@link #setup(String, ImagePlus)}, the plugin will also work on
025 * ordinary (single) images.
026 * </p>
027 *
028 * @author WB
029 */
030public class Stack_Processing_Demo implements PlugInFilter, JavaDocHelp {
031        
032        ImagePlus im = null;    // keep a reference to the associated ImagePlus object
033        
034        public int setup(String args, ImagePlus im) {
035                this.im = im;
036                return DOES_ALL + STACK_REQUIRED;
037        }
038
039        public void run(ImageProcessor ignored) {
040                ImageStack stack = im.getImageStack();
041                int K = stack.getSize();
042                for (int k = 1; k <= K; k++) {  // NOTE: slices are numbered from 1,...,K !!
043                        ImageProcessor ip = stack.getProcessor(k);
044                        ip.invert();
045                }
046        }
047}