Batch process, save and split channels

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

Batch process, save and split channels

thomas.clarke
Hi I'm new to imagej and macros,

I'm splitting a nd2 file into the 3 channels, running z project, enhancing
and then saving each of the 3 channels. When I run the macro bellow in batch
processing it does everything correct however it only saves one of the
channels and without the file name I want. Any suggestions on how I can
achieve this?

T = getTitle();

run("Split Channels");
selectWindow("C1-"+T);
run("Z Project...", "projection=[Max Intensity]");
run("Enhance Contrast", "saturated=0.35");
selectWindow("C2-"+T);
run("Z Project...", "projection=[Max Intensity]");
run("Enhance Contrast", "saturated=0.35");
selectWindow("C3-"+T);
run("Z Project...", "projection=[Max Intensity]");
run("Enhance Contrast", "saturated=0.35");

selectWindow("MAX_C1-"+T);
saveAs("Jpeg", T + "Jpeg");
selectWindow("MAX_C2-"+T);
saveAs("Jpeg", T + "GREEN.Jpeg");
selectWindow("MAX_C3-"+T);
saveAs("Jpeg", T + "RED.Jpeg");



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch process, save and split channels

George Patterson
Hi Thomas,
A couple of points which might help.

1.  In these lines
saveAs("Jpeg", T + "Jpeg");
you'll probably need to specify the path to the directory in which you'd
like to store your images.
Adding something like
dir0 = getDirectory("Choose a directory");
to a some point before the saveAs lines and then edit those lines to
specify the path to that directory.
saveAs("Jpeg", dir0+T + "Jpeg");

2.  You can find many discussions on this and other lists discussing the
relative merits of image formats.
Most if not all agree that we're better off saving our files in an
uncompressed format rather than a jpeg as you are doing here.
Unless you have a specific reason for needing jpegs, I'd also suggest
changing
saveAs("Jpeg", dir0+T + "Jpeg");
to something like
saveAs("tiff", dir0+T + ".tif");

Best,
George



On Mon, Sep 18, 2017 at 2:14 AM, thomas.clarke <[hidden email]> wrote:

> Hi I'm new to imagej and macros,
>
> I'm splitting a nd2 file into the 3 channels, running z project, enhancing
> and then saving each of the 3 channels. When I run the macro bellow in
> batch
> processing it does everything correct however it only saves one of the
> channels and without the file name I want. Any suggestions on how I can
> achieve this?
>
> T = getTitle();
>
> run("Split Channels");
> selectWindow("C1-"+T);
> run("Z Project...", "projection=[Max Intensity]");
> run("Enhance Contrast", "saturated=0.35");
> selectWindow("C2-"+T);
> run("Z Project...", "projection=[Max Intensity]");
> run("Enhance Contrast", "saturated=0.35");
> selectWindow("C3-"+T);
> run("Z Project...", "projection=[Max Intensity]");
> run("Enhance Contrast", "saturated=0.35");
>
> selectWindow("MAX_C1-"+T);
> saveAs("Jpeg", T + "Jpeg");
> selectWindow("MAX_C2-"+T);
> saveAs("Jpeg", T + "GREEN.Jpeg");
> selectWindow("MAX_C3-"+T);
> saveAs("Jpeg", T + "RED.Jpeg");
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Batch process, save and split channels

Stoyan Pavlov
Hi Thomas,
I recently had to write a macro for batch extraction of channels from a
composite image. Feel free to modify as needed. It's a bit crude but gets
the job done:
What the macro does is : it asks you for the composite images folder and
for channel folders. Than based on the lookup table it renames the channels
and saves them to the corresponding folder. You can modify it to only save
them by channel number.

Best wishes,
Stoyan
---


inputDir = getDirectory("Choose composite image directory! ");
chDir1 = getDirectory("Choose directory to save ch1! ");
chDir2 = getDirectory("Choose directory to save ch2! ");
chDir3 = getDirectory("Choose directory to save ch3! ");
chDir4 = getDirectory("Choose directory to save ch4! ");

