Posted by
Michael Entrup on
Oct 27, 2014; 5:31pm
URL: http://imagej.273.s1.nabble.com/To-plot-mean-values-in-results-table-tp5010204p5010207.html
Hi cwc,
here is some Jython code (tested with Fiji) that plots the mean value of
a stack vs the slice number:
from ij import IJ
from ij import WindowManager as WM
from ij.gui import Plot
image = WM.getCurrentImage()
stack = image.getStack()
x = []
y = []
for i in range(1, stack.getSize() + 1):
ip = stack.getProcessor(i)
stat = ip.getStatistics()
x.append(i)
y.append(stat.mean)
plot = Plot("title", "slice", "mean", x, y)
plot.show()
The following code will create a results table first and reads the mean
values from there (2nd for loop):
from ij import IJ
from ij import WindowManager as WM
from ij.measure import ResultsTable as RT
from ij.gui import Plot
image = WM.getCurrentImage()
stack = image.getStack()
x = []
y = []
IJ.run("Set Measurements...", "mean display redirect=None decimal=3");
IJ.run("Clear Results", "")
for i in range(1, stack.getSize() + 1):
image.setSlice(i)
IJ.run(image, "Measure", "")
table = RT.getResultsTable()
counter = table.getCounter()
for i in range(0,counter):
row = table.getRowAsString(i)
cells = row.split()
x.append(i)
# the table consists of 3 columns
# cells[0]: index
# cells[1]: slice name
# cells[2]: mean value
y.append(float(cells[2]))
plot = Plot("title", "slice", "mean", x, y)
plot.show()
For me it's much easier to write macros with Jython than with the basic
macro language, because you can use the full ImageJ API that is well
documented. I hope this examples will help you.
Best regards
Michael
Am 27.10.2014 um 16:53 schrieb cwc:
> Hi everyone,
>
> My apology if my question is too basic. I am trying to search the related
> topics but still confused. My need is to plot x-y graph (x = nResults and y
> = mean in results table) and thus I try to modify the example code but fail
> (please see below). Could everyone help me to figure it out? Thank you very
> much.
>
>
> n = nResults;
>
> macro "Plot" {
> yValues = getResult('mean');
> Plot.create("Plot", "X", "Y");
> Plot.setLimits(0, n, 0, 10000);
> Plot.setLineWidth(2);
> Plot.setColor("lightGray");
> Plot.add("line",yValues);
> Plot.setColor("red");
> Plot.add("circles", yValues);
> Plot.show();
> }
>
>
>
>
> --
> View this message in context:
http://imagej.1557.x6.nabble.com/To-plot-mean-values-in-results-table-tp5010204.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