Skip to content

Instantly share code, notes, and snippets.

@mutterer
Created April 21, 2015 11:39
Show Gist options
  • Select an option

  • Save mutterer/a7ab071d06348798b382 to your computer and use it in GitHub Desktop.

Select an option

Save mutterer/a7ab071d06348798b382 to your computer and use it in GitHub Desktop.
ImageJ macro to split LSM files
sourcedir=getDirectory("select source directory with lsm files");
destdir=getDirectory("select or create destination directory");
list = getFileList(sourcedir);
Dialog.create("New LSM Batch color converter options");
Dialog.addChoice("Export format ", newArray("Tiff", "Jpeg"));
Dialog.addCheckbox("Output merged channels image(s) ", true);
Dialog.addCheckbox("Process all time points ", false);
Dialog.addCheckbox("Process all slices ", false);
Dialog.addCheckbox("Convert to 8-bit ", false);
Dialog.show();
type = Dialog.getChoice();
merge_image = Dialog.getCheckbox();
process_frames = Dialog.getCheckbox();
process_slices = Dialog.getCheckbox();
convert8 = Dialog.getCheckbox();
for (i=0; i<list.length; i++) {
path = sourcedir+list[i];
if (endsWith(path, ".lsm")) {
run("LSM Reader", "open=["+path+"]");
processImage();
close();
}
}
function processImage() {
run("Make Composite", "composite");
id=getImageID;
t=getTitle();
t = replace(t,".","_");
t = replace(t,":","_");
t = replace(t," ","_");
Stack.getDimensions(width, height, channels, slices, frames);
ones=""; while(lengthOf(ones)<channels) ones+="1";
if (process_frames==false) frames=1;
if (process_slices==false) slices=1;
for (f=1;f<= frames;f++) {
Stack.setFrame(f);
for (s=1;s<= slices;s++) {
Stack.setSlice(s);
for (c=1;c<= channels;c++) {
selectImage(id);
Stack.setChannel(c);
run("Duplicate...", "title="+t+"_T"+f+"_Z"+s+"_"+getInfo('slice.label'));
if (convert8==true) run ("8-bit");
saveImage();
}
if (merge_image==true) {
selectImage(id);
Stack.setDisplayMode("composite");
Stack.setActiveChannels(ones);
run("RGB Color", " keep");
rename(t+"_T"+f+"_Z"+s+"_Merge");
saveImage();
}
}
}
}
function saveImage() {
saveAs(type,destdir+getTitle);
close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment