Exporting image stack to obj via script

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

Exporting image stack to obj via script

Simon W
I'm using Fiji to process some image stacks that I need to export to OBJ format. I have over 2000 stacks and need to script this.

The image stacks are all stored in the following directory format

slices/specimen_number/16 bit/specimen_number00000x.tif

where specimen_number varies and there will be multiple .tif files in the directory numbered from 0000 to n.

I want to be able to choose the slices directory, read the images in turn in each directory as a stack and then convert each stack to an obj file and write it out in the corresponding directory.

I ran each step on a single directory and recorded as a macro which i then attempted to automate.

The script so far is below. The commented lines at the bottom of the script are what the macro recorder saved.

I'm also trying to save the image stack.

The script obviously doesn't work as 1. It doesn't write out the stack 2. The 3D viewer opens but doesn't read in the file

I havent tried to finish off the rest of it i.e. the export as until I can get the rest to work.

As you've probably gathered I'm not a programmer and I'm sure there's a much easier way of doing this!

Any help gratefully received.

Simon

dir = getDirectory("Choose a Directory");
list = getFileList(dir);
print(list.length, 'files in this folder');
setBatchMode(true);

for (i=0; i<list.length; i++) {
inputPath = dir+list[i];
outputFile = inputPath+"Processed";
run("Image Sequence...", "open=[*.tif] sort");
run("8-bit");
saveAs("Tiff", inputPath+"Processed");  
run("3D Viewer");
call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
call("ij3d.ImageJ3DViewer.add", outputfile, "None", "16 bit", "150", "true", "true", "true", "2", "2");
}





//run("Image Sequence...", "open=[G:\\SW_Teethstack [2014-12-03 10.42.23]\\slices\\JR3\\16 bit\\JR30000000.tif] sort");
//run("8-bit");
//run("3D Viewer");
//call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
//call("ij3d.ImageJ3DViewer.add", "16 bit", "None", "16 bit", "150", "true", "true", "true", "2", "2");
//call("ij3d.ImageJ3DViewer.select", "16 bit");
//call("ij3d.ImageJ3DViewer.select", "16 bit");
//call("ij3d.ImageJ3DViewer.select", "16 bit");
//call("ij3d.ImageJ3DViewer.exportContent", "WaveFront", "G:\SW_Teethstack [2014-12-03 10.42.23]\slices\JR3\16 bit\mesh.obj");
Reply | Threaded
Open this post in threaded view
|

Re: Exporting image stack to obj via script

Michael Schmid
Hi Simon,

not sure whether I understand your problem correctly, but it seems that your images are not in an immediate subfolder of the 'slices' directory.

So if you select the 'slices' directory, the macro will get the list of files in the slices directory, but that's not where the tiffs are.

You will need something like the
  http://rsb.info.nih.gov/ij/macros/ListFilesRecursively.txt
macro, but instead of the 'print' statement you should have the code for opening the image sequence, converting it to 8-bit data and writing it to disk.
You should probably close the stack after writing it to disk; otherwise you might run out of memory (depends of the number of stacks and their size).


Michael
________________________________________________________________
On Jan 14, 2015, at 19:45, Simon W wrote:

> I'm using Fiji to process some image stacks that I need to export to OBJ
> format. I have over 2000 stacks and need to script this.
>
> The image stacks are all stored in the following directory format
>
> slices/specimen_number/16 bit/specimen_number00000x.tif
>
> where specimen_number varies and there will be multiple .tif files in the
> directory numbered from 0000 to n.
>
> I want to be able to choose the slices directory, read the images in turn in
> each directory as a stack and then convert each stack to an obj file and
> write it out in the corresponding directory.
>
> I ran each step on a single directory and recorded as a macro which i then
> attempted to automate.
>
> The script so far is below. The commented lines at the bottom of the script
> are what the macro recorder saved.
>
> I'm also trying to save the image stack.
>
> The script obviously doesn't work as 1. It doesn't write out the stack 2.
> The 3D viewer opens but doesn't read in the file
>
> I havent tried to finish off the rest of it i.e. the export as until I can
> get the rest to work.
>
> As you've probably gathered I'm not a programmer and I'm sure there's a much
> easier way of doing this!
>
> Any help gratefully received.
>
> Simon
>
> dir = getDirectory("Choose a Directory");
> list = getFileList(dir);
> print(list.length, 'files in this folder');
> setBatchMode(true);
>
> for (i=0; i<list.length; i++) {
> inputPath = dir+list[i];
> outputFile = inputPath+"Processed";
> run("Image Sequence...", "open=[*.tif] sort");
> run("8-bit");
> saveAs("Tiff", inputPath+"Processed");  
> run("3D Viewer");
> call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
> call("ij3d.ImageJ3DViewer.add", outputfile, "None", "16 bit", "150", "true",
> "true", "true", "2", "2");
> }
>
>
>
>
>
> //run("Image Sequence...", "open=[G:\\SW_Teethstack [2014-12-03
> 10.42.23]\\slices\\JR3\\16 bit\\JR30000000.tif] sort");
> //run("8-bit");
> //run("3D Viewer");
> //call("ij3d.ImageJ3DViewer.setCoordinateSystem", "false");
> //call("ij3d.ImageJ3DViewer.add", "16 bit", "None", "16 bit", "150", "true",
> "true", "true", "2", "2");
> //call("ij3d.ImageJ3DViewer.select", "16 bit");
> //call("ij3d.ImageJ3DViewer.select", "16 bit");
> //call("ij3d.ImageJ3DViewer.select", "16 bit");
> //call("ij3d.ImageJ3DViewer.exportContent", "WaveFront", "G:\SW_Teethstack
> [2014-12-03 10.42.23]\slices\JR3\16 bit\mesh.obj");
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Exporting-image-stack-to-obj-via-script-tp5011216.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