help with Batch Merge of 2-channel image sequence

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

help with Batch Merge of 2-channel image sequence

Jeremy Florman
I have a large data set of two channel tiff images that I would like to merge. I've been trying to find/write a plugin to facilitate this and the batchRGBmerge macro seems to be just what I'm looking for but I am running into trouble due to the fact that my images are 2-channel rather than 3-channel. My filenames have the suffix w1.tif (blue) and w2.tif (green) but I've been unable to get the batchRGB merge to recognize these suffixes or run with multiples of 2. If anyone could help me here or suggest an existing plugin/macro to accomplish this it would be greatly appreciated.

Jeremy Florman
Neurobiology Department
Umass Medical School

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

Re: help with Batch Merge of 2-channel image sequence

Jasvinder S Ahuja
Could you put the three channels in 3 different folders. Then merge one
each file from the folders? That way you would avoid problems in 3 and 2
channels and always be sure of the order
Jasvinder

On Thu, Dec 20, 2012 at 5:01 PM, Jeremy Florman <[hidden email]
> wrote:

> here

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

code to open, display, modify, pause, go back to directory

ktoo
Hi all,

I would like ImageJ to open a 4-channel image file from a directory, display the channel I'm interested in, perform some modifications of that image (these steps I know how to do), let me manually work on that image, and take me back to the directory that the image came from when I close it (these two last steps I haven't been able to work out).

It doesn't even have to open the first image automatically, as long as it takes me back to the same folder as the previously used image.

I would be grateful for help!



IMPORTANT WARNING:  This email (and any attachments) is only intended for the use of the person or entity to which it is addressed, and may contain information that is privileged and confidential.  You, the recipient, are obligated to maintain it in a safe, secure and confidential manner.  Unauthorized redisclosure or failure to maintain confidentiality may subject you to federal and state penalties. If you are not the intended recipient, please immediately notify us by return email, and delete this message from your computer.

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

Re: code to open, display, modify, pause, go back to directory

Volker Baecker
Hi,
do you want to do this in java code or in a macro?

Is the image already displayed or not? If not you have to show the image
and then you call waitForUser. This can be done in a macro or plugin. See

http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:wait_for_user:start

It will stop the execution of a macro or plugin, let the user do
something with the image. When he finished he presses the button on the
dialog and the macro or plugin continues its work.

I'm not sure what you mean by "take me back to the directory that the
image came from". ImageJ has the "open next" command that opens the next
image in the folder the current image came from. You can run it with
run("Open Next");
from a macro.

You could of course as well just iterate over the images in the folder.
See for example section 4.1 in
http://www.sussex.ac.uk/gdsc/intranet/pdfs/ImageJBatchProcessing.pdf

I hope this helps,
Volker

 On 21/12/12 00:45, Olofsdotter Otis, Klara wrote:

> Hi all,
>
> I would like ImageJ to open a 4-channel image file from a directory, display the channel I'm interested in, perform some modifications of that image (these steps I know how to do), let me manually work on that image, and take me back to the directory that the image came from when I close it (these two last steps I haven't been able to work out).
>
> It doesn't even have to open the first image automatically, as long as it takes me back to the same folder as the previously used image.
>
> I would be grateful for help!
>
>
>
> IMPORTANT WARNING:  This email (and any attachments) is only intended for the use of the person or entity to which it is addressed, and may contain information that is privileged and confidential.  You, the recipient, are obligated to maintain it in a safe, secure and confidential manner.  Unauthorized redisclosure or failure to maintain confidentiality may subject you to federal and state penalties. If you are not the intended recipient, please immediately notify us by return email, and delete this message from your computer.
>
> --
> 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: code to open, display, modify, pause, go back to directory

ktoo
Volker,

Thanks for your reply to my question! For some reason, the macro I have written (below) does not display an image for me to work on. My files are in Zeiss LSM format, so unfortunately the "Open next" command doesn't work. Maybe it would be worth my time to convert the files before trying to work on them, it might save me time. Also, thanks for the pointer to the batch processing tutorial. I will look into that more after the holidays.

Happy holidays!

Klara



dir = getDirectory("Choose a Directory "); list = getFileList(dir); setBatchMode(true); for (i=0; i<list.length; i++) { showProgress(i, list.length); open(dir+list[i]);

title = getTitle();
run("Split Channels");
selectWindow("C1-"+title);
close();
selectWindow("C2-"+title);
close();
selectWindow("C3-"+title);
close();

selectWindow("C4-"+title);
setAutoThreshold("Default dark");
run("Convert to Mask");

run("Fill Holes");
run("Watershed");
//setTool("wand");

run("Set Measurements...", "area mean perimeter display add redirect=None decimal=3");
run("wait For User");
close;}





-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Volker Baecker
Sent: Friday, December 21, 2012 2:59 AM
To: [hidden email]
Subject: Re: code to open, display, modify, pause, go back to directory

Hi,
do you want to do this in java code or in a macro?

Is the image already displayed or not? If not you have to show the image and then you call waitForUser. This can be done in a macro or plugin. See

http://imagejdocu.tudor.lu/doku.php?id=plugin:utilities:wait_for_user:start

It will stop the execution of a macro or plugin, let the user do something with the image. When he finished he presses the button on the dialog and the macro or plugin continues its work.

I'm not sure what you mean by "take me back to the directory that the image came from". ImageJ has the "open next" command that opens the next image in the folder the current image came from. You can run it with run("Open Next"); from a macro.

You could of course as well just iterate over the images in the folder.
See for example section 4.1 in
http://www.sussex.ac.uk/gdsc/intranet/pdfs/ImageJBatchProcessing.pdf

I hope this helps,
Volker

 On 21/12/12 00:45, Olofsdotter Otis, Klara wrote:

> Hi all,
>
> I would like ImageJ to open a 4-channel image file from a directory, display the channel I'm interested in, perform some modifications of that image (these steps I know how to do), let me manually work on that image, and take me back to the directory that the image came from when I close it (these two last steps I haven't been able to work out).
>
> It doesn't even have to open the first image automatically, as long as it takes me back to the same folder as the previously used image.
>
> I would be grateful for help!
>
>
>
> IMPORTANT WARNING:  This email (and any attachments) is only intended for the use of the person or entity to which it is addressed, and may contain information that is privileged and confidential.  You, the recipient, are obligated to maintain it in a safe, secure and confidential manner.  Unauthorized redisclosure or failure to maintain confidentiality may subject you to federal and state penalties. If you are not the intended recipient, please immediately notify us by return email, and delete this message from your computer.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

IMPORTANT WARNING:  This email (and any attachments) is only intended for the use of the person or entity to which it is addressed, and may contain information that is privileged and confidential.  You, the recipient, are obligated to maintain it in a safe, secure and confidential manner.  Unauthorized redisclosure or failure to maintain confidentiality may subject you to federal and state penalties. If you are not the intended recipient, please immediately notify us by return email, and delete this message from your computer.

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

Re: code to open, display, modify, pause, go back to directory

wainsw1
Klara,

This may be a little late, however I will post this with the hope that future ImageJ-ers who stumble across this forum with a similar problem find the solution they seek.  In short, your macro uses the code "setBatchMode(true);" and, according to ImageJ documentation,

setBatchMode(arg)

If arg is true, the interpreter enters batch mode and images are not displayed, allowing the macro to run up to 20 times faster. If arg is false, exits batch mode and displays the active image in a window. ImageJ exits batch mode when the macro terminates if there is no setBatchMode(false) call. Note that a macro should not call setBatchMode(true) more than once.
This means that, once you're in "Batch Mode," no images will be displayed until you set the argument (arg) to be false.  

Also, to cut down on some steps that you go through, I suggest changing the script as follows:

dir = getDirectory("Choose a Directory ");
//I excluded the setBatchMode, as the following steps occur so quickly, that they probably won't be seen anyway
//Feel free to add it, however you must setBatchMode(false) when you want to interact with the image
list = getFileList(dir);

for (i=0; i<list.length; i++) {
showProgress(i, list.length);
open(dir+list[i]);

title = getTitle();
run("Slice Remover", "first=1 last=3 increment=1");
//This will remove all slices but the fourth
//Can also be found in  Image >> Stacks >> Tools >> Slice Remover
//Note that I am using the Fiji Build of ImageJ, so this may be different than yours.  
//If you do not have the "Slice Remover" plugin, download and place it in your ImageJ plugins folder

setAutoThreshold("Default dark");
run("Convert to Mask");

run("Fill Holes");
run("Watershed");
//setTool("wand");

run("Set Measurements...", "area mean perimeter display add redirect=None decimal=3");
run("wait For User");
close;}


With these corrections, the image should appear.  

Hope this helps!
Barrett
Reply | Threaded
Open this post in threaded view
|

Re: help with Batch Merge of 2-channel image sequence

Javier Mazarío
In reply to this post by Jeremy Florman
Hi,

