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(); } |
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 |
Hi,
I also suggest to use some other languages (I use Jython too) to have full access to ImageJ API, and overall you can use some IDE like Eclipse to debug your code in a more or less easy way. Have a nice day, Emanuele
Image Analyst @Ifom-IEO research campus -MI-
|
In reply to this post by cwc
Hi user "cwc", to have your code working you could simply change the line
---------------------- yValues = getResult('mean'); ---------------------- in ---------------------- yValues=newArray(n); for(i=0;i<n;i++) { yValues[i]=getResult('Mean',i); } ---------------------- Best regards, Rocco
Senior Microscopist
Crick Advanced Light Microscopy facility (CALM) The Francis Crick Institute 1 Midland Road, NW1 1AT, London (UK) https://roccodant.github.io/ |
In reply to this post by Emanuele Martini
Hi Michael and Emanuele,
Thank you for your time and replies. It is my bad since I am not familiar with Fiji and thus it is my first time to hear the Jython code and others. I've read the related instructions in Fiji and felt interesting to learn them. My appreciation for your kind advices. :) Regards, cwc |
In reply to this post by Rocco D'Antuono
Hi Rocco,
Yes, I got the same answer as yours. I feel grateful because I figure out the problem and agree with someone even though the question is small. Very thanks for your time and reply. :) Regards, cwc |
In reply to this post by cwc
Hi cwc,
You do not need to write a macro. Use "Plot Results" function from BAR package written by Tiago Ferreira. https://github.com/tferr/Scripts/blob/master/README.md#data-analysis BAR is listed in the update sites. http://fiji.sc/List_of_update_sites HTH Kota On Mon, Oct 27, 2014 at 4:53 PM, cwc <[hidden email]> wrote: > 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 > -- -------------------------------------------------------------*Dr. Kota Miura* Scientist & IT Engineer Centre for Molecular and Cellular Imaging, European Molecular Biology Laboratory Meyerhofstr. 1 69117 Heidelberg GERMANY Tel +49 6221 387 404 Mobile +49 160 95001177 Fax +49 6221 387 512 http://cmci.embl.de ------------------------------------------------------------- -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |