open next

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

open next

AJBell
Hello,

I want a macro to open an image, perfrom an operation, save it to another
location, and open the next image in the original folder. Is this possible
without the user having to specify the source folder each time?

This is where i am at so far:


dir = getDirectory("Choose Destination Directory ");
open();
name = dir+getTitle();
run("Rolling Ball Background", "rolling=50");
save(name+".tif");
run("Open Next");

This macro only opens the next file in the destination folder. How can I
specify to open the next file in the source folder?

Any suggestions warmly welcomed!

Regards,

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: open next

lechristophe
Get the user to select both source and destination directories at the beginning
get the names of all files in the directory using getfilelist and
store them in an array
then loop on this array using indexes and names stored, using open()
and save() with full path names on the source and destination
directory respectively
it can be good to enclose the loop in a condition testing the image
file extension (.tif or what you use), to avoid trying to open
non-image files if there are any in the source directory.

Christophe

On Thu, Oct 15, 2009 at 12:08 PM, Andrew Bell <[hidden email]> wrote:

> Hello,
>
> I want a macro to open an image, perfrom an operation, save it to another
> location, and open the next image in the original folder. Is this possible
> without the user having to specify the source folder each time?
>
> This is where i am at so far:
>
>
> dir = getDirectory("Choose Destination Directory ");
> open();
> name = dir+getTitle();
> run("Rolling Ball Background", "rolling=50");
> save(name+".tif");
> run("Open Next");
>
> This macro only opens the next file in the destination folder. How can I
> specify to open the next file in the source folder?
>
> Any suggestions warmly welcomed!
>
> Regards,
>
> Andrew
>
Reply | Threaded
Open this post in threaded view
|

Re: open next

lechristophe
something like

sdir = getDirectory("Choose Source Directory ");
ddir = getDirectory("Choose Destination Directory ");
names= getFileList(sdir);
for (i=0; i<names.length, i++) {
        open(sdir+names[i]);
        run("Rolling Ball Background", "rolling=50");
        save(ddir+names[i]);
}

as a side note, if it is just for a simple operation such as backround
substraction, the easiest way is to open all your images from source
directory as a stack, apply the operation on the whole stack, and then
save them as an image sequence using "Use labels as file names" option
in your destination directory, so you will get the modified images in
your destination directory, with the original names, no macro required
(as long as the memory allow you to open all your directory images as
one stack).

Christophe

On Thu, Oct 15, 2009 at 12:23 PM, Christophe Leterrier
<[hidden email]> wrote:

> Get the user to select both source and destination directories at the beginning
> get the names of all files in the directory using getfilelist and
> store them in an array
> then loop on this array using indexes and names stored, using open()
> and save() with full path names on the source and destination
> directory respectively
> it can be good to enclose the loop in a condition testing the image
> file extension (.tif or what you use), to avoid trying to open
> non-image files if there are any in the source directory.
>
> Christophe
>
> On Thu, Oct 15, 2009 at 12:08 PM, Andrew Bell <[hidden email]> wrote:
>> Hello,
>>
>> I want a macro to open an image, perfrom an operation, save it to another
>> location, and open the next image in the original folder. Is this possible
>> without the user having to specify the source folder each time?
>>
>> This is where i am at so far:
>>
>>
>> dir = getDirectory("Choose Destination Directory ");
>> open();
>> name = dir+getTitle();
>> run("Rolling Ball Background", "rolling=50");
>> save(name+".tif");
>> run("Open Next");
>>
>> This macro only opens the next file in the destination folder. How can I
>> specify to open the next file in the source folder?
>>
>> Any suggestions warmly welcomed!
>>
>> Regards,
>>
>> Andrew
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: open next

Gabriel Landini
On Thursday 15 October 2009  11:46:31 Christophe Leterrier wrote:

> something like
>
> sdir = getDirectory("Choose Source Directory ");
> ddir = getDirectory("Choose Destination Directory ");
> names= getFileList(sdir);
> for (i=0; i<names.length, i++) {
> open(sdir+names[i]);
> run("Rolling Ball Background", "rolling=50");
> save(ddir+names[i]);
> }

One can also use new "Process>Batch" option which seems very convenient.

G.
Reply | Threaded
Open this post in threaded view
|

Re: open next

Wayne Rasband
In reply to this post by AJBell
 > Hello,
 >
 > I want a macro to open an image, perfrom an operation, save
 > it to another location, and open the next image in the
 > original folder. Is this possible without the user having
 > to specify the source folder each time?
 >
 > This is where i am at so far:
 >
 >
 > dir = getDirectory("Choose Destination Directory ");
 > open();
 > name = dir+getTitle();
 > run("Rolling Ball Background", "rolling=50");
 > save(name+".tif");
 > run("Open Next");
 >
 > This macro only opens the next file in the destination
 > folder. How can I specify to open the next file in the
 > source folder?

The easy way to run a macro on all the images in a folder is to use the
new Process>Batch>Macro command, available in ImageJ 1.43f or later.

   1. Specify the source folder in "Input"
   2. Specify the output folder in "Output"
   3. Select the output file format
   4. Paste the macro into the text area
   5. Press "Test" to test the macro on the first image in the input
folder
   6. Press "Process" to run the macro on all the images in the input
folder

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: open next

ctrueden
In reply to this post by AJBell
Hi Andrew,

Here is an example macro that does something similar to what you ask:

https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/utils/macros/recursiveTiffConvert.txt

This one batch converts an input directory of files in some format into
TIFFs in an output directory, but you could change the logic per-file to do
whatever you want.

-Curtis

On Thu, Oct 15, 2009 at 5:08 AM, Andrew Bell <[hidden email]> wrote:

> Hello,
>
> I want a macro to open an image, perfrom an operation, save it to another
> location, and open the next image in the original folder. Is this possible
> without the user having to specify the source folder each time?
>
> This is where i am at so far:
>
>
> dir = getDirectory("Choose Destination Directory ");
> open();
> name = dir+getTitle();
> run("Rolling Ball Background", "rolling=50");
> save(name+".tif");
> run("Open Next");
>
> This macro only opens the next file in the destination folder. How can I
> specify to open the next file in the source folder?
>
> Any suggestions warmly welcomed!
>
> Regards,
>
> Andrew
>