ParticleAnalyzer output in Java does not agree with program

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

ParticleAnalyzer output in Java does not agree with program

Cspr
Hey everyone.

My problem is this. Using the macro:

IJ.run("Analyze Particles...", "size=0.15-Infinity circularity=0-1 show=Nothing display exclude clear include record add");

I'm greeted with the ROI manager and the results of applying these inputs. This is called from within Java, and the problem is that the results displayed (area, min_max, std_dev and so forth) is NOT the same that ImageJ gives back when using ImageJ. That is to say, when using ImageJ like you would any other program following the exact same steps results in something different than what results from using above command (with appropriate pre-steps before to the two procedures are identical up until that point).

For instance filling in the size field in the Analyze Particle dialog as 0.15-infinity is VERY different from the above command with size set as "size=0.15-999999". Using the first ("0.15-infinity") gives me back 87 measurements, whereas the exact same command called from within Java gives me 411 measurements.

I'm workin on images where the scale is 36 by 36 microns or 512 x 512 image. I think its a scale or calibration issue because everything up until that point is exactly what it should be.

Can anyone shed some light on what the problem is?

Thanks :)
Reply | Threaded
Open this post in threaded view
|

Re: ParticleAnalyzer output in Java does not agree with program

Michael Schmid
Hi Danish anonymous,

your description is not really clear to me. Do you have a macro  
(ImageJ macro language), a plugin (Java) or JavaScript code?
In a plugin,
   IJ.run("Analyze Particles...", options);
should do exactly the same as the macro command
   run("Analyze Particles...", options);
and the same as doing it manually.

All three should take the calibration into account. I have tried it  
with a macro (there is hardly any difference between IJ.run and macro  
"run") and found no such problem.

Maybe the reason for your problems is processing the wrong image? To  
avoid this in a plugin, in a plugin you could try the command
   IJ.run(ImagePlus imp, String command, String options)


Michael
________________________________________________________________

On 1 Mar 2010, at 20:10, Cspr wrote:

> Hey everyone.
>
> My problem is this. Using the macro:
>
> IJ.run("Analyze Particles...", "size=0.15-Infinity circularity=0-1
> show=Nothing display exclude clear include record add");
>
> I'm greeted with the ROI manager and the results of applying these  
> inputs.
> This is called from within Java, and the problem is that the results
> displayed (area, min_max, std_dev and so forth) is NOT the same  
> that ImageJ
> gives back when using ImageJ. That is to say, when using ImageJ  
> like you
> would any other program following the exact same steps results in  
> something
> different than what results from using above command (with appropriate
> pre-steps before to the two procedures are identical up until that  
> point).
>
> For instance filling in the size field in the Analyze Particle  
> dialog as
> 0.15-infinity is VERY different from the above command with size  
> set as
> "size=0.15-999999". Using the first ("0.15-infinity") gives me back 87
> measurements, whereas the exact same command called from within  
> Java gives
> me 411 measurements.
>
> I'm workin on images where the scale is 36 by 36 microns or 512 x  
> 512 image.
> I think its a scale or calibration issue because everything up  
> until that
> point is exactly what it should be.
>
> Can anyone shed some light on what the problem is?
>
> Thanks :)
Reply | Threaded
Open this post in threaded view
|

Re: ParticleAnalyzer output in Java does not agree with program

Cspr
Thanks for your reply.

In the following ParticleAnalyzer has been abbreviated to "PartAn", and Analyzer will be abbreviated to "An" to circumvent the spam detector.

Let me clarify for a moment.
I work on only one picture in this context, so the chance of messing that up doesn't seem likely. I figured out that a major problem I had was not setting the scale right (from pixel to microns does make a difference) and now the call:

IJ.run(imp3, "AnalyzeParticles...", "size=0.15-999999.00 circularity=0-1 show=Nothing display exclude clear include record add");

does indeed work, i.e. it produces the same result as when useing ImageJ as any other program using identical steps. This is good news, however when I try to initialize a ParticleAnalyzer object using:

PartAn pa = new PartAn(options, measurements, null, 0.15, Double.POSITIVE_INFINITY);

with options as:

int options = PartAn.SHOW_RESULTS                     +
                  PartAn.EXCLUDE_EDGE_PARTICLES +
                  PartAn.CLEAR_WORKSHEET           +
                  PartAn.INCLUDE_HOLES                +
                  PartAn.RECORD_STARTS               +
                  PartAn.ADD_TO_MANAGER;

and measurements as:

int measurements = An.STD_DEV + An.MIN_MAX + An.MEAN + An.AREA;

The problem persists. The result-table shows an incredible 411 measurements. I know for a fact the problem is the minSize - the smallest particle size in pixels i.e. the 0.15 parameter. However when in microns I need some form of conversion between them to make it work.

My only solution suggestion was to take the microns-to-pixel ratio (which is something like 14) and multiply it by 0.15 to get the appropriate scale. This did not work.

Can you spot the error?

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: ParticleAnalyzer output in Java does not agree with program

Michael Schmid
Hi,

ok, you are doing something different, not IJ.run, and not a macro.

See the documentation of the ParticleAnalyzer:
   @param minSize the smallest particle size in pixels
   @param maxSize the largest particle size in pixels

The ImageJ command uses scaled units for the size range unless you  
select 'Pixel Units'.

You can have a look at what ParticleAnalyzer.java does with the input  
in its showDialog method:
If you don't use 'Pixel Units' and the image has a calibration,  
minSize and maxSize are divided by unitSquared, which is  
cal.pixelWidth*cal.pixelHeight ('cal' is the Calibration of the  
ImagePlus). So you will have to do the same if you want to convert  
scaled units into pixel units.

Michael
________________________________________________________________

On 2 Mar 2010, at 12:55, Cspr wrote:

> Thanks for your reply.
>
> In the following ParticleAnalyzer has been abbreviated to "PartAn",  
> and
> Analyzer will be abbreviated to "An" to circumvent the spam detector.
>
> Let me clarify for a moment.
> I work on only one picture in this context, so the chance of  
> messing that up
> doesn't seem likely. I figured out that a major problem I had was not
> setting the scale right (from pixel to microns does make a  
> difference) and
> now the call:
>
> IJ.run(imp3, "AnalyzeParticles...", "size=0.15-999999.00  
> circularity=0-1
> show=Nothing display exclude clear include record add");
>
> does indeed work, i.e. it produces the same result as when useing  
> ImageJ as
> any other program using identical steps. This is good news, however  
> when I
> try to initialize a ParticleAnalyzer object using:
>
> PartAn pa = new PartAn(options, measurements, null, 0.15,
> Double.POSITIVE_INFINITY);
>
> with options as:
>
> int options = PartAn.SHOW_RESULTS                     +
>                   PartAn.EXCLUDE_EDGE_PARTICLES +
>                   PartAn.CLEAR_WORKSHEET           +
>                   PartAn.INCLUDE_HOLES                +
>                   PartAn.RECORD_STARTS               +
>                   PartAn.ADD_TO_MANAGER;
>
> and measurements as:
>
> int measurements = An.STD_DEV + An.MIN_MAX + An.MEAN + An.AREA;
>
> The problem persists. The result-table shows an incredible 411  
> measurements.
> I know for a fact the problem is the minSize - the smallest  
> particle size in
> pixels i.e. the 0.15 parameter. However when in microns I need some  
> form of
> conversion between them to make it work.
>
> My only solution suggestion was to take the microns-to-pixel ratio  
> (which is
> something like 14) and multiply it by 0.15 to get the appropriate  
> scale.
> This did not work.
>
> Can you spot the error?
>
> Thank you.