Adding a measurement type

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

Adding a measurement type

Grant Harris
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?

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

Re: Adding a measurement type

Kenneth Sloan-2
"Circular" is tricky.  "Semi-circular" is easier.

If you measure the orientation of an ROI - say by fitting an ellipse which has the same low order moments, then the orientations 0 and pi are interchangeable.  So, you can get away with computing the orientation modulo pi - so that all orientations fall in the range [0,pi).

Once you do that, you can apply all standard statistics without difficulty.

BUT…someone will surely come up with a definition of "orientation" for which 0 and pi are distinct.
Then, you need to deal with a fully circular set of value, and you are … screwed.

I don't know how to compute a mean for a set of values in [0, 2pi).  Assume the values are:
 
   ( pi/8, pi/8, 15pi/8, 15pi/8 )

What's the "average" of these values?  If you get pi…is that really the answer you want?

Now, rotate your world by pi/4.  What happens to the mean?

I *think* everything works out nicely if you work with orientation modulo pi - but I might be wrong about that.  I've never needed to actually implement such an analysis package and there may be "gotchas" that I don't know about.

One point: if you deal with slowly rotating ROI's (say, in an animation), it might not be desirable to have the orientation "flip" at pi - it's more natural to be fully circular.  So, you might want to
keep the full range of [0,2pi) for the raw orientation values, but fold to [0,pi) in the statistics.

AS I said…"circular" is tricky.


--
Kenneth Sloan
[hidden email]


On Nov 20, 2013, at 09:00 , Grant Harris <[hidden email]> 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?
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: Adding a measurement type

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Grant Harris
On Nov 20, 2013, at 10:00 AM, 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?

Have you considered using the "Fit ellipse" measurement option to get ROI orientation? It adds "Major", "Minor" and "Angle" columns to the Results table. Here is an example macro that draws the ellipse major axis on each particle in the Blobs sample image:

  saveSettings;
  open("http://imagej.nih.gov/ij/images/blobs.gif");
  setAutoThreshold("Default");
  run("Set Measurements...", "  centroid fit");
  run("Analyze Particles...", "exclude clear");
  resetThreshold();
  setColor("red");
  setLineWidth(2);
  for (i=0; i<nResults; i++) {
     xc = getResult("X", i);
     yc = getResult("Y", i);
     major = getResult("Major", i);
     angle = getResult("Angle", i);
     dx = major*cos(angle/180 * PI)/2;
     dy = -major * sin(angle/180 * PI)/2;
     x1 = xc - dx;
     x2 = xc + dx;
     y1 = yc - dy;
     y2 = yc + dy;
     Overlay.drawLine(x1, y1, x2, y2);
  }
  Overlay.show;
  restoreSettings;

And here is a JavaScript version:

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
  Analyzer.setMeasurement(Measurements.CENTROID, true);
  Analyzer.setMeasurement(Measurements.ELLIPSE, true);
  IJ.setAutoThreshold(imp, "Default");
  IJ.run(imp, "Analyze Particles...", "exclude clear");
  IJ.resetThreshold(imp);
  rt = Analyzer.getResultsTable();
  overlay = new Overlay();
  for (i=0; i<rt.getCounter(); i++) {
     xc = rt.getValue("X", i);
     yc = rt.getValue("Y", i);
     major = rt.getValue("Major", i);
     angle = rt.getValue("Angle", i);
     dx = major*Math.cos(angle/180 * Math.PI)/2;
     dy = -major * Math.sin(angle/180 * Math.PI)/2;
     x1 = xc - dx;
     x2 = xc + dx;
     y1 = yc - dy;
     y2 = yc + dy;
     line = new Line(x1, y1, x2, y2);
     line.setStrokeColor(Color.red);
     line.setStrokeWidth(2);
     overlay.add(line);
  }
  imp.setOverlay(overlay);
  imp.show();

[cid:[hidden email]]




--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

blobs.png (47K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adding a measurement type

Daniel Hornung
In reply to this post by Grant Harris
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday, November 20, 2013 16:00:10 you wrote:
> I'd like to add a measurement for circular/directional statistics for
> calculating the average orientation of an area/ROI.

Hi,

adding to what Kenneth wrote, I would like to stress the nontrivial part in
your question: directional statistics[1].  The average of 1º and 179º is not
90º in most cases :-)

I have never come across tools in ImageJ or Fiji that would do this kind of
analysis for you.  If you just want the data for each ROI, Wayne's suggestion
is probably your solution.

Cheers,
Daniel

[1] https://en.wikipedia.org/wiki/Directional_statistics

- --
Max-Planck-Institute for Dynamics and Self-Organization
Research Group Biomedical Physics

