help with modifying ImageJ macro Batch RGB merge

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

help with modifying ImageJ macro Batch RGB merge

tcarter
Hi,

We regularly acquire 3 color confocal fluorescence images and would like a quick and simple way of merging these to RGB.

There is a Batch_RBG merge macro available (code appended below) however, there are particular problems with its use in our case; specifically 1) it only works with a folder containing multiples of 3 image files and cannot cope with folders that also contain non-image files (e.g. log files that are typically generated by microscope software systems) and 2) it does not work with a folder that contains subfolders.  

Our problem:
Our image data is acquired in .pic format (BioRad confocal file format) with 3 .pic files (for each wavelength) saved into a folder along with with several other BioRad specific log files. Each experiment generates its own folder.....so we end up with a directory (folder) with many subfolders, each containing the 3 .pic files plus their ancillary log files.

I have found (and modified) a simple macro that allows us to access subfolders within a directory and batch convert the .pic files to .tif format (It looks specifically for the .pic files and ignores files with other extensions; I have pasted the code for that macro below). What we now need is a modified Batch_RBG_merge macro that can 1) look in subfolders within a directory, 2) identity only the 3 .tif files we have generated, and 3) carry out an RGB merge placing the merged file in the same folder, while ignoring the other ancillary log files.

Unfortunately I am simply not up to the task of modifying the Batch_RBG_merge macro to achieve this (I have tried but have failed).

Is there anyone out there who could help.

Thanks in advance.

Tom
---------------------------------
Code for the macro that recursively converts .pic files to .Tiff starting in a user-specified directory and able to access subfolders.

dir = getDirectory("Choose a Directory ");
count = 1;
prefix = "converted-";
listFiles(dir);

function listFiles(dir) {
    list = getFileList(dir);
    for (i=0; i<list.length; i++) {
        if (endsWith(list[i], "/"))
            listFiles(""+dir+list[i]);
        else if (endsWith(toLowerCase(list[i]), ".pic") ||
            endsWith(toLowerCase(list[i]), ".pic"))
        {
            print((count++) + ": " + dir + list[i]);
            open(dir + list[i]);
            // convert all open images to TIFF
            c = 1;
            while (nImages > 0) {
                // place additional commands here
                saveAs("Tiff", dir + prefix + list[i] + "-" + c + ".tif");
                close();
                c++;
            }
        }
    }
}    

------------------------------------------------------------------
code for the Batch_RBG_merge macro

// "Batch RGB Merge"

// Opens multiple sets of three separate color channels as
// an RGB stack or converts them to RGB images. File names
// ending in "d1", "d2" and "d0" are assumed to be red, 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:", "02");
  Dialog.addString("Green Suffix:", "01");
  Dialog.addString("Blue Suffix:", "03");
  Dialog.addCheckbox("Open as Stack", true);
  Dialog.show();
  redSuffix = Dialog.getString() + ".";
  greenSuffix = Dialog.getString() + ".";
  blueSuffix = 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%3)!=0)
         exit("The number of files must be a multiple of 3");
      stack = 0;
      first = 0;
      for (i=0; i<n/3; i++) {
          showProgress(i+1, n/3);
          red="?"; green="?"; blue="?";
          for (j=first; j<first+3; 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];
          }
          open(dir+red);
          open(dir+green);
          open(dir+blue);
          run("RGB Merge...", "red=["+red+"] green=["+green+"] blue=["+blue+"]");
          width=getWidth; height=getHeight;
          run("Copy");
          close();
          if (stack==0) {
              newImage("RGB Stack", "RGB Black", width, height, n/3);
              stack = getImageID;
          }
          selectImage(stack);
          setSlice(i+1);
          run("Paste");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
          setMetadata(name);
          first += 3;
      }
      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%3)!=0)
         exit("The number of files must be a multiple of 3");
      stack = 0;
      first = 0;
      for (i=0; i<n/3; i++) {
          showProgress(i+1, n/3);
          red="?"; green="?"; blue="?";
          for (j=first; j<first+3; 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];
          }
          open(dir1 +red);
          open(dir1 +green);
          open(dir1 +blue);
          run("RGB Merge...", "red=["+red+"] green=["+green+"] blue=["+blue+"]");
          index = indexOf(red, redSuffix);
          name = substring(red, 0, index);
          saveAs("tiff", dir2+name);
          first += 3;
      }
  }


