batch focus stacker

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

batch focus stacker

dgrosen
Hi. New to the forum but not to imageJ. However, I need a little help
modifying this code to do the following.

I have a folder with multiple images. Each set has 5 images from different
focal distance. I need to:

- grab the first 5, open focus stacker and save as img1.
- grab the second set of 5, open focus stacker and save as img2....
.....and so forth

I found this code here but it does not work for me. It just stacks the first
5 pictures and nothing else

Thanks

dir = getDirectory("Choose image sequence folder");
   setBatchMode(true);
      count = 0;
      countFiles(dir);
      n = 0;
      processFiles(dir);
      print(count+" files processed");
 
function countFiles(dir) {
        list = getFileList(dir);
        for (i=0; i<list.length; i++) {
                if (endsWith(list[i], "/"))
                        countFiles(""+dir+list[i]);
                else
                        count++;
        }
}
 
function processFiles(dir) {
        list = getFileList(dir);
        for (i=0; i<list.length; i++) {
                if (endsWith(list[i], "/"))
                        processFiles(dir+list[i]);
                else {
                        showProgress(n++, count);
                        path = dir+list[i];
                        processFile(path);
                        i = list.length; // This line takes care that all
images in a directory are only analysed once
                }
        }
}
 
function processFile(path) {
        for (i=0; i<list.length; i++)
                open(path); // Removed a } what closed the function at this
point
           
        run("Images to Stack", "name=Stack title=[] use");
        run("Stack Focuser ", "enter=11");
        saveAs("Tiff", dir+"stack");
        run("Close All"); // Take care that all images are closed



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

Herbie
Good day,

you tell us that you are not new to ImageJ, therefore you should be able
to represent your images as a 4D stack (attached is an example file),
i.e. each set of 5 images is a z-stack (3D) and the fourth dimension
means the series of these z-stacks.

If you are able to arrange your images in this fashion (4D), you can use
the ImageJ-macro "Easy_Focus.ijm" that is based on the ImageJ-plugin
"Focus_LP" which does what you want.
<https://www.gluender.de/Miscellanea/MiscTexts/UtilitiesText.html#Gl-2019-3>
Please carefully read the ReadMe-document!

"Easy_Focus.ijm" allows for fast, high quality and one-click focus
analyses of focus series. Compared to similar approaches available for
ImageJ, "Easy Focus" is clearly faster. It provides superior results,
when compared to standard approaches such as those investigated by
Mir et al. (2014)
<https://cs.uwaterloo.ca/~vanbeek/Publications/spie2014.pdf>.

Good luck

Herbie

:::::::::::::::::::::::::::::::::::::
Am 24.12.19 um 18:32 schrieb dgrosen:

> Hi. New to the forum but not to imageJ. However, I need a little help
> modifying this code to do the following.
>
> I have a folder with multiple images. Each set has 5 images from different
> focal distance. I need to:
>
> - grab the first 5, open focus stacker and save as img1.
> - grab the second set of 5, open focus stacker and save as img2....
> .....and so forth
>
> I found this code here but it does not work for me. It just stacks the first
> 5 pictures and nothing else
>
> Thanks
>
> dir = getDirectory("Choose image sequence folder");
>     setBatchMode(true);
>        count = 0;
>        countFiles(dir);
>        n = 0;
>        processFiles(dir);
>        print(count+" files processed");
>    
> function countFiles(dir) {
>          list = getFileList(dir);
>          for (i=0; i<list.length; i++) {
>                  if (endsWith(list[i], "/"))
>                          countFiles(""+dir+list[i]);
>                  else
>                          count++;
>          }
> }
>    
> function processFiles(dir) {
>          list = getFileList(dir);
>          for (i=0; i<list.length; i++) {
>                  if (endsWith(list[i], "/"))
>                          processFiles(dir+list[i]);
>                  else {
>                          showProgress(n++, count);
>                          path = dir+list[i];
>                          processFile(path);
>                          i = list.length; // This line takes care that all
> images in a directory are only analysed once
>                  }
>          }
> }
>    
> function processFile(path) {
>          for (i=0; i<list.length; i++)
>                  open(path); // Removed a } what closed the function at this
> point
>              
>          run("Images to Stack", "name=Stack title=[] use");
>          run("Stack Focuser ", "enter=11");
>          saveAs("Tiff", dir+"stack");
>          run("Close All"); // Take care that all images are closed
>
>
>
> --
> 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

small_4D-stack_8bit.tif (2M) Download Attachment