fileList1 = getFileList(inputDir);

setBatchMode(true);
for (i = 0; i < fileList1.length; i++) {
   showProgress(i, fileList1.length);
   file1 = fileList1[i];
   open(inputDir+file1);
  id1 = getTitle();
 run("Split Channels");

 chnumber= getList("image.titles");
for (c = 0; c < chnumber.length; c++) {
cn=c+1;
selectWindow("C"+cn+"-"+id1);
 getLut(reds, greens, blues);
 if (blues[254] == 254) {
  rename("DAPI_"+id1);
  idch1 = getTitle();
  saveAs("Tiff", chDir1 + "/" + idch1);}
  else if (reds[254] == 254) {
  if (greens[254] == 254) {
  rename("AF647_"+id1);
  idch4 = getTitle();
  saveAs("Tiff", chDir4 + "/" + idch4);}
  else {rename("CY3_"+id1);
  idch3 = getTitle();
  saveAs("Tiff", chDir3 + "/" + idch3);}
  }
  else {rename ("FITC_"+id1);
  idch2 = getTitle();
saveAs("Tiff", chDir2 + "/" + idch2);}
}


run("Close All");
}
showMessage("Finished splitting channels!");
---

---
Dr. Stoyan P. Pavlov, MD, PhD
Departament of Anatomy, Histology and Embryology
Medical University "Prof. Dr. Paraskev Stoyanov", Varna
Prof. Marin Drinov Str.55
9002 Varna
 Bulgaria
Tel: +359 (0) 52 - 677 - 052
e-mail: [hidden email]
           [hidden email]

2017-09-18 22:02 GMT+03:00 George Patterson <[hidden email]>:

> Hi Thomas,
> A couple of points which might help.
>
> 1.  In these lines
> saveAs("Jpeg", T + "Jpeg");
> you'll probably need to specify the path to the directory in which you'd
> like to store your images.
> Adding something like
> dir0 = getDirectory("Choose a directory");
> to a some point before the saveAs lines and then edit those lines to
> specify the path to that directory.
> saveAs("Jpeg", dir0+T + "Jpeg");
>
> 2.  You can find many discussions on this and other lists discussing the
> relative merits of image formats.
> Most if not all agree that we're better off saving our files in an
> uncompressed format rather than a jpeg as you are doing here.
> Unless you have a specific reason for needing jpegs, I'd also suggest
> changing
> saveAs("Jpeg", dir0+T + "Jpeg");
> to something like
> saveAs("tiff", dir0+T + ".tif");
>
> Best,
> George
>
>
>
> On Mon, Sep 18, 2017 at 2:14 AM, thomas.clarke <[hidden email]> wrote:
>
> > Hi I'm new to imagej and macros,
> >
> > I'm splitting a nd2 file into the 3 channels, running z project,
> enhancing
> > and then saving each of the 3 channels. When I run the macro bellow in
> > batch
> > processing it does everything correct however it only saves one of the
> > channels and without the file name I want. Any suggestions on how I can
> > achieve this?
> >
> > T = getTitle();
> >
> > run("Split Channels");
> > selectWindow("C1-"+T);
> > run("Z Project...", "projection=[Max Intensity]");
> > run("Enhance Contrast", "saturated=0.35");
> > selectWindow("C2-"+T);
> > run("Z Project...", "projection=[Max Intensity]");
> > run("Enhance Contrast", "saturated=0.35");
> > selectWindow("C3-"+T);
> > run("Z Project...", "projection=[Max Intensity]");
> > run("Enhance Contrast", "saturated=0.35");
> >
> > selectWindow("MAX_C1-"+T);
> > saveAs("Jpeg", T + "Jpeg");
> > selectWindow("MAX_C2-"+T);
> > saveAs("Jpeg", T + "GREEN.Jpeg");
> > selectWindow("MAX_C3-"+T);
> > saveAs("Jpeg", T + "RED.Jpeg");
> >
> >
> >
> > --
> > Sent from: http://imagej.1557.x6.nabble.com/
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html