Login  Register

Read value from ASCII file for image properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Read value from ASCII file for image properties

Lars
2 posts
Hi all,
First, many thanks to the ImageJ development team. A great tool!
I am a newbie at ImageJ and using Image1.46r.
I have a little question about a macro: I like to read a value from an ASCII file an use it for the image properties Pixel "Width" and "Height" and "Voxel Depth".

What I tried so far:

// ~~~~~~Begin macro
//1.) Choose Image tif File. (e.g:"1166-24.tif")
//Note: Tiled Tiff. Open with ImageIO...  
run("Open ...", "Select Tiff File");

?

//2.)Looking for the related ASCII file which should be in the same directory. The name is
//equal, except the extension is ".tfw" instead of ".tif" (e.g:"1166-24.tfw")
//----Begin file example----
//0.250000 //--> This value is wanted
//0.000000
//0.000000
//-0.250000
//2598125.125000
//1202999.875000//
//----End file example----

?

//3.) If the file is being found, read the value from the *first* row (e.g.: 0,250000) and copy it into "Image Properties...":
//pixel_width=copy-value-here (e.g.:0.25)
//pixel_height=copy-value-here (e.g.:0.25)
//voxel_depth=copy-value-here (e.g.:0.25)
//("Properties...", "channels=1 slices=1 frames=1 unit=m pixel_width=copy-value-here pixel_height=copy-value-here voxel_depth=copy-value-here frame=[0 sec] origin=0,0");

?

// ~~~~~~End macro

Many thanks for any help
Lars
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Read value from ASCII file for image properties

Herbie-2
38 posts
Lars,

as always it may be helpful to read the docs, in this case especially
the list of macro functions

        http://rsb.info.nih.gov/ij/developer/macro/functions.html

and the associated example macros.

There you will find all calls necessary for your endeavor.

Look especially for the "File Functions" that allow you to obtain
information about (the presence of) files and that let you open text
files and read from them...

HTH

Herbie
______________________________
On 04.02.13 17:32, Lars wrote:

> Hi all,
> First, many thanks to the ImageJ development team. A great tool!
> I am a newbie at ImageJ and using Image1.46r.
> I have a little question about a macro: I like to read a value from an ASCII
> file an use it for the image properties Pixel "Width" and "Height" and
> "Voxel Depth".
>
> What I tried so far:
>
> // ~~~~~~Begin macro
> //1.) Choose Image tif File. (e.g:"1166-24.tif")
> //Note: Tiled Tiff. Open with ImageIO...
> run("Open ...", "Select Tiff File");
>
> ?
>
> //2.)Looking for the related ASCII file which should be in the same
> directory. The name is
> //equal, except the extension is ".tfw" instead of ".tif"
> (e.g:"1166-24.tfw")
> //----Begin file example----
> //0.250000 //-->  This value is wanted
> //0.000000
> //0.000000
> //-0.250000
> //2598125.125000
> //1202999.875000//
> //----End file example----
>
> ?
>
> //3.) If the file is being found, read the value from the *first* row (e.g.:
> 0,250000) and copy it into "Image Properties...":
> //pixel_width=copy-value-here (e.g.:0.25)
> //pixel_height=copy-value-here (e.g.:0.25)
> //voxel_depth=copy-value-here (e.g.:0.25)
> //("Properties...", "channels=1 slices=1 frames=1 unit=m
> pixel_width=copy-value-here pixel_height=copy-value-here
> voxel_depth=copy-value-here frame=[0 sec] origin=0,0");
>
> ?
>
> // ~~~~~~End macro
>
> Many thanks for any help
> Lars
>
>
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/Read-value-from-ASCII-file-for-image-properties-tp5001661.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> 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
| More
Print post
Permalink

Re: Read value from ASCII file for image properties

Rasband, Wayne (NIH/NIMH) [E]
1064 posts
In reply to this post by Lars
On Feb 4, 2013, at 11:32 AM, Lars wrote:

> Hi all,
> First, many thanks to the ImageJ development team. A great tool!
> I am a newbie at ImageJ and using Image1.46r.
> I have a little question about a macro: I like to read a value from an ASCII
> file an use it for the image properties Pixel "Width" and "Height" and
> "Voxel Depth".

Use open() to open the tiff file. Use File.openAsString() to open the associated text file. Use split() to extract the values in the text file. And use setVoxelSize() to set the image scale. Here is an example:

  dir = "/Users/wayne/stack/";
  name = "1166-24.tif";
  open(dir+name);
  path2 = dir+File.nameWithoutExtension+".tfw";
  text = File.openAsString(path2);
  values = split(text);
  psize = parseFloat(values[0]);
  setVoxelSize(psize, psize, psize, "mm");

-wayne

>
> What I tried so far:
>
> // ~~~~~~Begin macro
> //1.) Choose Image tif File. (e.g:"1166-24.tif")
> //Note: Tiled Tiff. Open with ImageIO...  
> run("Open ...", "Select Tiff File");
>
> ?
>
> //2.)Looking for the related ASCII file which should be in the same
> directory. The name is
> //equal, except the extension is ".tfw" instead of ".tif"
> (e.g:"1166-24.tfw")
> //----Begin file example----
> //0.250000 //--> This value is wanted
> //0.000000
> //0.000000
> //-0.250000
> //2598125.125000
> //1202999.875000//
> //----End file example----
>
> ?
>
> //3.) If the file is being found, read the value from the *first* row (e.g.:
> 0,250000) and copy it into "Image Properties...":
> //pixel_width=copy-value-here (e.g.:0.25)
> //pixel_height=copy-value-here (e.g.:0.25)
> //voxel_depth=copy-value-here (e.g.:0.25)
> //("Properties...", "channels=1 slices=1 frames=1 unit=m
> pixel_width=copy-value-here pixel_height=copy-value-here
> voxel_depth=copy-value-here frame=[0 sec] origin=0,0");
>
> ?
>
> // ~~~~~~End macro
>
> Many thanks for any help
> Lars
>
>
>
> --
> View this message in context: http://imagej.1557.n6.nabble.com/Read-value-from-ASCII-file-for-image-properties-tp5001661.html
> Sent from the ImageJ mailing list archive at Nabble.com.

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