Posted by
Krs5 on
URL: http://imagej.273.s1.nabble.com/Ugly-Macro-help-Splitting-multi-channel-images-and-combining-into-stack-made-up-of-images-of-one-colr-tp5018408p5018411.html
Dear Laura,
I think the code below might do what you want
setBatchMode(true);
dir=getDirectory("Choose an Input Directory");
list = getFileList(dir);
saveloc = getDirectory("Choose Ouput Directory");
run("Image Sequence...", "open=[dir]"+list[1]+" sort");
run("Make Substack...", "delete slices=1-"+list.length*3+"-3");
saveAs("Tiff", saveloc+"FullStackC1.tif");
close();
run("Make Substack...", "delete slices=1-"+list.length*2+"-2");
saveAs("Tiff", saveloc+"FullStackC2.tif");
close();
saveAs("Tiff", saveloc+"FullStackC3.tif");
close();
waitForUser("Macro is finished.");
Best wishes
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/aifImageJ workshops 1 and 2 June 2017:
https://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/AIF/workshops/imagej-workshops-June-2017-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of lmurphy
Sent: 28 March 2017 22:48
To:
[hidden email]
Subject: Ugly Macro help - Splitting multi channel images and combining into stack made up of images of one colour
Someone asked me to write a macro that does the below. I know I'm doing it in a very inelegant fashion (especially including the fact that I save and delete files). I was wondering if anyone could help me see where it could be done in a better way? Thank you in advance.
Input is a number of multi-channel images The desired output is one saved tiff stack for each of the channels.
setBatchMode(true);
dir=getDirectory("Choose an Input Directory"); print(dir); list = getFileList(dir); saveloc = getDirectory("Choose Ouput Directory");
for (i=0; i<list.length; i++) {
if (endsWith(list[i], ".tif")){
print(i + ": " + dir+list[i]);
open(dir+list[i]);
imgName=getTitle();
run("Split Channels");
selectWindow("C1-"+imgName);
saveAs("Tiff", saveloc + "C1-"+imgName); close(); selectWindow("C2-"+imgName); saveAs("Tiff", saveloc + "C2-"+imgName); close(); selectWindow("C3-"+imgName); saveAs("Tiff", saveloc + "C3-"+imgName); close(); run("Close All"); } else { } }
run("Image Sequence...", "open=[saveloc] file=C1 use");"); saveAs("Tiff", saveloc+"FullStackC1.tif"); run("Close All");
run("Image Sequence...", "open=[saveloc] file=C2 use");"); saveAs("Tiff", saveloc+"FullStackC2.tif"); run("Close All");
run("Image Sequence...", "open=[saveloc] file=C3 use");"); saveAs("Tiff", saveloc+"FullStackC3.tif"); run("Close All");
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (startsWith(list[i], "C"))
File.delete(dir+list[i]);
}
Dialog.create("Progress");
Dialog.addMessage("Complete!");
Dialog.show;
setBatchMode(false);
--
View this message in context:
http://imagej.1557.x6.nabble.com/Ugly-Macro-help-Splitting-multi-channel-images-and-combining-into-stack-made-up-of-images-of-one-colr-tp5018408.htmlSent 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