Login  Register

Re: batching imageCalculator - [ i ] unexpected

Posted by Greg Joss on Jul 06, 2006; 1:28am
URL: http://imagej.273.s1.nabble.com/batching-imageCalculator-please-NOT-spam-tp3702275p3702279.html

Gianpaolo,
Christophe CHAMOT's post arrived in my mailbox after I had posted my version
so that I didn't have his post to comment on at the time.

There are a couple of critical differences between my version (copied at end below) and Christophe's:
1. in my version, only one getFileList() instead of two.
There is no guarantee that getFileList's will be in same order for different directories;
even though same filenames are present, order can be different depending on creation sequence, OS, sequence options etc.
 Christophe's relied on listA[i],listB[i] being enumerated in same sequence.
Mine did not assume this but fetches B image to correspond to each A
by using same filename fs[i] with different directory dirB

2. to avoid problems of duplicate names and IJ's renaming on open,
imageCalculator("Subtract create",a,b);
uses numeric imageID instead of filenames.

My reference to "checking for mismatch errors" was meant to indicate that the macro could be elaborated to check that matching files exist (not that you should visually check).

I will be surprised if, on retesting, you  can confirm "Also the macro written by Greg Joss give the same results."
The filename matching is explicit in my code.  If matching files are not present, open will fail with "not found" message.

I have in fact tested it with the following two statements appended

fsb=getFileList(dirB);
for(i=0;i<fs.length;i++)print(fs[i],fsb[i]);<~!B*+R^&>

which confirm that the macro works correctly even where filelists are in different sequence.

Greg Joss

>>> [hidden email]  >>>
Thank you, seems to be what I need

but...
running the macro I expect (1A-1B); (2A-2B); (3A-3B),
and I obtain:  (1A-3B);  (2A-1B); (3A-2B)
it means that the first image "A" is well-processed, but there is a index-misunderstanding concerning the image "B". I've tried to checking the [i]-stuff, but my java is poor...

Also the macro written by Greg Joss give the same results.
(I've checked my images: no accidental exchange)
Brainstorming please!

Gianpaolo Rando


----- Messaggio Originale -----

> You can try something like this macro:
>
> -------Snip-----------
>
> dirA = getDirectory("Choose source A Directory ");
> listA = getFileList(dirA);
> //print(""+dirA+listA[i]);
> dirB = getDirectory("Choose source B Directory ");
> listB = getFileList(dirB);
> //print(""+dirB+listB[i]);
> count=1;
> for (i=0; i<listA.length; i++) {
> open(""+dirA+listA[i]);
> rename("A");
> open(""+dirB+listB[i]);
> rename("B");
> imageCalculator("Subtract create", "A","B");
> saveAs("Tiff", "/home/kriss/Desktop/C/Result"+count+".tif");
> count++;
> close();
> close();
> close();
> }
>
> -------Snap-----------

> Christophe CHAMOT

> -----------------------------------------------------------------
> gianpaolo rando a écrit :
> I've two directories:
> both containing a lot of image files with the same title (1,
> 2, 3).
> >> I need to write a macro that subtract image B/1 to A/1, B/2
> to
> >> A/2, B/3 to A/3...
> >>
> >> some suggestions?
> >>
> >> Gianpaolo Rando
> >> University of Milan


>>> [hidden email]  >>>
without checking for mismatch errors etc
(see File.exists(path)
<http://rsb.info.nih.gov/ij/developer/macro/functions.html>)<~!B*+R^&><~!B*+R^&>//_____________________________________<~!B*+R^&>dirA = getDirectory("Choose SourceA Directory ");
dirB = getDirectory("Choose SourceB Directory ");
fs=getFileList(dirA);
for(i=0;i<fs.length;i++){<~!B*+R^&>    open(dirA+File.separator+fs[i]);
    a=getImageID;
    open(dirB+File.separator+fs[i]);
    b=getImageID;
    imageCalculator("Subtract create",a,b);
}
//_____________________________________