/* ImageJ Binning Macro (c) 2005-2015 Renaud Lebrun This macro is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ // This macro requires the averaging reducer plugin!!! requires("1.33n"); dir = getDirectory("Choose input directory "); list = getFileList(dir); dir2 = getDirectory("Choose a target directory "); Sort(list); start = getTime(); setBatchMode(true); // runs up to 6 times faster length = list.length; print ("length "+length); for (i=0; i=10)&&(k<=99)){im_num = "00"+toString(k);} if ((k>=100)&&(k<=999)){im_num = "0"+toString(k);} if ((k>=1000)){im_num = toString(k);} image_output = dir2+"Bin_"+im_num; print ("image_input1 "+list[i]); print ("image_input2 "+list[i+1]); print ("image_output "+im_num); showProgress(i, list.length); //list[i] must not be a directory! if (!endsWith(image_input1,"/") &&!endsWith(image_input2,"/")) { //run("Raw...", "open="+image_input1+" image=[32-bit Real] width=1959 height=1959 offset=0 number=1 gap=0"); //run("Raw...", "open="+image_input2+" image=[32-bit Real] width=1959 height=1959 offset=0 number=1 gap=0"); open(image_input1);//First image open(image_input2);//Second image run("Convert Images to Stack"); id_stack = getImageID(); run("Z Project...", "start=1 stop=2 projection=[Average Intensity]"); id_zproject = getImageID(); run("Averaging Reducer", "x=2 y=2"); saveAs("Tiff", image_output); //saveAs("Raw Data", image_output); close(); selectImage(id_stack); close(); selectImage(id_zproject); close(); } i++; } setBatchMode(false); // runs up to 6 times faster //print((getTime()-start)/1000); function Sort (a) { if (! AlreadySorted(a)) {SortA(a, 0, a.length-1);} } function SortA (a, from, to) { i = from; j = to; center = a[(from + to)/2]; do { while(i a[i]) {i++;} while (j>from && center = comes after //< = comes before for (i=1; i" + a[i-1]);} } return true; }