Login  Register

Re: Read value from ASCII file for image properties

Posted by Rasband, Wayne (NIH/NIMH) [E] on Feb 05, 2013; 4:59pm
URL: http://imagej.273.s1.nabble.com/Read-value-from-ASCII-file-for-image-properties-tp5001661p5001673.html

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