setting up multiple arrays using sequential name.

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

setting up multiple arrays using sequential name.

grimper
Hello,

I am trying to write a macro to analysis multiple image stacks. For each stack, the analyzed result would put into an array respectively. As I have n stacks, I would need to define n arrays.
Ex:
a1 = newArray(nSlices);
a2 = newArray(nSlices);
.
.
.
.
an = newArray(nSlices);

Could I use "for loop" to do this job? Like:
for (i=1; i<nImages;i++){
     "a"+i = newArray(nSlices);
}

I tried this but it seems to me that by concatenating a string and a variable couldn't be assigned as the name of array.

Thanks a lot,


_-3
Reply | Threaded
Open this post in threaded view
|

Re: setting up multiple arrays using sequential name.

_-3
Hi,
unfortunately it is not possible to create a more dimensional array but  
you can use a second  image to store your data.

Greetings.


grimper schrieb:

> Hello,
>
> I am trying to write a macro to analysis multiple image stacks. For each
> stack, the analyzed result would put into an array respectively. As I have n
> stacks, I would need to define n arrays.
> Ex:
> a1 = newArray(nSlices);
> a2 = newArray(nSlices);
> .
> .
> .
> .
> an = newArray(nSlices);
>
> Could I use "for loop" to do this job? Like:
> for (i=1; i<nImages;i++){
>      "a"+i = newArray(nSlices);
> }
>
> I tried this but it seems to me that by concatenating a string and a
> variable couldn't be assigned as the name of array.
>
> Thanks a lot,
>
>
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: setting up multiple arrays using sequential name.

grimper
Did you mean using setPixel() and getPixel() to put my data into the new image? But it seems to me that the pixel can only contain integer as value. What if my data contains  decimal places upto 3 or 4?

Thanks a lot for your reply,




_ wrote
Hi,
unfortunately it is not possible to create a more dimensional array but  
you can use a second  image to store your data.

Greetings.


grimper schrieb:
> Hello,
>
> I am trying to write a macro to analysis multiple image stacks. For each
> stack, the analyzed result would put into an array respectively. As I have n
> stacks, I would need to define n arrays.
> Ex:
> a1 = newArray(nSlices);
> a2 = newArray(nSlices);
> .
> .
> .
> .
> an = newArray(nSlices);
>
> Could I use "for loop" to do this job? Like:
> for (i=1; i<nImages;i++){
>      "a"+i = newArray(nSlices);
> }
>
> I tried this but it seems to me that by concatenating a string and a
> variable couldn't be assigned as the name of array.
>
> Thanks a lot,
>
>
>
>  
_-3
Reply | Threaded
Open this post in threaded view
|

Re: setting up multiple arrays using sequential name.

_-3
Yes  I did.
You can use a RGB image (3*255) cahnnel or a 32-Bit image (
"plain"-decimal ).
If using an RGB image you can multiply your values (*10 or *100 .. ) to
draw the data.

Maybe its also possible to store your data in a table (print .. ).

Greetings


grimper schrieb:

> Did you mean using setPixel() and getPixel() to put my data into the new
> image? But it seems to me that the pixel can only contain integer as value.
> What if my data contains  decimal places upto 3 or 4?
>
> Thanks a lot for your reply,
>
>
>
>
>
> _ wrote:
>  
>> Hi,
>> unfortunately it is not possible to create a more dimensional array but  
>> you can use a second  image to store your data.
>>
>> Greetings.
>>
>>
>> grimper schrieb:
>>    
>>> Hello,
>>>
>>> I am trying to write a macro to analysis multiple image stacks. For each
>>> stack, the analyzed result would put into an array respectively. As I
>>> have n
>>> stacks, I would need to define n arrays.
>>> Ex:
>>> a1 = newArray(nSlices);
>>> a2 = newArray(nSlices);
>>> .
>>> .
>>> .
>>> .
>>> an = newArray(nSlices);
>>>
>>> Could I use "for loop" to do this job? Like:
>>> for (i=1; i<nImages;i++){
>>>      "a"+i = newArray(nSlices);
>>> }
>>>
>>> I tried this but it seems to me that by concatenating a string and a
>>> variable couldn't be assigned as the name of array.
>>>
>>> Thanks a lot,
>>>
>>>
>>>
>>>  
>>>      
>>    
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: setting up multiple arrays using sequential name.

