MKI$ -like macro function?

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

MKI$ -like macro function?

Gabriel Landini
Hi,
I have a loop in a macro that generates signed numbers and I want to write all
those rounded number to a raw file as a signed 16bit, little endian.strings

I can open a file as:
  f = File.open("test");
and print to it the number stored in w as a string with:
  print(f, round(w));

However this prints the numbers as strings, one per line, and what I am
looking for is a stream of signed 16bit little endian..

I thought of using a 16 bit file and save it as raw, but that cannot store
signed numbers.
I guess I am looking something like the ancient MKI$ function of QuickBASIC
(don't laugh I did my very first imaging program using that!).

Can this be done in the macro language?

Many thanks

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: MKI$ -like macro function?

Krs5
Hi Gabriel,

You might want to use something like:

// Read the intensity/pixel
getDimensions(width, height, channels, slices, frames)                              
a=newArray(width*height);
for(x=0;x<width;x++){
        for(y=0;y<height;y++){
        a[y*width+x]=getPixel(x,y);  
        }
}

// Write the intensity/pixel in a log file
x=0;
while (x<(width*height)){
        b=newArray(width);
        for (i=0; i<width;i++){
                b[i]=a[x];
                x=x+1;
        }
        Array.print(b);
}

You might have to update the code for your specific use.

Best wishes

Kees


Dr Ir K.R. Straatman
Senior Experimental Officer
Centre for Core Biotechnology Services
University of Leicester
http://www.le.ac.uk/biochem/microscopy/home.html


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Gabriel Landini
Sent: 23 September 2012 23:01
To: [hidden email]
Subject: MKI$ -like macro function?

Hi,
I have a loop in a macro that generates signed numbers and I want to write all
those rounded number to a raw file as a signed 16bit, little endian.strings

I can open a file as:
  f = File.open("test");
and print to it the number stored in w as a string with:
  print(f, round(w));

However this prints the numbers as strings, one per line, and what I am
looking for is a stream of signed 16bit little endian..

I thought of using a 16 bit file and save it as raw, but that cannot store
signed numbers.
I guess I am looking something like the ancient MKI$ function of QuickBASIC
(don't laugh I did my very first imaging program using that!).

Can this be done in the macro language?

Many thanks

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: MKI$ -like macro function?

Michael Schmid
In reply to this post by Gabriel Landini
Hi Gabriel,

it should be possible to create an image and save it as raw image to write 16-bit signed numbers.
Use Edit>Options>IO Options to set the byte order.

array = newArray(-2, -1, 0, 1, 32767, -32767);
nValues = lengthOf(array);
newImage("temp", "16-bit", nValues, 1, 1);
for (i=0; i<nValues; i++)
  putPixel(i,0,array[i]&0xffff);

Note that a hex value of, e.g. 0xfffe is *interpreted* by ImageJ as 65534, but a program that reads it as signed int will *interpret* 0xfffe as -2. There is no difference in the bits, it's just a difference of how you interpret it.
You can easily verify this by saving the macro output as raw and opening the file as raw, with '16-bit signed' (mind the byte order). Then, the calibrated pixel values will be displayed as the numbers in 'array' (ImageJ uses calibrated pixel values to simulate signed image data).

If you might have values exceeding the range of 16-bit signed ints (below -32768 or above 32767), you have to care what to do with them. My macro does not care about this problem.

Michael
________________________________________________________________
On Sep 24, 2012, at 00:00, Gabriel Landini wrote:

> Hi,
> I have a loop in a macro that generates signed numbers and I want to write all
> those rounded number to a raw file as a signed 16bit, little endian.strings
>
> I can open a file as:
>  f = File.open("test");
> and print to it the number stored in w as a string with:
>  print(f, round(w));
>
> However this prints the numbers as strings, one per line, and what I am
> looking for is a stream of signed 16bit little endian..
>
> I thought of using a 16 bit file and save it as raw, but that cannot store
> signed numbers.
> I guess I am looking something like the ancient MKI$ function of QuickBASIC
> (don't laugh I did my very first imaging program using that!).
>
> Can this be done in the macro language?
>
> Many thanks
>
> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: MKI$ -like macro function?

Gabriel Landini
On Monday 24 Sep 2012 10:35:01 Michael Schmid wrote:
> it should be possible to create an image and save it as raw image to write
> 16-bit signed numbers. Use Edit>Options>IO Options to set the byte order.

Thanks Michael, For some reason I was confused with the "interpretation" part
(I should know better! :-/ ) but thanks to your example I realised how it
should handled.

Many thanks again,
Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html