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 ImageAccessorDemos; 010 011import ij.ImagePlus; 012import ij.plugin.filter.PlugInFilter; 013import ij.process.ImageProcessor; 014import imagingbook.common.image.access.ImageAccessor; 015import imagingbook.common.image.access.ScalarAccessor; 016import imagingbook.core.jdoc.JavaDocHelp; 017 018/** 019 * This plugin demonstrates the of class {@link ScalarAccessor} for unified access to scalar-valued images. The plugin 020 * adds 20 brightness units to each pixel of the active image. It can be applied to any scalar image type. 021 * 022 * @author WB 023 * @see ImageAccessor 024 * @see ScalarAccessor 025 */ 026public class ImageAccessor_Demo_Scalar implements PlugInFilter, JavaDocHelp { 027 028 public int setup(String arg, ImagePlus img) { 029 return DOES_8G + DOES_16 + DOES_32; 030 } 031 032 public void run(ImageProcessor ip) { 033 final int width = ip.getWidth(); 034 final int height = ip.getHeight(); 035 036 ScalarAccessor ia = ScalarAccessor.create(ip, null, null); 037 038 for (int u = 0; u < width; u++) { 039 for (int v = 0; v < height; v++) { 040 float val = ia.getVal(u, v); // get a single value (float) 041 ia.setVal(u, v, val + 20); 042 } 043 } 044 } 045 046}