Am Fassberg 17
D-37077 Goettingen

(+49) 551 5176 373
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIcBAEBAgAGBQJSjcg0AAoJEB7dAS3xl7EoQM8QAIkKVZ4fxbIjm/WTapq49lcX
uL+SiKkEi2Cbbnbl329AHQqKkJrrlCamghEyYXb0pUoAJQA3nr8kJjMAZajJBdf2
e3n1xCDXYs0onUPs5C/XHVsvmw11UNQAgGzIgtwR0TXIgRlIvJb0hHGandXJD0vH
vpBHRKCUkKTgLbV8buGTSsXT76bh4pseBLoc1sTYsNgkn9JLkih/9iaqgmNYShGA
QO/lENptVziaJX1jHE6sCxEiC6kYvavrohP7vNQzH55e0NJ5e31pThReH7Tgmzst
a1UusMsEvLCw7mhgwg5I0rc1kxUM3H2v6j6Y+T4k0/plHsmu00HFWO7k0WYMfsF5
h43IdKf+UvPR9PkkpfgvyhHs8FXWKGCvBJ1qWn4lbe5ZBbuHwUBf+FX5dy6ZD7IX
2KjvJGEOg3jo0m51ATIc+9treaP6T5tbYkryrZUfL+4dTiQILyRB/YwN/x1SxyM6
8VE8PPblBIYAdksrWYIdk0wYXyiQeEUPj41se9U574IYw0icRDeDpIk5Vvevh4c0
4FkSUnN5bkGWkk/qMAGJsoB6VA10IZ2y2vujgDaSq1BogP/kFJdVgmcIJC7PhLtD
T9Sety+PuW5Q09D88tMahuhws546hUQ6vowdxJS7zVoOvv3euaudamWYn/gv7fdY
lxWwAyOA29ea5jZYAb4G
=ornA
-----END PGP SIGNATURE-----

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

IRLabs TRIWAVE USB camera works with the Quicktime Capture Plugin

Seth Pappas
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
 Wayne,
People using Image J for live video display and capture will want to know that the IRLabs Ge pixel TRIWAVE USB2.0 camera has been tested and works flawlessly with the plugin. Would you consider adding it to the camera list in your description of the plugin?

Many thanks,
Seth Pappas


 

 

-----Original Message-----
From: Rasband, Wayne (NIH/NIMH) [E] (NIH/NIMH) [E] <[hidden email]>
To: IMAGEJ <[hidden email]>
Sent: Wed, Nov 20, 2013 11:41 pm
Subject: Re: Adding a measurement type


On Nov 20, 2013, at 10:00 AM, 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?

Have you considered using the "Fit ellipse" measurement option to get ROI
orientation? It adds "Major", "Minor" and "Angle" columns to the Results table.
Here is an example macro that draws the ellipse major axis on each particle in
the Blobs sample image:

  saveSettings;
  open("http://imagej.nih.gov/ij/images/blobs.gif");
  setAutoThreshold("Default");
  run("Set Measurements...", "  centroid fit");
  run("Analyze Particles...", "exclude clear");
  resetThreshold();
  setColor("red");
  setLineWidth(2);
  for (i=0; i<nResults; i++) {
     xc = getResult("X", i);
     yc = getResult("Y", i);
     major = getResult("Major", i);
     angle = getResult("Angle", i);
     dx = major*cos(angle/180 * PI)/2;
     dy = -major * sin(angle/180 * PI)/2;
     x1 = xc - dx;
     x2 = xc + dx;
     y1 = yc - dy;
     y2 = yc + dy;
     Overlay.drawLine(x1, y1, x2, y2);
  }
  Overlay.show;
  restoreSettings;

And here is a JavaScript version:

  imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif");
  Analyzer.setMeasurement(Measurements.CENTROID, true);
  Analyzer.setMeasurement(Measurements.ELLIPSE, true);
  IJ.setAutoThreshold(imp, "Default");
  IJ.run(imp, "Analyze Particles...", "exclude clear");
  IJ.resetThreshold(imp);
  rt = Analyzer.getResultsTable();
  overlay = new Overlay();
  for (i=0; i<rt.getCounter(); i++) {
     xc = rt.getValue("X", i);
     yc = rt.getValue("Y", i);
     major = rt.getValue("Major", i);
     angle = rt.getValue("Angle", i);
     dx = major*Math.cos(angle/180 * Math.PI)/2;
     dy = -major * Math.sin(angle/180 * Math.PI)/2;
     x1 = xc - dx;
     x2 = xc + dx;
     y1 = yc - dy;
     y2 = yc + dy;
     line = new Line(x1, y1, x2, y2);
     line.setStrokeColor(Color.red);
     line.setStrokeWidth(2);
     overlay.add(line);
  }
  imp.setOverlay(overlay);
  imp.show();

