Stitching together multiple images within a series of folders

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

Stitching together multiple images within a series of folders

nebenb
Hello,

I am trying to stitch together images of entire c.elegans worms to recreate
a 3d image of the entire worm.
Stitching them manually is easy but tedious, so I am trying to write an
ImageJ macro that will stitch them for me. All the plugins necessary are
available (pairwise stitching, run 8bit, etc) and I can get a macro to
stitch the files in a single folder if I provide the exact file names,
paths, etc within the macro. However, with my severely limited coding
knowledge, I cannot find a way to make this process generic.

Additionally, I want this macro to be propagative (not sure if this is the
right description) to the point where the user selects a 'mother' folder
with subfolders that each contain the images for a single worm (see below).
Then ImageJ would sample each 'daughter' folder, stitch those images
together, and save the result, before moving on to the next 'daughter'
folder.



MOTHER
  >DAUGHTER 1
    >worm 1_1
    >worm 1_2
    >worm 1_3
    >worm 1_4
    >worm 1_5
    >worm 1_6
    >worm 1_7
  >DAUGHTER 2
    >worm 2_1
    >worm 2_2
    >worm 2_3
    >worm 2_4
    >worm 2_5
  >DAUGHTER 3
    >worm 3_1
    >worm 3_2
    >worm 3_3
    >worm 3_4
    >worm 3_5
    >worm 3_6
etc etc


From what I have found on the web and my own trail and error I have pieced
together the following:


// This macro will takemutlipleple folders with individual
// images sequential images, sorted by sequence into folders,
// and stitch them together using the "PairwiseStitching" macro.
// The stitched images will be saved to the 'mother'
// directory with the name of the sequence-folder they were
// constructed from.


print("");
print("-- 3D Stitching --");
print("");
 mother = getDirectory("select mother directory");
print("MOTHER directory set as:");
print(mother);


// The MOTHER directory contains any number of daughter
// directories. The following sequence effectively primes
// ImageJ to be familiar with all the files within the
// 'Daughter' directories.


setBatchMode(true);
   count = 0;
   countFiles(mother);
   n = 0;
   processFiles(mother);
   print(count+" files processed");
   
   function countFiles(mother) {
      list = getFileList(mother);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              countFiles(""+mother+list[i]);
          else
              count++;
          print(list.length);
      }
  }

   function processFiles(mother) {
      list = getFileList(mother);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              processFiles(""+mother+list[i]);
          else {
             showProgress(n++, count);
             daughter = mother+list[i];
             print(daughter);
          }
      }
  }



// The first two images are stitched together to serve as a
// template for subsequent images to be stitched on to.
// This template is saved in the MOTHER directory with the
// file name of the DAUGHTER directory.


for (i=0; i<2; i++)
   initial(daughter, mother, file1, file2);

