Skip to content

Instantly share code, notes, and snippets.

@nbr23
Created June 20, 2017 20:40
Show Gist options
  • Select an option

  • Save nbr23/1f19d31c3e2fd81e258280a454cf0197 to your computer and use it in GitHub Desktop.

Select an option

Save nbr23/1f19d31c3e2fd81e258280a454cf0197 to your computer and use it in GitHub Desktop.
Image J Batch red green channel merge and invert (based of http://onlinelibrary.wiley.com/doi/10.1111/j.1365-2818.2007.01719.x/full )
.\ImageJ.exe -eval "macfile=File.openAsString('batch_rg_channels_merge.macro'); eval(macfile);"
macro "Batch RG Channels Merge" {
sourcedir=getDirectory("Select the source images directory");
resultdir=getDirectory("Select the result images directory");
flist=getFileList(sourcedir);
File.makeDirectory(resultdir);
for (i = 0; i < flist.length; i++){
open(sourcedir + '/' + flist[i]);
fname = File.nameWithoutExtension;
run('RGB Split');
close();
selectImage(1);
run('Rename...', 'title=green');
selectImage(2);
run('Rename...', 'title=red');
run('Image Calculator...', 'image1=[green] operation=AND image2=[red] create');
run('Invert');
run('Rename...', 'title=Result');
selectWindow('red');
run('Close');
selectWindow('green');
run('Close');
selectWindow('Result');
save(resultdir + '/' + fname + '_result.tiff');
run('Close');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment