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.IJ; 012import ij.ImagePlus; 013import ij.plugin.filter.PlugInFilter; 014import ij.process.ImageProcessor; 015import imagingbook.core.jdoc.JavaDocHelp; 016 017/** 018 * This ImageJ plugin shows how data can be communicated from one plugin to another. In this example, ANOTHER plugin 019 * ({@link Data_Transfer_Plugin_Producer}) calculates a histogram that is subsequently retrieved by THIS plugin 020 * {@link Data_Transfer_Plugin_Consumer}. Data are stored as a property of the associated image (of type 021 * {@link ImagePlus}). Note that the stored data should contain no instances of self-defined classes, since these may be 022 * re-loaded when performing compile-and-run. 023 * 024 * @author WB 025 */ 026public class Data_Transfer_Plugin_Consumer implements PlugInFilter, JavaDocHelp { 027 ImagePlus im; 028 029 public int setup(String arg, ImagePlus im) { 030 this.im = im; 031 return DOES_ALL;} 032 033 public void run(ImageProcessor ip) { 034 String key = Data_Transfer_Plugin_Producer.HistKey; // property key from the producer plugin class 035 Object prop = im.getProperty(key); 036 if (prop == null) { 037 IJ.error("found no histogram for image " + im.getTitle()); 038 } 039 else { 040 int[] hist = (int[]) prop; 041 IJ.log("found histogram of length " + hist.length); 042 // process the histogram ... 043 } 044 045 // delete the stored data if not needed any longer: 046 // im.setProperty(key, null); 047 048 } 049}