Gabriel Landini
In reply to this post by grimper
On Sunday 08 February 2009, grimper wrote:
> >> I am trying to write a macro to analysis multiple image stacks. For each
> >> stack, the analyzed result would put into an array respectively. As I
> >> have n stacks, I would need to define n arrays.

The solutions to the lack of mutlidimensional arrays in the macro language are
(in order of complexity):

1. print() or write() your results as you get them, so you do not need to
store them, then save the data and process it outside IJ
2. store everything in a one dimensional array (like java does with getpixels)
3. use javascript (or other script in Fiji) instead if the macro language
http://pacific.mpi-cbg.de/wiki/index.php/Javascript_Scripting
4. use java instead of the macro language

Cheers,

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

Re: setting up multiple arrays using sequential name.

Wolfgang Schechinger
In reply to this post by _-3
Hi,

is there something in ImageJ that corresponds to Matlab's or Octave's eval() command in order to assemble commands during runtime from changing parameters?

If not, you might consider to process your data externally with an application like Octave that has been designed for matrices and re-import it into IJ when the numbercrunching has been done.

Octave may be foud at http://www.ocatve.org

Best reagrds,
Wo

> >>> a1 = newArray(nSlices);
> >>> a2 = newArray(nSlices);
> >>> .
> >>> .
> >>> .
> >>> .
> >>> an = newArray(nSlices);
> >>>
> >>> Could I use "for loop" to do this job? Like:
> >>> for (i=1; i<nImages;i++){
> >>>      "a"+i = newArray(nSlices);
> >>> }
> >>>
> >>> I tried this but it seems to me that by concatenating a string and a
> >>> variable couldn't be assigned as the name of array.
> >>>
> >>> Thanks a lot,

--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
Reply | Threaded
Open this post in threaded view
|

Re: setting up multiple arrays using sequential name.

Wayne Rasband
In reply to this post by grimper
> Hello,
>
> I am trying to write a macro to analysis multiple image stacks. For  
> each
> stack, the analyzed result would put into an array respectively. As  
> I have n
> stacks, I would need to define n arrays.
> Ex:
> a1 = newArray(nSlices);
> a2 = newArray(nSlices);
> .
> .
> .
> .
> an = newArray(nSlices);
>
> Could I use "for loop" to do this job? Like:
> for (i=1; i<nImages;i++){
>      "a"+i = newArray(nSlices);
> }
>
> I tried this but it seems to me that by concatenating a string and a
> variable couldn't be assigned as the name of array.

You can use the Results table as if it were a 2D array. Here is an  
example that creates 10x100 results table and saves it in the user's  
home directory as a spreadsheet-compatible text file.

       // generate 10x100 results table
       columns = 10;
       rows = 100;
       run("Clear Results");
       for (n=1; n<=columns; n++) {
           for (i=0; i<rows; i++) {
               setResult("a"+n, i, n+i/100);
           }
       }
       updateResults();

       // randomly access results
       for (i=0; i<10; i++) {
           n = round(random*columns+1);
           index = round(random*rows);
           value = getResult("a"+n, index);
           print("n="+n+", index="+index+", value="+value);
       }

       // save in users home directory
       saveAs("Measurements", getDirectory("home")+"Results.xls");

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

Re: setting up multiple arrays using sequential name.

dscho
In reply to this post by Wolfgang Schechinger
Hi,

On Sun, 8 Feb 2009, Wolfgang Schechinger wrote:

> is there something in ImageJ that corresponds to Matlab's or Octave's
> eval() command in order to assemble commands during runtime from
> changing parameters?

Umm, writing macros is all about that?

> If not, you might consider to process your data externally with an
> application like Octave that has been designed for matrices and
> re-import it into IJ when the numbercrunching has been done.

In the light of having the option to use Java (or scripting languages such
as Jython, JRuby, Clojure, Javascript or BeanShell, where you do not even
need to compile your script) with a wide range of third-party software to
do number crunching, I find it particularly cumbersome to convert your
data to a format suitable for Octave (or R), call an external program, and
then convert your data back.

Besides, ImageJ is platform independent due to Java being platform
independent, and requiring the user to have a certain program installed
limits the options.

Ciao,
Dscho