Posted by
Christophe CHAMOT on
URL: http://imagej.273.s1.nabble.com/batching-imageCalculator-please-NOT-spam-tp3702275p3702280.html
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/---------------------------------------------------------------------