Reply | Threaded
Open this post in threaded view
|

FIJI Stitching Plugins

PEARSON Matthew
Hi all,

I'm using a QImaging Micropublisher camera to acquire tiles of images in Micro-Manager then i'm stitching using the deprecated>Stitch directory with images (unknown configuration).  This is the only method that works for me with this camera.  Is there a newer equivalent method to this which should work?  My only issue with the old method assuming it remains deprecated is that its quite slow, computing the stitch can take many minutes even for just a few images <15.  I should say that i'm using a Mac and wondered if compute time would be slower?  I am using FIJI 64bit.

Thanks for the advice,

Matt

--
Matt Pearson
Core Microscopy Facility
MRC Human Genetics Unit
IGMM
University of Edinburgh
Carrington Crescent
EH4 2XU


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

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

Re: FIJI Stitching Plugins

Majurski, Michael Paul (Fed)
Matt,

The simple answer to your question is the newer version of deprecated>Stitch directory with images (unknown configuration) should be "Plugins > Stitching > Grid/Collection stitching" of type "Unknown position".

I have also included a longer answer containing a summary of the two automatic image stitching FIJI plugins that I am aware of. I restrict it to "automatic" because TrackEM2 also can perform image registration, but from what I have heard it is more manual.


1) "Grid/Collection stitching"
This plugin ships with Fiji:
Plugins > Stitching > Grid/Collection Stitching
Which has a help page http://fiji.sc/Image_Stitching 
Specifically http://fiji.sc/Image_Stitching#Grid.2FCollection_Stitching

I have found that this plugin is fairly robust when the images have enough content for the phase correlation image alignment method to operate on. When the images are sparser I have had trouble getting accurate results with it.

2) "MIST"
This stitching plugin I helped write and it uses the same basic translation computation algorithm as the "Grid/Collection stitching" but it has a different translation optimization algorithm which models the mechanical stage actuators to constrain the translations.
Plugins > Stitching > MIST
Project page: https://isg.nist.gov/deepzoomweb/resources/csmet/pages/image_stitching/image_stitching.html
Github page: https://github.com/NIST-ISG/MIST 
Installation guide: https://github.com/NIST-ISG/MIST/wiki/Install-Guide
User guide: https://github.com/NIST-ISG/MIST/wiki/User-Guide

"MIST" requires a grid of images which overlap by a roughly constant amount, for example, 10% +- 3%. Special attention has been paid to accelerating the MIST computation to the point that reading the images off of disk is generally the slowest part.


Other comments:
When acquiring the images in MicroManger are you using the "Create Grid" tool within the "Stage Position List" window? Any position list the "Create Grid" tool generates should meet the regular grid requirement of MIST. The MicroManager "Create Grid" tool generates images names using row/column position names. The "Grid/Collection stitching" plugin type "Filename defined positions" should be the right one to use. If you are not using a grid of images then the "Grid/Collection stitching" plugin type "Unknown positions" might be able to stitch them.  


~Michael Majurski



-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of PEARSON Matthew
Sent: Friday, March 04, 2016 5:57 AM
To: [hidden email]
Subject: FIJI Stitching Plugins

Hi all,

I'm using a QImaging Micropublisher camera to acquire tiles of images in Micro-Manager then i'm stitching using the deprecated>Stitch directory with images (unknown configuration).  This is the only method that works for me with this camera.  Is there a newer equivalent method to this which should work?  My only issue with the old method assuming it remains deprecated is that its quite slow, computing the stitch can take many minutes even for just a few images <15.  I should say that i'm using a Mac and wondered if compute time would be slower?  I am using FIJI 64bit.

Thanks for the advice,

Matt

--
Matt Pearson
Core Microscopy Facility
MRC Human Genetics Unit
IGMM
University of Edinburgh
Carrington Crescent
EH4 2XU


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

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

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