Login  Register

RE: batch processing macro problem.

Posted by jacob goodwin on Feb 18, 2015; 10:34am
URL: http://imagej.273.s1.nabble.com/batch-processing-macro-problem-tp5011621p5011657.html

Thanks Christine for all of your help.

The macro that you wrote works great for the 4 images when I run it through 4 open images.  I rearranged the order to make the images appear int he right order (from 3214 to 4123) and then I altered the channel colours to match what I needed. 

I may have over simplified the naming of these files so that I could try and say what I have without it getting too confusing.  Here is the first two sets of images.  The A1 is the well number, the W00001 is the position in that well (each well had six images taken).

A1--W00001--P00001--Z00000--T00000--Alexa488
A1--W00001--P00001--Z00000--T00000--Alexa555
A1--W00001--P00001--Z00000--T00000--Alexa647
A1--W00001--P00001--Z00000--T00000--DAPI
A1--W00001--P00002--Z00000--T00000--Alexa488
A1--W00001--P00002--Z00000--T00000--Alexa555
A1--W00001--P00002--Z00000--T00000--Alexa647
A1--W00001--P00002--Z00000--T00000--DAPI

After we get to the 6th image for that well it then starts over with A2--W00002--P00001----etc

At the end of this, I want to have just the montages of all files so that we can group them together in their respective treatments and if we want to use any particular image set then we can go back to the files and work on them one by one, so I do not need to save the stacks etc (I only have so much hard drive space).  So I would like to have the files be converted to the montage and then this image saved into a sub folder within the folder that contains the original images.  Currently the image montage saves as

A1--W00001--P00001--Z00000--T00000--DAPI montage.tif 

So I am very happy with that, thanks.

If I then Directly take your macro and try to do the Batch>macro from the image folder to a output folder on the desktop it comes up with a window that says Hyperstack converter, then channels x slices x frames <> stack size

Thanks again for your help Christine and if you could help get this into batch mode I would be really grateful. I will also have a play with it but I am not hopeful, when it comes to this sort of thing I am pretty useless.

Here is the code as it is


   t=getTitle();                                                                       
   s=lastIndexOf(t, '.');                         
   t=substring(t, 0,s);
   t=replace(t," ","_");
 
t2= t +' montage.tif';             
run("Images to Stack", "name=Stack title=[] use");
run("Stack to Hyperstack...", "order=xyczt(default) channels=4 slices=1 frames=1 display=Composite");
run("Arrange Channels...", "new=4123");
Stack.setDisplayMode("color");
Stack.setChannel(1);
run("Blue");
Stack.setChannel(2);
run("Green");
Stack.setChannel(3);
run("Red");
Stack.setChannel(4);
run("Magenta");
Stack.setDisplayMode("composite");
run("Stack to RGB");
rename("merge");
selectWindow("Stack");
Stack.setDisplayMode("color");
run("RGB Color");
run("Add Slice");
selectWindow("merge");
run("Copy");
selectWindow("Stack (RGB)");
run("Paste");
run("Make Montage...", "columns=5 rows=1 scale=1 first=1 last=5 increment=1 border=0 font=12");
rename(t2);                                     


Thanks again,

Jacob Goodwin




From: Christine Labno-2 [via ImageJ] [ml-node+[hidden email]]
Sent: Tuesday, 17 February 2015 6:28 PM
To: Jacob Goodwin
Subject: Re: batch processing macro problem.

Hi Jacob,

I think I can help you, but I had to make some guesses about what you wanted based on your description and macro code.  

I think the code below does what you want as far as creating the montage.  It's not in batch mode yet, but I can get it there pretty easily.  I just want to make sure this does what you want before we get into batch processing.  

Your method is a little convoluted, but not by much.  I modified your code a bit to keep from having to go in and out of stacks so much.  

First I grab the name for you and modify it slightly so that the montage is saved as "original name montage.tif"  Not knowing your exact file name format it may not come out exactly right, but it can be modified.  Then I rearrange the stack to the order (I think) you want.  It should proceed automatically now, with the addition of the "new=" code.  If you need a different order, modify the numbers in this line.  run("Arrange Channels...", "new=3214");