[cid:[hidden email]]




--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

 


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

Re: IRLabs TRIWAVE USB camera works with the Quicktime Capture Plugin

Gabriel Landini
On Thursday 21 Nov 2013 20:43:39 Seth Pappas wrote:
>  Wayne,
> People using Image J for live video display and capture will want to know
> that the IRLabs Ge pixel TRIWAVE USB2.0 camera has been tested and works
> flawlessly with the plugin.

Does that run under linux?

Thanks

Gabriel

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

Re: IRLabs TRIWAVE USB camera works with the Quicktime Capture Plugin

Seth Pappas
 The camera uses standard USB device class interfaces CDC/ACM for virtual com port and USB Video Class for streaming video. Video encoding is non-standard...12 bit images encoded in YUV4:2:2. A flter is used to transform a pseudo monochrome image to 12 bit.
Our current SDK is written for Windows but we would expect a Linux version could be written.

Thanks for asking,
Seth

 

 

-----Original Message-----
From: Gabriel Landini <[hidden email]>
To: IMAGEJ <[hidden email]>
Sent: Fri, Nov 22, 2013 4:28 am
Subject: Re: IRLabs TRIWAVE USB camera works with the Quicktime Capture Plugin


On Thursday 21 Nov 2013 20:43:39 Seth Pappas wrote:
>  Wayne,
> People using Image J for live video display and capture will want to know
> that the IRLabs Ge pixel TRIWAVE USB2.0 camera has been tested and works
> flawlessly with the plugin.

Does that run under linux?

Thanks

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

 

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

Re: Adding a measurement type

Adrian Daerr-2
In reply to this post by Grant Harris
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
Reply | Threaded
Open this post in threaded view
|

Re: Adding a measurement type

Grant Harris
Thanks for all for your comments.
I've already worked out the circular/directional statistics
calculations.  Adrian's interpretation is the one I intended - Is there
a way allow adding custom measurements to the Analyzer and thus the
RoiManager.  I'm not sure there is a way to do that but I'm trying
another approach...
Use the RoiManager to select multiple Rois, then run a plugin to do the
measurements by getting the array of Rois and doing the measurments
with my own code.

Grant

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

Adding custom measurement

Peter Haub
In reply to this post by Adrian Daerr-2
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
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom measurement

Rasband, Wayne (NIH/NIMH) [E]
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
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom measurement

Peter Haub
Hi Wayne,

sorry, more precise my idea was to add custom measurements which are
performed when the ParticleAnalyzer is used.

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
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom measurement

Gabriel Landini
On Sunday 24 Nov 2013 19:26:30 Peter Haub wrote:
> sorry, more precise my idea was to add custom measurements which are
> performed when the ParticleAnalyzer is used.

What you are asking can be done via the macro language already if there is a
procedure that does something on a single object:
You split your image into a series of single region images (there are a couple
of ways of doing this, via the ROI manager or using Binary Reconstruction)
then process that single region, get the result into a variable and update the
Results Table accordingly (since you know which region of the original you are
processing). Then repeat for all remaining regions.
I use this quite a lot and doing it in batch mode is both transparent and
fast.

If you need an example, just ask.

Cheers
Gabriel

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

Re: Adding custom measurement

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Peter Haub
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
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom measurement

Peter Haub
Dear Gabriel,
Dear Wayne,

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 -
maybe - a possibility to add a useful feature for those who are not so
deep in the code.

I have modified the ParticleAnalyzer for a project by including
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
would have a more professional and less workaround character and I wish
it would have the potential for a more general usage so that I could
share it.
What I learned from it was that a modification of the original code is
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.

Regards and Thanks

Peter

On 25.11.2013 04:15, Rasband, Wayne (NIH/NIMH) [E] wrote:

> 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
>

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

Re: Adding custom measurement

rmakanza
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
I also have more or less similar problem: I would like to run a macro with a series of steps extracting data from images at different levels after applying some filtering processes. Each step has its own result table. How can I add statistics of a series of results tables into one CustomStatsTable e.g. macro:http://rsb.info.nih.gov/ij/macros/CustomTabStatFromResults.txt. Thank in advance for your assistance.


Reply | Threaded
Open this post in threaded view
|

Re: Adding custom measurement

rmakanza
I also have more or less similar problem: I would like to run a macro with a series of steps extracting data from images at different levels after applying some filtering processes. Each step has its own result table. How can I add statistics of a series of results tables into one CustomStatsTable e.g. macro:http://rsb.info.nih.gov/ij/macros/CustomTabStatFromResults.txt. Thank in advance for your assistance.