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 Ch21_Geometric_Operations; 010 011import ij.ImagePlus; 012import ij.plugin.filter.PlugInFilter; 013import ij.process.ImageProcessor; 014import imagingbook.common.geometry.mappings.Mapping2D; 015import imagingbook.common.geometry.mappings.linear.Rotation2D; 016import imagingbook.common.ij.DialogUtils; 017import imagingbook.common.ij.IjUtils; 018import imagingbook.common.image.ImageMapper; 019import imagingbook.core.jdoc.JavaDocHelp; 020import imagingbook.sampleimages.GeneralSampleImage; 021 022/** 023 * <p> 024 * ImageJ plugin, rotates the current image by a specified angle around the coordinate origin. See Sec. 21.1.1 of [1] 025 * for details. Optionally opens a sample image if no image is currently open. 026 * </p> 027 * <p> 028 * [1] W. Burger, M.J. Burge, <em>Digital Image Processing – An Algorithmic Introduction</em>, 3rd ed, Springer 029 * (2022). 030 * </p> 031 * 032 * @author WB 033 * @version 2022/11/28 034 * @see ImageMapper 035 * @see Rotation2D 036 */ 037public class Map_Rotate_Origin implements PlugInFilter, JavaDocHelp { 038 039 private static double alphaDeg = 15.0; // rotation angle (15 degrees) 040 041 /** 042 * Constructor, asks to open a predefined sample image if no other image 043 * is currently open. 044 */ 045 public Map_Rotate_Origin() { 046 if (IjUtils.noCurrentImage()) { 047 DialogUtils.askForSampleImage(GeneralSampleImage.Clown); 048 } 049 } 050 051 @Override 052 public int setup(String arg, ImagePlus im) { 053 return DOES_ALL; // works for all image types 054 } 055 056 @Override 057 public void run(ImageProcessor ip) { 058 double alpha = Math.toRadians(alphaDeg); 059 Mapping2D mi = new Rotation2D(alpha).getInverse(); // inverse mapping (target to source) 060 new ImageMapper(mi).map(ip); 061 } 062}