Then I set up the colors, again guessing based on what I think you want, create the merged image by having the hyperstack spit out an RGB, convert the original hyperstack to RGB as well, add a new blank frame to the end of this hyperstack into which I paste the merged image (so you don't have to go out of stack, merge and back into stack).  Then I make the montage and rename it in preparation for saving.  

Does this all make sense to you?  Can you modify it to be closer to exactly what you want in terms of colors and names, test and then post/send it back?  Then I can help you get the code into batch mode (or you could try this code with the Process --> Batch --> Macro feature and see if you can automate whole folder processing that way).  

Best,
Christine

------------------------begin macro after this line--------------------------
   t=getTitle();                                                                        
   s=lastIndexOf(t, '.');                          
   t=substring(t, 0,s);
   t=replace(t," ","_");
 
t2= t +' montage.tif';              
run("Images to Stack", "name=Stack title=[] use");
run("Stack to Hyperstack...", "order=xyczt(default) channels=4 slices=1 frames=1 display=Composite");
run("Arrange Channels...", "new=3214");
Stack.setDisplayMode("color");
Stack.setChannel(1);
run("Red");
Stack.setChannel(2);
run("Green");
Stack.setChannel(3);
run("Blue");
Stack.setChannel(4);
run("Magenta");
Stack.setDisplayMode("composite");
run("Stack to RGB");
rename("merge");
selectWindow("Stack");
Stack.setDisplayMode("color");
run("RGB Color");
run("Add Slice");
selectWindow("merge");
run("Copy");
selectWindow("Stack (RGB)");
run("Paste");
run("Make Montage...", "columns=5 rows=1 scale=1 first=1 last=5 increment=1 border=0 font=12");
rename(t2);                                      

------------------------end macro after this line--------------------------

--------------------------------------------
Christine Labno, Ph.D.
Asst. Technical Director
Light Microscopy Core
University of Chicago
Office of Shared Research Facilities
KCBD 1250 900 E. 57th St.
(773) 834-9040 (phone)

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of jacob goodwin [[hidden email]]
Sent: Monday, February 16, 2015 1:58 PM
To: [hidden email]
Subject: batch processing macro problem.

Hi everyone,

I have used imagej a bit in the past (not much, and very basic) but I have
absolutely no ideas about how to approach this problem.

We recently had a 384 well, 4 channel microscopy screen performed on drug
treatment of cells.  We received data files that were 12bit images, that I
was able to convert to 8bit tiffs so we could view the grey scale images.
(the company has done some analysis, but we still want to view the image
files, to see if we can get any further data from it.

The data is in one folder, and the order of the image files is A1-1 to A1-6,
A2-1 to A2-6 etc

each file name then having the wavelength name at the end (in the following
order)
488
555
647
Dapi

What I would like to do, is pseudo colour all the images, make an overlay,
and then if I am not pushing my luck too far, to make a montage of all the
images while keeping the A1-1 name.

So far I am unable to record a macro that allows me to do this, to keep it
simple first I open the 4 images, then start recording the macro.  I convert
the images to a stack, then hyperstack, make it composite with display mode
set to colour.  I then Arrange the colours so that they are in the correct
order, split the channels again then merge the images (while keeping the
source images) to create the combined image (which is still in a stack). To
get rid of the stack I convert the merged image to a RGB colour file and
close the merged stack.

This leaves me with 5 open files, four individual colours plus the merged.
I then turn this into a stack, and then create a montage (with 5 columns and
1 row).  I then save the montage file, and close down the stack.  End the
recording, create and save the macro to the macro folder.

To me this seems a very convoluted process, but I cannot find a simpler
method.  If I do this manually as described, I save the image that I want
(the montage of 4+1merge), however, if I open up another 4 images and then
run the macro a number of issues occur.

First the macro stops at the Arrange channels, so I then have to go and
reassign the colours.  After that it goes through and makes the montage, but
now all images in the montage are all of one colour (whichever is the first
in the arrange channel)

This also doesn't solve the problem of applying this to the whole folder

If anyone has any ideas that would be great, and I am sorry if anything I
have asked has been solved previously, I was unable to find what I needed.

Cheers

Jacob


This is the macro as it stands now.
run("Images to Stack", "name=Stack title=[] use");
run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices=4
frames=1 display=Color");
run("Make Composite", "display=Color");
run("Arrange Channels...");
run("Stack to Images");
run("Merge Channels...", "c1=Stack-0003 c2=Stack-0002 c3=Stack-0001
c6=Stack-0004 create keep");
run("RGB Color");
run("Close");
run("Images to Stack", "name=Stack title=[] use");
run("Make Montage...", "columns=5 rows=1 scale=1 first=1 last=5 increment=1
border=0 font=12");
saveAs("Tiff", "C:\\Users\\Jacob\\Desktop\\Montage new macro.tif");
run("Close");
run("Close");





--
View this message in context: http://imagej.1557.x6.nabble.com/batch-processing-macro-problem-tp5011621.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



If you reply to this email, your message will be added to the discussion below:
http://imagej.1557.x6.nabble.com/batch-processing-macro-problem-tp5011621p5011640.html
To unsubscribe from batch processing macro problem., click here.
NAML