problems with macro (solved)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

problems with macro (solved)

PEARSON Matthew
Hi Wayne,

Yes that did indeed work.  I was confused as to which functions work  
in batch mode or not and using Put Behind [tab] always seems to get me  
confused when it comes to selecting images so using the  
selectImage(id) makes a lot of sense.  For anyone who doesn't know,  
you can find out the ID number of an image by selecting Image>Show  
Info...
if C3 is the active window and getimageID returns -10, C2 = -9, C3 = -8
Then use this line:
c3=getImageID; c2=c3+1; c1=c3+2;

Thanks for the help again wayne!
best wishes,
Matt.


Dear Matt,

Your macro appeared to work okay for me but I had to modify it to work  
in batch mode. I removed the run("Put Behind [tab]") calls, which  
don't work in batch mode, and replaced them with selectImage(id)  
calls. Please test my modified version and let me know how it works  
for you.

Best regards,

-wayne


setBatchMode(true);
dir1 = getDirectory("Choose source directory");
//Returns an array containing the names of files in a directory
list = getFileList(dir1);
dir2 = getDirectory("Choose destination directory");

//Runs the code block and increments

for (i=0; i<list.length; i++){
  path = dir1+list[i];

  run("Bio-Formats Windowless Importer", "open=[path]");
  title = File.nameWithoutExtension;
  run("Stack to Images");
  c3=getImageID; c2=c3+1; c1=c3+2;
  rename("Ch3-T3");
  run("Grays");
  selectImage(c2);
  rename("Ch2-T2");
  run("Grays");
  selectImage(c1);
  rename("Ch1-T1");
  run("Grays");

  run("Merge Channels...", "c1=Ch3-T3 c2=Ch2-T2 c3=Ch1-T1 create keep");
  selectWindow("Composite");
  run("RGB Color");
  selectWindow("Composite (RGB)");
  saveAs("Tiff", dir2 + title + "(RGB).tif");
  run("Close");
  run("Close");

  selectImage(c1);
  run("8-bit");
  saveAs("Tiff", dir2 + title + "Blue 8 bit");
  run("Close");

  selectImage(c2);
  run("8-bit");
  saveAs("Tiff", dir2 + title + "Green 8 bit");
  run("Close");

  selectImage(c3);
  run("8-bit");
  saveAs("Tiff", dir2 + title + "Red 8 bit");
  run("Close");

}




On May 8, 2012, at 12:47 PM, Matthew Pearson wrote:

> Hi all,
>
> I'm trying to figure out what's wrong with my macro.
> Basically it should open all zeiss LSM files in a folder, create a
> composite colour image (3 channels) keeping the originals save the
> composite then save the original channels as 8bit gray scale.  The
> composite saves fine but the individual planes it often saves the red
> channel 3 times and not the other 2.
> if i split saving of the composite and the originals so they are in 2
> scripts it works ok but noT when the code is all together.  I'd like
> to get this running in batch mode so it runs quicker also.
> Can any one see any fundamental issues here?
> Thanks for your help,
> Matt.
>
>
> This is the script:
>
> //macro batch converts 3 colour LSM files
> //into individual channel mono 8 bit tiffs
> //and a RGB 24bit merge
> //uses batchmode so images don't need to be opened
>
>
> dir1 = getDirectory("Choose source directory");
> //Returns an array containing the names of files in a directory
> list = getFileList(dir1);
> dir2 = getDirectory("Choose destination directory");
>
> //Runs the code block and increments
>
> for (i=0; i<list.length; i++){
>
> path = dir1+list[i];
>
> run("Bio-Formats Windowless Importer", "open=[path]");
> title = File.nameWithoutExtension;
> run("Stack to Images");
> rename("Ch3-T3");
> run("Grays");
> run("Put Behind [tab]");
> rename("Ch2-T2");
> run("Grays");
> run("Put Behind [tab]");
> rename("Ch1-T1");
> run("Grays");
>
> run("Merge Channels...", "c1=Ch3-T3 c2=Ch2-T2 c3=Ch1-T1 create keep");
> selectWindow("Composite");
> run("RGB Color");
> selectWindow("Composite (RGB)");
> saveAs("Tiff", dir2 + title + "(RGB).tif");
> run("Close");
> run("Close");
>                                                  IF I PUT FROM HERE
> ONWARDS INTO A SEPARATE SCRIPT IT WORKS OK.
> run("8-bit");
> saveAs("Tiff", dir2 + title + "Blue 8 bit");
> run("Close");
>
> run("8-bit");
> saveAs("Tiff", dir2 + title + "Red 8 bit");
> run("Close");
>
> run("8-bit");
> saveAs("Tiff", dir2 + title + "Green 8 bit");
> run("Close");
> }
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.