batching imageCalculator (please NOT spam)

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

batching imageCalculator (please NOT spam)

gianpaolo rando
I don't know why the server consider my message as spam...
anycase...

> Hi everybody, this is my first post.
>
> I've two directories:
>       dirA = getDirectory("Choose
> SourceA Directory ");
>       dirB = getDirectory("Choose
> SourceB Directory ");
> 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
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator (please NOT spam)

Christophe CHAMOT
gianpaolo rando a écrit :

> I don't know why the server consider my message as spam...
> anycase...
>  
>> Hi everybody, this is my first post.
>>
>> I've two directories:
>>       dirA = getDirectory("Choose
>> SourceA Directory ");
>>       dirB = getDirectory("Choose
>> SourceB Directory ");
>> 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
>>    
>
>  
Hi listers,

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

Hope it helps ...

--
Christophe CHAMOT
---------------------------------------------------------------------
Plate-Forme  de Recherche IFR117
"Imageries des Processus Dynamiques
en Biologie  Cellulaire et Biologie du Développement "
Institut Jacques Monod, CNRS,  Universités Paris 6 et 7
2, place Jussieu - Tour 43
75251 Paris cedex  05
Tel: 01 44 27 47 56
fax: 01 44 27 98 57
http://www.ijm.jussieu.fr/
---------------------------------------------------------------------  
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator (please NOT spam)

Greg Joss
In reply to this post by gianpaolo rando
without checking for mismatch errors etc
(see File.exists(path)
<http://rsb.info.nih.gov/ij/developer/macro/functions.html>)

//_____________________________________
dirA = getDirectory("Choose SourceA Directory ");
dirB = getDirectory("Choose SourceB Directory ");
fs=getFileList(dirA);
for(i=0;i<fs.length;i++){
        open(dirA+File.separator+fs[i]);
        a=getImageID;
        open(dirB+File.separator+fs[i]);
        b=getImageID;
        imageCalculator("Subtract create",a,b);
}
//_____________________________________  


>>> [hidden email]  >>>
I don't know why the server consider my message as spam...
anycase...

> Hi everybody, this is my first post.
>
> I've two directories:
>       dirA = getDirectory("Choose
> SourceA Directory ");
>       dirB = getDirectory("Choose
> SourceB Directory ");
> 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
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator - [ i ] unexpected

gianpaolo rando
In reply to this post by Christophe CHAMOT
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
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator - [ i ] unexpected

Greg Joss
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);
}
//_____________________________________  
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator - [ i ] unexpected

Christophe CHAMOT
Greg Joss a écrit :

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

Joss is absolutely right. I was tired yesterday and more today (soccer
world cup, hem, hem, ...).

Point 1. With Joss's code, no need to care about other things than
filenames.
Point 2. Joss is right again. IDs are safer because unique during an
ImageJ session. Even if I've no problem with renaming...

For Joss : Why do you need a File.separator statement ? A path+filename
concatenation is sufficient (for unix at least).

One more question for Gianpaolo: You wrote you have the right order for
A (1,2,3) and not for B (3,1,2), what about the following images ? Is it
A4-B4, A5-B5, .... ?


So, if your source directories contain the same number of images, Joss's
code will work, like that :

dirA = getDirectory("Choose SourceA Directory ");
dirB = getDirectory("Choose SourceB Directory ");
dirC =getDirectory("Choose Result Directory ");//because I'm lazy
res_name=getString("Result name", "Result");
fs=getFileList(dirA);
for(i=0;i<fs.length;i++){
   open(dirA+fs[i]);
   a=getImageID;
   open(dirB+fs[i]);
   b=getImageID;
   imageCalculator("Subtract create",a,b);
   saveAs("Tiff", dirC+res_name+i);
   close();
   close();
   close();
}


Bye

--
Christophe CHAMOT
---------------------------------------------------------------------
Plate-Forme  de Recherche IFR117
"Imageries des Processus Dynamiques
en Biologie  Cellulaire et Biologie du Développement "
Institut Jacques Monod, CNRS,  Universités Paris 6 et 7
2, place Jussieu - Tour 43
75251 Paris cedex  05
Tel: 01 44 27 47 56
fax: 01 44 27 98 57
http://www.ijm.jussieu.fr/
---------------------------------------------------------------------  
Reply | Threaded
Open this post in threaded view
|

Re: batching imageCalculator - [ i ] unexpected

Greg Joss
In reply to this post by gianpaolo rando
Christophe,
You are quite right to query the File.separator.
getDirectory(""); already supplies trailing  File.separator, even on Windows.

Fortuneately for me, it was treated as redundant (by Windows XP or IJ?) and still worked

Greg

PS who won the soccer?
:-)

>>> [hidden email]  >>>
Greg Joss a écrit :
>...snip....
Joss is absolutely right. I was tired yesterday and more today (soccer
world cup, hem, hem, ...).

.........

For Joss : Why do you need a File.separator statement ? A path+filename
concatenation is sufficient (for unix at least).
..........
--
Christophe CHAMOT
---------------------------------------------------------------------
Plate-Forme  de Recherche IFR117
"Imageries des Processus Dynamiques
en Biologie  Cellulaire et Biologie du Développement "
Institut Jacques Monod, CNRS,  Universités Paris 6 et 7
2, place Jussieu - Tour 43
75251 Paris cedex  05
Tel: 01 44 27 47 56
fax: 01 44 27 98 57
http://www.ijm.jussieu.fr/
---------------------------------------------------------------------