function initial(daughter, mother, file1, file2) {
   open(daughter + list[i]);
     run("8-bit");
   open(daughter + list[i+1]);
     run("8-bit");
   print("stitching 1+2");
     run("Pairwise stitching", "first_image=file1 second_image=file2
fusion_method=[Max. Intensity] check_peaks=5 compute_overlap
subpixel_accuracy x=0.0000 y=0.0000 z=0.0000
registration_channel_image_1=[Average all channels]
registration_channel_image_2=[Average all channels]");
   saveAs("Tiff", mother + daughter);
   if (i == 2)
     exit();
   }


// With a template available, imageJ can now propagate through
// The remaining files (i<list.length) to stitch them to the template


 stitch(daughter);

for (i = 2; i < list.length; i++)
   stitch(daughter, mother, file1, file2);

function stitch(daughter, mother, file1, file2); {
   open(daughter + file1);
     run("8-bit");
   open(mother + "daughter.tif");
   print("propagative stitching");
     run("Pairwise stitching", "first_image=file1 second_image=daughter.tif
fusion_method=[Max. Intensity] check_peaks=5 compute_overlap
subpixel_accuracy x=0.0000 y=0.0000 z=0.0000
registration_channel_image_1=[Average all channels]
registration_channel_image_2=[Average all channels]");
   saveAs("Tiff", mother + daughter)
   }


//** I'm not sure if this style of naming will work, i'm not sure how to
recall



Thank you all so much for your help, in advance. I look forward to all
suggestions and criticisms.


- Ben






--
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: Stitching together multiple images within a series of folders

wgiang
Have you tried using Grid/Collection Stitching?

https://imagej.net/Image_Stitching#Grid.2FCollection_Stitching



--
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: Stitching together multiple images within a series of folders

nebenb
I have, and it seems gets overwhelmed when i have more than 4 images for it
to put together. the worms are all oriented differently so I unfortunately
cannot set a grid for the images to be stitched on. Thanks for the
suggestion though!



--
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: Stitching together multiple images within a series of folders

Stephan.Preibisch@mdc-berlin.de
Hi,

You can define many types of grids before starting the stitching, and it does support C. elegans image stitching. This is one of the cases we originally developed it for :) We also wrote quite extensive documentation, did you read it on how to set up grids? It is pretty straight forward:

http://imagej.net/Image_Stitching … specifically here: http://imagej.net/Image_Stitching#Grid.2FCollection_Stitching - you can choose from many grid types, and a simple line can represented by some of them

We also just finished the BigStitcher which is a significant extension of the Stitching plugins. One feature that might specifically be interesting for you is that you can interactively try different grid types, so you can adjust sliders until the initialization is right by real-time display of the result. You can find general instructions here: http://imagej.net/BigStitcher … Again, specifically on the interactive grid initialization here: http://imagej.net/BigStitcher_manual_translation#Move_Tiles_To_Regular_Grid_…

At the end of the day, both are macro-scriptable, so once you know the basic workflow it is easy to automate.

All the best,
Stephan
---

Dr. Stephan Preibisch
Group Leader

Berlin Institute for Medical Systems Biology (BIMSB), Max Delbrück Center for Molecular Medicine (MDC)
Building 89, 1.08b
Robert-Rössle-Str. 10
13125 Berlin

email: [hidden email]<mailto:[hidden email]>
web: http://preibischlab.mdc-berlin.de
twitter: http://twitter.com/preibischs

On Apr 26, 2018, at 7:07 PM, nebenb <[hidden email]<mailto:[hidden email]>> wrote:

I have, and it seems gets overwhelmed when i have more than 4 images for it
to put together. the worms are all oriented differently so I unfortunately
cannot set a grid for the images to be stitched on. Thanks for the
suggestion though!



--
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: Stitching together multiple images within a series of folders

nebenb
Hello Dr. Preibisch,

Thank you for your response! The stitching plugins all work great when I'm
manually stitching worms, my troubles come more from the macro-writing in
that I'm not sure how write a macro to jump from folder to folder to stitch
worm after worm together.

I'm excited to try out your new BigStitcher! Now if only the ImageJ server
weren't down for maintenance..I'll give it a try on monday!

Vielen Dank!

Ben





--
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: Stitching together multiple images within a series of folders

ctrueden
In reply to this post by Stephan.Preibisch@mdc-berlin.de
Hi Ben,

> if only the ImageJ server weren't down for maintenance..I'll give it a
> try on monday!

Are you talking about http://imagej.nih.gov/ij? Everything there is
mirrored daily to http://imagej.net/index.html, so feel free to use that if
the NIH site is ever inaccessible. Why do you need the ImageJ 1.x website
to try out the BigStitcher?

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Fri, Apr 27, 2018 at 11:52 AM, nebenb <[hidden email]> wrote:

> Hello Dr. Preibisch,
>
> Thank you for your response! The stitching plugins all work great when I'm
> manually stitching worms, my troubles come more from the macro-writing in
> that I'm not sure how write a macro to jump from folder to folder to stitch
> worm after worm together.
>
> I'm excited to try out your new BigStitcher! Now if only the ImageJ server
> weren't down for maintenance..I'll give it a try on monday!
>
> Vielen Dank!
>
> Ben
>
>
>
>
>
> --
> 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: Stitching together multiple images within a series of folders

nebenb
Hi Curtis,

If I'm remembering correctly, ImageJ/FIJI weren't wanting to update because
they couldn't connect to a server? Regardless, I have the BigStitcher beta
now and its GREAT its so easy and straightforward and does a remarkable job
stitching my files together.

I'm still working on understanding how to script the stitching process to be
automated, since I can use the same stitch-settings for each group of files.
Ideally, FIJI would move from folder to folder stitching together the files
in each. I don't see a clear way to do this with BigStitcher but also have
close to zero coding experience and might be missing something obvious.


Dr. Preibisch,

Thank you again for the tip on BigStitcher, it works wonders! As i mentioned
above I'm trying to script the image stitching to be automated. Since the
worms i'm trying to stitch are arbitrarily oriented, I can't define a
tiling-orientation ahead of time, but the stitcher does a good job orienting
the tiles.


Thanks again for all the input,

Ben





--
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: Stitching together multiple images within a series of folders

Stephan.Preibisch@mdc-berlin.de
Hi Ben,

It’s great to hear that the BigStitcher works for you. Did you try to put all tiles on top of each other and maybe it’ll be able to figure it out itself using quite aggressive, high thresholds?

If that works, you can easily automate it using the ImageJ Macro Recording function with BigStitcher (Plugins > BigStitcher > Batch Processing & Plugins > Multiview Reconstruction > Batch Processing). It might also work well using interest point detection and Precise Descriptor-based registration in the Multiview Reconstruction instead of the correlation-based stitching. Depends on the marker in your C. elegans.

All the best,
Stephan
---

Dr. Stephan Preibisch
Group Leader

Berlin Institute for Medical Systems Biology (BIMSB), Max Delbrück Center for Molecular Medicine (MDC)
Building 89, 1.08b
Robert-Rössle-Str. 10
13125 Berlin

email: [hidden email]<mailto:[hidden email]>
web: http://preibischlab.mdc-berlin.de
twitter: http://twitter.com/preibischs

On May 4, 2018, at 10:38 PM, nebenb <[hidden email]<mailto:[hidden email]>> wrote:

Hi Curtis,

If I'm remembering correctly, ImageJ/FIJI weren't wanting to update because
they couldn't connect to a server? Regardless, I have the BigStitcher beta
now and its GREAT its so easy and straightforward and does a remarkable job
stitching my files together.

I'm still working on understanding how to script the stitching process to be
automated, since I can use the same stitch-settings for each group of files.
Ideally, FIJI would move from folder to folder stitching together the files
in each. I don't see a clear way to do this with BigStitcher but also have
close to zero coding experience and might be missing something obvious.


Dr. Preibisch,

Thank you again for the tip on BigStitcher, it works wonders! As i mentioned
above I'm trying to script the image stitching to be automated. Since the
worms i'm trying to stitch are arbitrarily oriented, I can't define a
tiling-orientation ahead of time, but the stitcher does a good job orienting
the tiles.


Thanks again for all the input,

Ben





--
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