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.IJ; 012import ij.ImagePlus; 013import ij.plugin.filter.PlugInFilter; 014import ij.process.ImageProcessor; 015import imagingbook.common.image.access.ImageAccessor; 016import imagingbook.common.image.access.ScalarAccessor; 017import imagingbook.common.image.access.VectorAccessor; 018import imagingbook.core.jdoc.JavaDocHelp; 019 020/** 021 * This plugin demonstrates the of class {@link ImageAccessor} for unified access to scalar and vector-valued images. 022 * The plugin adds 20 brightness units to each component (color plane) of the active image. It can be applied to any 023 * image type. Image pixels are treated as vectors, even if only a single component is present. 024 * TODO: move to other package 025 * 026 * @author WB 027 * @see ImageAccessor 028 * @see ScalarAccessor 029 * @see VectorAccessor 030 */ 031public class ImageAccessor_Demo_Vector implements PlugInFilter, JavaDocHelp { 032 033 public int setup(String arg, ImagePlus img) { 034 return DOES_ALL; 035 } 036 037 public void run(ImageProcessor ip) { 038 final int width = ip.getWidth(); 039 final int height = ip.getHeight(); 040 041 ImageAccessor ia = ImageAccessor.create(ip, null, null); 042 IJ.log(ia.toString()); 043 044 for (int u = 0; u < width; u++) { 045 for (int v = 0; v < height; v++) { 046 float[] vals = ia.getPix(u, v); // get a single pixel (vector) 047 for (int i = 0; i < vals.length; i++) { 048 vals[i] += 20; 049 } 050 ia.setPix(u, v, vals); 051 } 052 } 053 } 054 055}