Plot profile macro through multiple slices

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

Plot profile macro through multiple slices

Jubok
Hello,

I'm working on line scan (xt) images and I need to extract the plot profile data (vertical) of each slices.
I 'wrote' a macro with the help of this mailing list :

  run("Plot Profile");
  Plot.getValues(x, y);
  run("Clear Results");
  for (i=0; i<x.length; i++) {
     setResult("x", i, x[i]);
     setResult("y", i, y[i]);
  }
  setOption("ShowRowNumbers", false);
  updateResults;
 
  saveAs("Measurements", "/Desktop/New_RawData/1.txt");

It works but I need to manually change the slice and file name, so a loop is required here...
But I can't make it functional, if I put simply

 N = nSlices;
 for (i=1; i<=N; i++) {
         setSlice(i);

At the beginning I get an error that say the argument of setSlice must be >=1 and <=1..

I'm not used to write code so the error may be obvious ..

Many thanks in advance !
 
Reply | Threaded
Open this post in threaded view
|

Re: Plot profile macro through multiple slices

Jubok
I have a working solution but I think it's not the most elegant one :

dir = getDirectory("Choose a directory :");
counter=1;

for (i=1; i <= nSlices(); i++) {
        setSlice(i);
        run("Plot Profile");
  Plot.getValues(x,y);
  run("Clear Results");
  for (j=0; j<x.length; j++) {
                setResult("x", j, x[j]);
                setResult("y", j, y[j]);
        }
        setOption("ShowRowNumbers", false);
  updateResults;
  saveAs("txt", dir+"slice_"+counter+".txt");
  counter+=1;
        run("Close");
        run("Close");
}

It needs to close the Plot and Results windows so I had to put "run("Close")" two times, it didn't work with "close()"

If you have suggestion to improve the code don't hesitate ! :)


Reply | Threaded
Open this post in threaded view
|

Re: Plot profile macro through multiple slices

Jubok
My final version, extracting vertical plot profile from a ROI in a xt linescan image with multiple slices !

macro linescan_dataextract{
       
run("Plots...", "vertical interpolate sub-pixel");
f = File.open("");
for (s=1; s <= nSlices(); s++) {
        setSlice(s);
        run("Plot Profile");
  Plot.getValues(x,y);
  run("Clear Results");
  for (j=0; j<x.length; j++) {
  print(f, x[j] + " \t" + y[j]);
        }
        run("Close");
}
showMessage("Terminé !");

}
Reply | Threaded
Open this post in threaded view
|

Re: Plot profile macro through multiple slices

Pedro J CamelloDr Pedro J Camello
In reply to this post by Jubok
I´m testing your final code but the line run("Plots..."...) fails (unknown command...)

In your print line, what is the purpose of f? To print the file name?

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

Re: Plot profile macro through multiple slices

Michael Schmid
On 2016-05-29 11:29, Pedro J Camello wrote:
 > I´m testing your final code but the line run("Plots..."...) fails
(unknown command...)

Hi Pedro,

please update to the latest version of ImageJ (Help>Update ImageJ).
The "Edit>Options>Profile Plot Options" command has been renamed to
Edit>Options>Plots... because it mainly refers to options relevant for
all plots.

Michael

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

Re: Plot profile macro through multiple slices

Jubok
In reply to this post by Pedro J CamelloDr Pedro J Camello
Hello,

As Michael said, it's about your ImageJ/FIJI version.. This line is only if you need a vertical profile from your ROI.

And in the print line, f is the link between the new file and the loop that record the xy values : You assign an file.open function to f to create a new file, and the print function will allow you to write in it !
The file name is "log.txt" by default, if the user don't change it in the save dialog box.


Hope it helped !