I know this a very old post but in case someone comes across this message, as I did, here is the modification of the "Batch RGB Merge" code (from https://imagej.nih.gov/ij/macros/Batch_RGB_Merge.txt) that I made a while ago. This is to merge blue and green images. I've also made other versions to merge blue and red, red and green, other combinations of three colors different to the original code, 4 channels and 5 channels. Feel free to contact me if you think you could use any of them.

I hope this is helpful

// "Batch RGB Merge blue and green"

// Opens multiple sets of two separate color channels as
// an RGB stack or converts them to RGB images. File names
// ending in "verde" and "azul" are assumed to be green and
// blue channels respectively, but this can be changed in
// the dialog box.

// A sample image set, courtesy of Mikael Bjorklund, is available at:
//    http://rsb.info.nih.gov/ij/macros/images/DrosophilaCells.zip
// It consists of three images of Drosophila S2 cells,
// each with three channels (d0=blue, d1=red and d2=green  
// as indicated by the end of the filename. The staining is
// standard Hoechst, phalloidin, tubulin.

  Dialog.create("RGB Batch Convert");
  //Dialog.addString("Red Suffix:", " rojo");
  Dialog.addString("Green Suffix:", " verde");
  Dialog.addString("Blue Suffix:", " azul");
  //Dialog.addString("Gray Suffix:", " gris");
  Dialog.addCheckbox("Open as Stack", false);
  Dialog.show();
  //redSuffix = Dialog.getString() + ".";
  greenSuffix = Dialog.getString() + ".";
  blueSuffix = Dialog.getString() + ".";
  //graySuffix = Dialog.getString() + ".";
  openAsStack = Dialog.getCheckbox();
  if (openAsStack)
      openImagesAsStack();
  else
      batchConvert();
  exit;

  function openImagesAsStack() {
      dir = getDirectory("Choose Source Directory ");
      list = getFileList(dir);
      setBatchMode(true);
      n = list.length;
      if ((n%2)!=0)
         exit("The number of files must be a multiple of 2");
      stack = 0;
      first = 0;
      for (i=0; i<n/2; i++) {
          showProgress(i+1, n/2);
          green="?"; blue="?";
          for (j=first; j<first+2; j++) {
              //if (indexOf(list[j], redSuffix)!=-1)
                  //red = list[j];
              if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
              //if (indexOf(list[j], graySuffix)!=-1)
                  //gray = list[j];
          }
          //open(dir+red);
          open(dir+green);
          open(dir+blue);
          //open(dir+gray);
          //run("Merge Channels...", "c1=["+red+"] c2=["+green+"] c3=["+blue+"] c4=["+gray+"]");
          run("Merge Channels...", "c2=["+green+"] c3=["+blue+"]");
          //close();
          width=getWidth; height=getHeight;
          run("Copy");
          close();
          if (stack==0) {
              newImage("RGB Stack", "RGB Black", width, height, n/2);
              stack = getImageID;
          }
          selectImage(stack);
          setSlice(i+1);
          run("Paste");
          //index = indexOf(red, redSuffix);
          //name = substring(red, 0, index);
          index = indexOf(green, greenSuffix);
          name = substring(green, 0, index);
          setMetadata(name);
          first += 2;
      }
      setSlice(1);
      run("Select None");
      setBatchMode(false);
  }

  function batchConvert() {
      dir1 = getDirectory("Choose Source Directory ");
      dir2 = getDirectory("Choose Destination Directory ");
      list = getFileList(dir1);
      setBatchMode(true);
      n = list.length;
      if ((n%2)!=0)
         exit("The number of files must be a multiple of 2");
      stack = 0;
      first = 0;
      for (i=0; i<n/2; i++) {
          showProgress(i+1, n/2);
          green="?"; blue="?";
          for (j=first; j<first+2; j++) {
              //if (indexOf(list[j], redSuffix)!=-1)
                  //red = list[j];
              if (indexOf(list[j], greenSuffix)!=-1)
                  green = list[j];
              if (indexOf(list[j], blueSuffix)!=-1)
                  blue = list[j];
              //if (indexOf(list[j], graySuffix)!=-1)
                  //gray = list[j];
          }
          //open(dir1 +red);
          open(dir1 +green);
          open(dir1 +blue);
          //open(dir1 +gray);
          //run("Merge Channels...", "c1=["+red+"] c2=["+green+"] c3=["+blue+"] c4=["+gray+"]");
          run("Merge Channels...", "c2=["+green+"] c3=["+blue+"]");
          //close();
          //index = indexOf(red, redSuffix);
          //name = substring(red, 0, index);
          index = indexOf(green, greenSuffix);
          name = substring(green, 0, index);
          saveAs("tiff", dir2+name);
          first += 2;
          run("Close All");          
      }
  }

<quote author="Jeremy Florman">
I have a large data set of two channel tiff images that I would like to merge. I've been trying to find/write a plugin to facilitate this and the batchRGBmerge macro seems to be just what I'm looking for but I am running into trouble due to the fact that my images are 2-channel rather than 3-channel. My filenames have the suffix w1.tif (blue) and w2.tif (green) but I've been unable to get the batchRGB merge to recognize these suffixes or run with multiples of 2. If anyone could help me here or suggest an existing plugin/macro to accomplish this it would be greatly appreciated.

Jeremy Florman
Neurobiology Department
Umass Medical School

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