Re: Total Particle Count from ParticleAnalyzer plugin

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

Re: Total Particle Count from ParticleAnalyzer plugin

ssim
Dear list,

 I am a newbie in java. I am writting a plugin to count the bacterial
colonies on an agar plate in batch processing. I want to save the total
count of colonies for each image of 3000 images in 'one place', rather than
a file of summary for each image. How can I get that information off
ParticleAnalyzer plugin ?

I have tried the following code in my program, but the totalCount is not
accessible:

ParticleAnalyzer pa = new ParticleAnalyzer();
count = pa.totalCount ;


Please help.


Stella
Reply | Threaded
Open this post in threaded view
|

Re: Total Particle Count from ParticleAnalyzer plugin

Albert-5
Stella,

Here's a crude patch to your problem:

Copy the ParticleAnalyzer.java from the ImageJ source
ij/plugin/filter/ParticleAnalyzer.java and make your own plugin from it
by doing:
        - replace all 'private' by 'public'
        - rename the class to My_Particle_Analyzer or something like that, and
so the name of the file too.

Now compile it, restart ImageJ to update the plugins table and call it
from your plugin as IJ.run("My_Particle_Analyzer");
The totalCount and all other vars will be accessible.

The ImageJ sources are here:
http://rsb.info.nih.gov/ij/download/src/ij134q-src.zip

Albert


Albert Cardona
Institute of Neuroinformatics     Tel : +41 1 635 3052
University/ETH Zurich             Fax : +41 1 635 3053
Winterthurerstrasse 190           acardona (at) ini phys ethz ch
Zurich 8057, Switzerland          www.ini.unizh.ch
Reply | Threaded
Open this post in threaded view
|

Re: Total Particle Count from ParticleAnalyzer plugin

har-wradim
This post was updated on .
In reply to this post by ssim
I realize this is an extremely old thread question, but I just wanted to point out that the solution suggested by Albert-5 is by far "not optimal". So, for anyone coming across this same issue:

The ParticleAnalyzer class is extendible and its saveResults method is overridable. If you want to get the summary statistics themselves you can implement your own class MyParticleAnalyzer extending ParticleAnalyzer and use it as follows:

MyParticleAnalyzer myPA = new MyParticleAnalyzer(...);
myPA.analyze(imp);
int totalCount = myPA.getCount(); // or whatever

Here is an example of the class definition (in MyParticleAnalyzer.java):

import ij.process.*;
import ij.gui.*;
import ij.plugin.filter.*;
import ij.measure.*;

public class MyParticleAnalyzer extends ParticleAnalyzer {
        private int myCount = 0;
        private double myTotalArea = 0;
        private double myMeanArea = 0;

        protected void saveResults(ImageStatistics stats, Roi roi) {
                this.myCount++;
                this.myTotalArea += stats.area;
        }

        public int getCount() {
                return this.myCount;
        }
        public double getTotalArea() {
                return this.myTotalArea;
        }
        public double getMeanArea() {
                if (this.myCount == 0) return Double.NaN;
                return this.myTotalArea / this.myCount;
        }

        public void resetSummaries() {
                this.myCount     = 0;
                this.myTotalArea = 0;
                this.myMeanArea  = 0;
        }

}