batch processing imagecalculation add

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

batch processing imagecalculation add

HB
This post was updated on .
Hi there,

I am pretty new to ImageJ and not good at writing macros.
I've got 200 images in a folder and would like to add always two subsequent fotos up.
Imagecalculation and the add function seem to be suitable for it.
I've tried to write a little macro which loops through my files (they end with an increasing number) but I couldn't work it out so far.
I couldn't find a solution in the forum either.

Here is what I did so far


macro "Batch Measure" {
    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
//    setBatchMode(true);
    for (i=0; i<list.length; i++) {
// for (i=0; i<2; i++){  
      path = dir+list[i];
        showProgress(i, list.length);
        if (!endsWith(path,"/")) open(path);
        if (nImages>=100) {
        open (dir+list[i]);
        open (dir+list[i+1]);
        imageCalculator("Add create", dir+list[i],dir+list[i+1]);
//run("Image Calculator...", "image1=dir+list[i] operation=Add image2=dir+list[i=+1] create");

saveAs("BMP", "C:\\Documents and Settings\\Administrator\\Desktop\\list[i].bmp");
}

            close();
        }
    }

The macro seems to be doing something but it definitely doesn't save the result I would like to have.

I would be greatful for any  suggestion.

cheers,

herwig
Reply | Threaded
Open this post in threaded view
|

Re: batch processing imagecalculation add

Fernando Sales
Hi Herwig!

If i understood your problem, this should be solved with a simple plugin
using stacks. Using the command Open -> Import -> Image Sequence a stack
with all your images will be created.
If the images are in the correct order, you'll not have problems to process
them.
Just make a loop and call imageCalculation inside this.

Try something like this:
public class Test_ implements PlugIn {
  ImagePlus imps;

  public void run(String args) {
    IJ.run("Image Sequence..."); // Open Sequence and make stack

    // Load Stack
    this.imps = ij.WindowManager.getCurrentImage();
    ImageStack stack = imps.getImageStack();

    for (int k = 0; k < stack.getSize()-1; k++) {
      ImagePlus imp1 = new ImagePlus("Name ", stack.getProcessor(k + 1));
      ImagePlus imp2 = new ImagePlus("Name ", stack.getProcessor(k + 2));
     <Input your operations here...>
   }
...
}
}

You can find hints and examples in the tutorial available in:
http://www.imagingbook.com/index.php?id=102
I hope this can be helpful.

Good luck!
Fernando

On Sat, Feb 23, 2008 at 3:59 AM, herwig <[hidden email]> wrote:

> Hi there,
>
> I am pretty new to ImageJ and not good at writing macros.
> I've got 200 images in a folder and would like to add always two
> subsequent
> fotos up.
> Imagecalculation and the add function seem to be suitable for it.
> I've tried to write a little macro which loops through my files (they end
> with an increasing number) but I couldn't work it out so far.
> I couldn't find a solution in the forum either.
>
> I would be greatful for any  suggestion.
>
> cheers,
>
> herwig
> --
> View this message in context:
> http://www.nabble.com/batch-processing-imagecalculation-add-tp15641464p15641464.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>



--
**************************************************
Fernando José Ribeiro Sales
**************************************************
Email: [hidden email]
Tel: (11) 82020303
**************************************************
HB
Reply | Threaded
Open this post in threaded view
|

Re: batch processing imagecalculation add

HB
Hi Fernando,

Thanks a lot for your suggestion. I actually came up with a solution in the mean time which is a bit different:

macro "Batch Measure" {
    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
        count=1;
      setBatchMode(true);
      for (i=0; i<list.length; i+=2) {
       
        path = dir+list[i];
        showProgress(i, list.length);
        if (!endsWith(path,"/")) open(path);
        if (nImages>=1) {
        open (dir+list[i]);
        rename ("A");
        open (dir+list[i+1]);
        rename ("B");
        imageCalculator("Add create", "A","B");
//run("Image Calculator...", "image1=A operation=Add image2=B create");

saveAs("BMP", "C:\\Documents and Settings\\Result"+count+".bmp");
       
        count++;
close();



};
            close();
       
    }
}


Anyway, your solution looks nice and I might be using it for other applications (i am working a lot with stacks).

Thanks again,

Herwig  


Fernando Sales wrote
Hi Herwig!

If i understood your problem, this should be solved with a simple plugin
using stacks. Using the command Open -> Import -> Image Sequence a stack
with all your images will be created.
If the images are in the correct order, you'll not have problems to process
them.
Just make a loop and call imageCalculation inside this.

Try something like this:
public class Test_ implements PlugIn {
  ImagePlus imps;

  public void run(String args) {
    IJ.run("Image Sequence..."); // Open Sequence and make stack

    // Load Stack
    this.imps = ij.WindowManager.getCurrentImage();
    ImageStack stack = imps.getImageStack();

    for (int k = 0; k < stack.getSize()-1; k++) {
      ImagePlus imp1 = new ImagePlus("Name ", stack.getProcessor(k + 1));
      ImagePlus imp2 = new ImagePlus("Name ", stack.getProcessor(k + 2));
     <Input your operations here...>
   }
...
}
}

