http://imagej.273.s1.nabble.com/Adding-a-measurement-type-tp5005620p5005704.html
thanks a lot for your answers and your clear and helpful suggestions.
I don't want to stress this issue to much. It was thought just as -
deep in the code.
additional features and a support for additional color channels. It
works fine in our case. Both changes push this modified ParticleAnalyzer
into the area of multichannel fluorescence measurement. I wish this code
share it.
not a good idea in terms of version actuality. On the other side a
Custom_Particle_Analyzer is not directly interconnected with the IJ menu.
Maybe I will find time to revise my code. Maybe this is still something
what could be an option for future versions or IJ2.
> On Nov 24, 2013, at 2:26 PM, Peter Haub wrote:
>
>> Hi Wayne,
>>
>> sorry, more precise my idea was to add custom measurements which are performed when the ParticleAnalyzer is used.
> You can do this in a plugin by extending the ParticleAnalyzer class and overriding the saveResults() method. I have attached an example plugin that measures the mean pixel value along the perimeter of particles. It displays the perimeter mean as "PMean" and the number of points sampled as "N". Here is an example of the Results table output:
>
> Area Mean Perim. PMean N
> 1 81 161.5 32.4 123.2 40
> 2 30 147.2 30.5 127.8 34
> 3 99 165.3 35.8 124.4 44
> 4 14 138.9 12.5 119 16
> 5 22 147.6 17.3 105.8 22
> 6 69 185.7 39.0 84.7 46
> 7 3 130.7 5.7 122 8
> 8 1 128 2.8 120 4
> 9 81 183.4 42.4 84.3 50
> 10 90 181.5 49.6 82.9 56
> 11 53 188.4 35.6 84.8 42
> 12 49 172.9 36.7 80 42
>
>
> import ij.*;
> import ij.measure.*;
> import ij.plugin.*;
> import ij.plugin.filter.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
>
> public class Custom_Particle_Analyzer implements PlugIn {
>
> public void run(String arg) {
> ImagePlus imp = IJ.getImage();
> analyzeParticles(imp);
> }
>
> public void analyzeParticles(ImagePlus imp) {
> CustomAnalyzer pa = new CustomAnalyzer();
> int flags = pa.setup("", imp);
> if (flags==PlugInFilter.DONE)
> return;
> pa.run(imp.getProcessor());
> Analyzer.getResultsTable().show("Results");
> }
>
> class CustomAnalyzer extends ParticleAnalyzer {
> @Override
> protected void saveResults(ImageStatistics stats, Roi roi) {
> super.saveResults(stats, roi);
> ImageProcessor ip = imp.getProcessor();
> ip.setRoi(roi);
> FloatPolygon p = roi.getInterpolatedPolygon(1, false);
> int n = p.npoints;
> double sum = 0;
> for (int i=0; i<n; i++) {
> int x = (int)Math.round(p.xpoints[i]);
> int y = (int)Math.round(p.ypoints[i]);
> sum += ip.getPixel(x, y);
> }
> double mean = sum/n;
> rt.addValue("PMean", mean);
> rt.addValue("N", n);
> }
> }
>
> }
>
>
>
>> On 24.11.2013 19:47, Rasband, Wayne (NIH/NIMH) [E] wrote:
>>> It is easy to add custom measurements to the Results table. This example macro opens the Blobs sample image, creates a selection, measures the area, mean, centroid and perimeter, and then calculates the perimeter mean and adds it to the same row of the Results table as "PMean". This macro has a keyboard shortcut so you can run it by typing "1".
>>>
>>> macro "Measure Boundary Mean [1]" {
>>> saveSettings;
>>> run("Blobs (25K)");
>>> setAutoThreshold("Default");
>>> doWand(114, 82);
>>> run("Interpolate", "interval=1 smooth");
>>> resetThreshold();
>>> run("To Selection");
>>> run("Set Measurements...", "area mean centroid perimeter");
>>> run("Measure");
>>> getSelectionCoordinates(x, y);
>>> n = x.length;
>>> sum = 0;
>>> for (i=0; i<n; i++)
>>> sum += getPixel(x[i], y[i]);
>>> mean = sum/n;
>>> setResult("PMean", nResults-1, mean);
>>> restoreSettings;
>>> }
>>>
>>> Here is a JavaScript version:
>>>
>>> imp = IJ.openImage("
http://imagej.nih.gov/ij/images/blobs.gif");
>>> IJ.setAutoThreshold(imp, "Default");
>>> IJ.doWand(imp, 128, 83, 0, "Legacy");
>>> //imp.show();
>>> IJ.run(imp, "Interpolate", "interval=1 smooth");
>>> IJ.resetThreshold(imp);
>>> IJ.run(imp, "To Selection", "");
>>> IJ.run("Set Measurements...", "area mean centroid perimeter");
>>> roi = imp.getRoi();
>>> p = roi.getPolygon();
>>> n = p.npoints;
>>> sum = 0;
>>> ip = imp.getProcessor();
>>> for (i=0; i<n; i++)
>>> sum += ip.getPixel(p.xpoints[i], p.ypoints[i]);
>>> mean = sum/n;
>>> analyzer = new Analyzer(imp);
>>> analyzer.measure();
>>> rt = Analyzer.getResultsTable();
>>> rt.addValue("PMean", mean)
>>> rt.show("Results");
>>>
>>>
>>> On Nov 23, 2013, at 11:59 AM, Peter Haub wrote:
>>>
>>>> Adrians idea is very nice.
>>>>
>>>> Just to give an input (no a solution) to this:
>>>>
>>>> I could imagine the possibility to specify a (set of) 'user defined measurement macro' or a 'user defined measurement plugin'.
>>>> This 'user defined measurements' could be selected in the measurement dialog, e.g. as UDMM_xx or UDMP_xx where xx is a number 00 .. 99.
>>>>
>>>> The modification in ImageJ should be not to complicated and the definition of an appropriate interface, return value and naming scheme of the macro/plugin not to complex.
>>>>
>>>> Peter
>>>>
>>>> On 22.11.2013 18:47, Adrian Daerr wrote:
>>>>> Hello,
>>>>>
>>>>> On 11/20/2013 04:00 PM, Grant Harris wrote:
>>>>>> I'd like to add a measurement for circular/directional statistics for calculating the average orientation of an area/ROI.
>>>>>> I'd like to do this so that I can utilize the functionality of the RoiManager and the ResultsTable, e.g. select a number of ROIs, do the measurement, and have the results in a table. Does anyone have an idea on how to do this?
>>>>> I have no answer to your question, but merely want to highlight the part of it which has not been discussed. So far contributions focussed directly on the problem at hand of measuring orientations, but I would find really interesting if there were also ideas on how to allow adding custom measurements in general. I have wanted to do that on several occasions (two examples: to measure fourier coefficients on the rim of circular selections; to measure the mean intensity on the boundary of a ROI). If there was a way to easily add to the measurement dialog a function/plugin(via a new MeasurementFilter interface?)/macro that takes an image+(roi/mask) as input and returns one or more double values, one could calculate any quantity on selections with minimal coding, and benefit from ImageJ's measurement functionalities mentioned by GH.
>>>>>
>>>>> I have no idea if this is easy to implement, but it might be a feature request worth considering for IJ1 or IJ2.
>>>>>
>>>>> cheers,
>>>>> Adrian
>>>>> (frequent user of the Process->Math->Macro..., which by allowing for arbitrary functions has sharply reduced the need for one-shot plugins iterating over all pixels and images)
>>>>>
>>>>> --
>>>>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>>>>
>>>>>
>>>> --
>>>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>> --
>>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>