Hi there,
for purpose of analysis, i decompose stacks into smaller volumes, where I then count objects. What I would like to do is randomize the analysis , so is there a function like random open a file in a folder or random selct an ROI ? Thank you very much, Fabrice. |
Hello fabrice,
Random is your function ;-) : random Returns a random number between 0 and 1. and round(n) your friend to make an integer. something like max = 50; a = round(random*max); Thomas Fabrice Senger a écrit : > Hi there, > > for purpose of analysis, i decompose stacks into smaller volumes, where > I then count objects. > What I would like to do is randomize the analysis , so is there a > function like random open a file in a folder or random selct an ROI ? > > Thank you very much, > > Fabrice. > > -- /**********************************************************/ Thomas Boudier, MCU Université Pierre et Marie Curie, IFR 83. Bat B 7ème étage, porte 709, Jussieu. Tel : 01 44 27 20 11 Fax : 01 44 27 22 91 /*******************************************************/ |
Here is a macro I wrote that randomly opens files in a folder of your
choosing. //ask the user what directory the files are in //only files can be in this directory or the macro will fail dir1 = getDirectory("Choose Source Directory "); list = getFileList(dir1); // make an ordered list ordered = newArray(list.length); for (i=0; i<list.length; i++) { ordered[i]=i; } // randomize the order randOrder = newArray(list.length); for (i=0; i<list.length; i++) { x=round(random*(list.length-1-i)); randOrder[i]=ordered[x]; removeX(ordered, x); } //open the files for (i=0; i<list.length; i++) { showProgress(i+1, list.length); open(dir1+list[(randOrder[i])]); rename("Random"+i); } function removeX (a, x){ tmp = Array.copy(a); for (i=0; i<x; i++){ a[i]=tmp[i]; } for (i=x+1; i<a.length; i++){ a[i-1]=tmp[i]; } } function printArray (b) { bob = ""; for (k=0; k<b.length; k++){ bob = bob+" "+b[k]; } print(bob); } I hope that it's useful to you. -Will Ashby On 7/23/09 9:54 AM, "Thomas Boudier" <[hidden email]> wrote: > Hello fabrice, > > Random is your function ;-) : > > random > Returns a random number between 0 and 1. > > and round(n) your friend to make an integer. > > something like > > max = 50; > a = round(random*max); > > Thomas > > > Fabrice Senger a écrit : >> Hi there, >> >> for purpose of analysis, i decompose stacks into smaller volumes, where >> I then count objects. >> What I would like to do is randomize the analysis , so is there a >> function like random open a file in a folder or random selct an ROI ? >> >> Thank you very much, >> >> Fabrice. >> >> |
On Thursday 23 July 2009 09:13:58 Will Ashby wrote:
> Here is a macro I wrote that randomly opens files in a folder of your > choosing. Rather than using the removeX routine which has 2 loops and an array copy, it would be easier and faster to just select an item from the list randomly, swap the last list item with the randomly chosen one, and reduce the list by 1 select another random item from the new list, etc That should be quicker if you have a large number of files. Cheers G. |
Thank you for the pointer. The result is much shorter and quicker.
//ask the user what directory the files are in dir1 = getDirectory("Choose Source Directory "); list = getFileList(dir1); // randomly open the files for (i=0; i<list.length; i++) { showProgress(i+1, list.length); end=list.length-1-i; x=round(random*end); open(dir1+list[x]); rename("Random"+i); list[x]=list[end]; } On 7/24/09 3:20 AM, "Gabriel Landini" <[hidden email]> wrote: > On Thursday 23 July 2009 09:13:58 Will Ashby wrote: >> Here is a macro I wrote that randomly opens files in a folder of your >> choosing. > > Rather than using the removeX routine which has 2 loops and an array copy, it > would be easier and faster to just > select an item from the list randomly, > swap the last list item with the randomly chosen one, and > reduce the list by 1 > select another random item from the new list, etc > > That should be quicker if you have a large number of files. > > Cheers > > G. |
Free forum by Nabble | Edit this page |