Login  Register

Re: Batch stack to images, with renaming

Posted by Krs5 on Dec 23, 2014; 11:24am
URL: http://imagej.273.s1.nabble.com/Batch-stack-to-images-with-renaming-tp5011012p5011039.html

Dear jpmatson

If the number of images within each individual stack is the same the macro code below might work. Copy the code and past it into a macro editor (File > New > Text Window) and hit run.
If not, you might be able to optimize the code for your use.

macro split_stack{
dir1 = getDirectory("Choose source directory");
list = getFileList(dir1);
dir2 = getDirectory("Choose destination directory");
a = 1;
Dialog.create("Input");
 Dialog.addNumber("Number of images per stack",a);
Dialog.show();
a = Dialog.getNumber();
setBatchMode(true);
for (i=0; i<list.length; i++) {
 open(dir1+list[i]);
 getDimensions(width, height, channels, slices, frames);
 counter=1;
 title = File.nameWithoutExtension;
 for (j=1; j< slices;j+=a){
  k = j+a-1;
  run("Make Substack...", "channels=1-"+channels+" slices="+j+"-"+k);
  saveAs("tif", dir2+title+"-stack"+counter+".tiff");
  close();
  counter+=1;
 }
 close();
}
showMessage("Macro is finished");
}



Best wishes and Merry Christmas

Kees

Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif
________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of cellcyclist [[hidden email]]
Sent: 20 December 2014 04:30
To: [hidden email]
Subject: Batch stack to images, with renaming

I have many tiff files with multiple stacks in each tiff. I would like to
split the stacks into individual tifs and save them in batch, with the file
names of the new images labeled with the original image and info about the
stack. For example:

Image 1.tiff
Image 2.tiff

converted to

Image 1-stack1.tiff
Image 1-stack2.tiff
Image 1-stack3.tiff
Image 2-stack1.tiff
Image2-stack2.tiff
Image2-stack3.tiff

I can sort of do what I want by opening all the original tiffs with stacks
as Import->Image Sequence, then Save As->Image Sequence, but that renames
all the files. I've tried using slice labels as file name when saving the
image process, but that requires me going through and setting up each splice
label, which defeats the whole point of batch.

Any thoughts or advice?



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-stack-to-images-with-renaming-tp5011012.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html