You can find hints and examples in the tutorial available in:
http://www.imagingbook.com/index.php?id=102
I hope this can be helpful.

Good luck!
Fernando

On Sat, Feb 23, 2008 at 3:59 AM, herwig <bachmannherwig@hotmail.com> wrote:

> Hi there,
>
> I am pretty new to ImageJ and not good at writing macros.
> I've got 200 images in a folder and would like to add always two
> subsequent
> fotos up.
> Imagecalculation and the add function seem to be suitable for it.
> I've tried to write a little macro which loops through my files (they end
> with an increasing number) but I couldn't work it out so far.
> I couldn't find a solution in the forum either.
>
> I would be greatful for any  suggestion.
>
> cheers,
>
> herwig
> --
> View this message in context:
> http://www.nabble.com/batch-processing-imagecalculation-add-tp15641464p15641464.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>



--
**************************************************
Fernando José Ribeiro Sales
**************************************************
Email: fernando.sales@gmail.com
Tel: (11) 82020303
**************************************************
Reply | Threaded
Open this post in threaded view
|

Re: batch processing imagecalculation add

Fernando Sales
Ok that's great!
Fernando

On Wed, Feb 27, 2008 at 4:53 PM, herwig <[hidden email]> wrote:

> Hi Fernando,
>
> Thanks a lot for your suggestion. I actually came up with a solution in
> the
> mean time which is a bit different:
>
> macro "Batch Measure" {
>        dir = getDirectory("Choose a Directory ");
>        list = getFileList(dir);
>        count=1;
>      setBatchMode(true);
>      for (i=0; i<list.length; i+=2) {
>
>        path = dir+list[i];
>        showProgress(i, list.length);
>        if (!endsWith(path,"/")) open(path);
>        if (nImages>=1) {
>        open (dir+list[i]);
>        rename ("A");
>        open (dir+list[i+1]);
>        rename ("B");
>        imageCalculator("Add create", "A","B");
> //run("Image Calculator...", "image1=A operation=Add image2=B create");
>
> saveAs("BMP", "C:\\Documents and Settings\\Result"+count+".bmp");
>
>        count++;
> close();
>
>
>
> };
>            close();
>
>    }
> }
>
>
> Anyway, your solution looks nice and I might be using it for other
> applications (i am working a lot with stacks).
>
> Thanks again,
>
> Herwig  =)
>
>
>
> Fernando Sales wrote:
> >
> > Hi Herwig!
> >
> > If i understood your problem, this should be solved with a simple plugin
> > using stacks. Using the command Open -> Import -> Image Sequence a stack
> > with all your images will be created.
> > If the images are in the correct order, you'll not have problems to
> > process
> > them.
> > Just make a loop and call imageCalculation inside this.
> >
> > Try something like this:
> > public class Test_ implements PlugIn {
> >   ImagePlus imps;
> >
> >   public void run(String args) {
> >     IJ.run("Image Sequence..."); // Open Sequence and make stack
> >
> >     // Load Stack
> >     this.imps = ij.WindowManager.getCurrentImage();
> >     ImageStack stack = imps.getImageStack();
> >
> >     for (int k = 0; k < stack.getSize()-1; k++) {
> >       ImagePlus imp1 = new ImagePlus("Name ", stack.getProcessor(k +
> 1));
> >       ImagePlus imp2 = new ImagePlus("Name ", stack.getProcessor(k +
> 2));
> >      <Input your operations here...>
> >    }
> > ...
> > }
> > }
> >
> > You can find hints and examples in the tutorial available in:
> > http://www.imagingbook.com/index.php?id=102
> > I hope this can be helpful.
> >
> > Good luck!
> > Fernando
> >
> > On Sat, Feb 23, 2008 at 3:59 AM, herwig <[hidden email]>
> > wrote:
> >
> >> Hi there,
> >>
> >> I am pretty new to ImageJ and not good at writing macros.
> >> I've got 200 images in a folder and would like to add always two
> >> subsequent
> >> fotos up.
> >> Imagecalculation and the add function seem to be suitable for it.
> >> I've tried to write a little macro which loops through my files (they
> end
> >> with an increasing number) but I couldn't work it out so far.
> >> I couldn't find a solution in the forum either.
> >>
> >> I would be greatful for any  suggestion.
> >>
> >> cheers,
> >>
> >> herwig
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/batch-processing-imagecalculation-add-tp15641464p15641464.html
> >> Sent from the ImageJ mailing list archive at Nabble.com.
> >>
> >
> >
> >
> > --
> > **************************************************
> > Fernando José Ribeiro Sales
> > **************************************************
> > Email: [hidden email]
> > Tel: (11) 82020303
> > **************************************************
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/batch-processing-imagecalculation-add-tp15641464p15721447.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>



--
**************************************************
Fernando José Ribeiro Sales
**************************************************
Email: [hidden email]
Tel: (11) 82020303
**************************************************