How to define a 3D array?

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

How to define a 3D array?

Sasmita Rath
Dear ImageJ Group,
Could you please tell me how to define a 3 dimensional array in a macro.
I 'm using the syntax :
int name[][][]=new int [10][10][10];


but it's not working in ImageJ.

Thank you.
Sasmita
Reply | Threaded
Open this post in threaded view
|

Re: How to define a 3D array?

Michael Doube
Sasmita:

One (huckery) way that I've done this in a macro is to do something like:

arrayX = newArray(10);
arrayY = newArray(10);
arrayZ = newArray(10);

Which will give you 3 arrays with 10 empty elements that you can then
retrieve using the same index:

This snippet will list all your 3 dimensional positions.
for (i = 0; i <10; i++){
    print(arrayX[i], arrayY[i], arrayZ[i]);
}

So long as you keep your array indices synchronised your 3 arrays will
represent 3D positions.

Alternatives to 3D arrays suggested on the IJ website are to use
setPixel() and getPixel() in a stack that's big enough to hold your
data, or make a 1D array and do your own indexing:
http://rsb.info.nih.gov/ij/developer/macro/functions.html#N

You also don't have to declare your array as type int, the language will
do that for you.

Mike

Sasmita Rath wrote:

> Dear ImageJ Group,
> Could you please tell me how to define a 3 dimensional array in a macro.
> I 'm using the syntax :
> int name[][][]=new int [10][10][10];
>
>
> but it's not working in ImageJ.
>
> Thank you.
> Sasmita
>  
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: How to define a 3D array?

Joachim Wesner
Mike,

what you suggest is not the same! Your arrays have a total of 30 elements,
the one that Sasmitha needs has 1000 elements!

Sasmitha,

You can´t really, there are not even 2D arrays in a macro, you needs to
create a single array of 1000 elements and use
explicit indexing, i.e, instead of

a[i][j][k]  (i, j, k, = 0..9)

use

a[i*100+j*10+k]

JW

ImageJ Interest Group <[hidden email]> schrieb am 17.06.2008 10:47:36:

> Sasmita:
>
> One (huckery) way that I've done this in a macro is to do something like:
>
> arrayX = newArray(10);
> arrayY = newArray(10);
> arrayZ = newArray(10);
>
> Which will give you 3 arrays with 10 empty elements that you can then
> retrieve using the same index:
>
> This snippet will list all your 3 dimensional positions.
> for (i = 0; i <10; i++){
>     print(arrayX[i], arrayY[i], arrayZ[i]);
> }
>
> So long as you keep your array indices synchronised your 3 arrays will
> represent 3D positions.
>
> Alternatives to 3D arrays suggested on the IJ website are to use
> setPixel() and getPixel() in a stack that's big enough to hold your
> data, or make a 1D array and do your own indexing:
> http://rsb.info.nih.gov/ij/developer/macro/functions.html#N
>
> You also don't have to declare your array as type int, the language will
> do that for you.
>
> Mike
>
> Sasmita Rath wrote:
> > Dear ImageJ Group,
> > Could you please tell me how to define a 3 dimensional array in a
macro.
> > I 'm using the syntax :
> > int name[][][]=new int [10][10][10];
> >
> >
> > but it's not working in ImageJ.
> >
> > Thank you.
> > Sasmita
> >


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: How to define a 3D array?

Michael Doube
Joachim,

I stand corrected...

My intent was to store 10 3D positions, which is a misunderstanding of
the problem: storing an arbitrary number of 3D positions is not the same
as storing the values held at a defined number of 3D positions!

Mike


Joachim Wesner wrote:

> Mike,
>
> what you suggest is not the same! Your arrays have a total of 30 elements,
> the one that Sasmitha needs has 1000 elements!
>
> Sasmitha,
>
> You can´t really, there are not even 2D arrays in a macro, you needs to
> create a single array of 1000 elements and use
> explicit indexing, i.e, instead of
>
> a[i][j][k]  (i, j, k, = 0..9)
>
> use
>
> a[i*100+j*10+k]
>
> JW
>
> ImageJ Interest Group <[hidden email]> schrieb am 17.06.2008 10:47:36:
>
>  
>> Sasmita:
>>
>> One (huckery) way that I've done this in a macro is to do something like:
>>
>> arrayX = newArray(10);
>> arrayY = newArray(10);
>> arrayZ = newArray(10);
>>
>> Which will give you 3 arrays with 10 empty elements that you can then
>> retrieve using the same index:
>>
>> This snippet will list all your 3 dimensional positions.
>> for (i = 0; i <10; i++){
>>     print(arrayX[i], arrayY[i], arrayZ[i]);
>> }
>>
>> So long as you keep your array indices synchronised your 3 arrays will
>> represent 3D positions.
>>
>> Alternatives to 3D arrays suggested on the IJ website are to use
>> setPixel() and getPixel() in a stack that's big enough to hold your
>> data, or make a 1D array and do your own indexing:
>> http://rsb.info.nih.gov/ij/developer/macro/functions.html#N
>>
>> You also don't have to declare your array as type int, the language will
>> do that for you.
>>
>> Mike
>>
>> Sasmita Rath wrote:
>>    
>>> Dear ImageJ Group,
>>> Could you please tell me how to define a 3 dimensional array in a
>>>      
> macro.
>  
>>> I 'm using the syntax :
>>> int name[][][]=new int [10][10][10];
>>>
>>>
>>> but it's not working in ImageJ.
>>>
>>> Thank you.
>>> Sasmita
>>>
>>>      
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
>  

--
Michael Doube  BPhil BVSc PhD MRCVS
Research Associate
Department of Bioengineering
Imperial College London
South Kensington Campus
London  SW7 2AZ
United Kingdom
Reply | Threaded
Open this post in threaded view
|

Re: Antwort: Re: How to define a 3D array?

Sasmita Rath
In reply to this post by Joachim Wesner
Thank you guys for your inputs.Now I understand I need to work with an array.This is my real Problem........If you could look into it.

Where k=slices,i=height,j=width.I wrote the macro as follows:

Z=0;
for(k=0;k<10;k++) {

run("Text Image... ", "open=[C:\\Documents and Settings\\...\\Desktop\\20080423-152704--58C-255x-985ms\\" +1000+k + ".dat]");
for(i=0;i<10;i++){
                for(j=0; j<10; j++) {
                                   
                                y=getPixel(i,j);
                                a[z]=y;
                                print(a[z]);
                                z=z+1; }
                                        }
                                close();
                                        }

When I run the macro it gives me the following erroe message.

java.lang.OutOfMemoryError: Java heap space
        at ij.macro.Functions.newArray(Functions.java:1146)
        at ij.macro.Functions.getArrayFunction(Functions.java:250)
        at ij.macro.Interpreter.doArrayAssignment(Interpreter.java:819)
        at ij.macro.Interpreter.doAssignment(Interpreter.java:627)
        at ij.macro.Interpreter.doStatement(Interpreter.java:214)
        at ij.macro.Interpreter.doStatements(Interpreter.java:195)
        at ij.macro.Interpreter.run(Interpreter.java:99)
        at ij.macro.Interpreter.run(Interpreter.java:65)
        at ij.macro.MacroRunner.run(MacroRunner.java:103)
        at java.lang.Thread.run(Unknown Source)



I appreciate your help.
Sasmita