IJ-macro: Selected values to 1D-array

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

IJ-macro: Selected values to 1D-array

H. Gluender
Dear experts,

this post concerns ImageJ 1.36b and macro solutions only!

I very much should like to know about an elegant macro approach to
write the values of all pixels of an arbitrary selection (image
types: 8-, 16-, 32-bit, but not RGB) to a 1D-array. (The values may
be written in arbitrary order.)

Presently, I copy the selection to a new image having the size
defined by the selection bounds and having a NaN-background. Then I
loop through this image and write all non-NaN values to the 1D-array.

Is there a better/faster way to perform this task with a macro?

Any suggestions welcome
--


                   Herbie

          ------------------------

          <http://www.gluender.de>
Reply | Threaded
Open this post in threaded view
|

Re: IJ-macro: Selected values to 1D-array

H. Gluender
In case somebody else is interested in this task, meanwhile I've
found a quite satisfying solution (no intermediate image required):

// BEGIN macro snipped
getRawStatistics( n );
getSelectionBounds( x, y, width, height );
snapshot();
setBackgroundColor( 0, 0, 0 );
run( "Clear Outside" );
// fill array with all non zero-valued pixels of the "selection bound"-area
// if these are less than n pixels, then top up with zeros
reset();
// END macro snipped

>Dear experts,
>
>this post concerns ImageJ 1.36b and macro solutions only!
>
>I very much should like to know about an elegant macro approach to
>write the values of all pixels of an arbitrary selection (image
>types: 8-, 16-, 32-bit, but not RGB) to a 1D-array. (The values may
>be written in arbitrary order.)
>
>Presently, I copy the selection to a new image having the size
>defined by the selection bounds and having a NaN-background. Then I
>loop through this image and write all non-NaN values to the 1D-array.
>
>Is there a better/faster way to perform this task with a macro?
>
>Any suggestions welcome

--


                   Herbie

          ------------------------

          <http://www.gluender.de>