/* Copyright (c) 2010 University of Chicago. All rights reserved. Fccd_RemovedOverScan is distributed subject to the following license conditions: SOFTWARE LICENSE AGREEMENT Software: Fccd_RemovedOverScan Versions: Release 1 and higher 1. The "Software", below, refers to Fccd_RemovedOverScan (in either source code, or binary form and accompanying documentation). Each licensee is addressed as "you" or "Licensee." 2. The copyright holders shown above and their third-party licensors hereby grant Licensee a royalty-free nonexclusive license, subject to the limitations stated herein and U.S. Government license rights. 3. You may modify and make a copy or copies of the Software for use within your organization, if you meet the following conditions: 1. Copies in source code must include the copyright notice and this Software License Agreement. 2. Copies in binary form must include the copyright notice and this Software License Agreement in the documentation and/or other materials provided with the copy. 4. You may modify a copy or copies of the Software or any portion of it, thus forming a work based on the Software, and distribute copies of such work outside your organization, if you meet all of the following conditions: 1. Copies in source code must include the copyright notice and this Software License Agreement; 2. Copies in binary form must include the copyright notice and this Software License Agreement in the documentation and/or other materials provided with the copy; 3. Modified copies and works based on the Software must carry prominent notices stating that you changed specified portions of the Software. 5. Portions of the Software resulted from work developed under a U.S. Government contract and are subject to the following license: the Government is granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide license in this computer software to reproduce, prepare derivative works, and perform publicly and display publicly. 6. WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDERS, THEIR THIRD PARTY LICENSORS, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4) DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL BE CORRECTED. 7. LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT HOLDERS, THEIR THIRD PARTY LICENSORS, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE, EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGES. */ // Originally created by John Weizeorick at APS import java.io.*; import java.awt.*; import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; import ij.io.*; public class Fccd_RemoveOverScan implements PlugInFilter { ImagePlus imp; protected ImageStack stackin; protected ImageStack stackout; public int setup(String arg, ImagePlus imp) { this.imp = imp; stackin = imp.getStack(); // added for stack operation // stackout = imp.createEmptyStack(); stackout = new ImageStack(480, 494); return DOES_ALL; } public void run(ImageProcessor ip) { String fixedFilepath = IJ.getDirectory("current"); // can get "home","plugins",.... for (int stackNum=1; stackNum <= stackin.getSize(); stackNum++) { ImageProcessor ipSlice = stackin.getProcessor(stackNum); String subfilename = imp.getTitle(); subfilename = "S_" + subfilename; //String fixedFilename = imp.getTitle(); String fixedFilename = stackin.getSliceLabel(stackNum); fixedFilename = "FCCDNoOverScan_" + fixedFilename; String filePathAndName = fixedFilepath + fixedFilename; ImagePlus imp3 = NewImage.createShortImage(fixedFilename, 480, 494, 1, NewImage.FILL_BLACK); ImageProcessor ip3 = imp3.getProcessor(); int x_org = 0; int x_new = 0; int y_new = 0; // Top of image - remove over scan columns - read right to left for (int y=0; y<247; y++) for(int Column = 0; Column<48; Column++) for(int xColumnPixel = 0; xColumnPixel < 10; xColumnPixel++) { x_org = xColumnPixel + (Column*12); x_new = xColumnPixel + (Column*10); ip3.set(x_new, y, (int) ipSlice.get(x_org,y) ); } // Bottom of image - remove over scan columns - read left to right for (int y=253; y<500; y++) for (int Column = 0; Column<48; Column++) for (int xColumnPixel = 0; xColumnPixel < 10; xColumnPixel++) { x_org = xColumnPixel + (Column * 12) + 2; x_new = xColumnPixel + (Column*10); y_new = y - 6; ip3.set(x_new, y_new, (int)ipSlice.get(x_org,y) ); } ip3.setMinAndMax( 0, (double) ip3.getAutoThreshold() + 500 ); new FileSaver(imp3).saveAsTiff(filePathAndName); stackout.addSlice( "FCCDNoOverScan" , ip3); } // end stack operation // show stack of results new ImagePlus("FCCDNoOverScan", stackout).show(); } }