Posted by
Jan Eglinger on
Apr 04, 2014; 8:54am
URL: http://imagej.273.s1.nabble.com/Intermittent-Problem-With-Analyze-Particles-Masks-tp5007197p5007199.html
Dear Jan and Dan,
On 04.04.2014, 9:03 AM, BioVoxxel wrote:
> The problem you describe is not a bug. I had the same problems while coding
> the macro of the Advanced Particle Analyzer and some other macros relying
> on the elimination of binary features from an image.
> I am actually wondering that your macro still recognizes "XStart" since in
> the table now the heading is only X and Y (might be due to reverse
> compatibility of those variables)
I think you are confusing two things here:
"XStart" and "YStart" are recorded exactly like this in the Results
table upon checking the "Record starts" option in the particle analyzer
[1]. "X" and "Y" are recorded if you checked "Centroid" in the Set
Measurements dialog [2].
XStart and YStart serve exactly the purpose of providing the coordinates
of a pixel that is *inside* the given particle/ROI.
Therefore I believe this is rather an issue of the macro mode, since
I've had no problems with Dan's strategy of recording XStart and YStart
and then using the wand tool when doing this in Javascript or Java.
>
> The problem is (most likely): in some cases you will have the cetroid of a
> particle actually outside the particle itself if the latter is bend, curved
> or has holes. In such a case your getResult("X",n); gives you an position
> outside the particle and leads to the fact that doWand(X, Y); selects not
> the particle but rather the background. This is fatal in such a case
> because you select the complete background including all particles (with
> potentially the exception of edge touching particles) and delete the whole
> area.
I agree that using the centroid coordinates might not always given the
desired results, as you describe. Using XStart and YStart however should
work.
>
> One workaround which mostly circumvents this problem is the use of the
> particles "territories". You can do this by converting a copy of the image
> into a voronoi map (>Process>Binary>Voronoi). Here, your centroids will
> always be inside the region which correspond to your particles.
>
> 1.) You can now use either this voronoi map directly, apply your wand
> selection, transfer the selection to the image with the binary particles
> and delete everything inside the current selection (might take longer due
> to constant switching between images)
> or
> 2.) You first convert the voronoi map into a binary image, invert it to
> have all regions in white and the lines in black. Then run all your
> elimination processes on the map (by doWand --> Clear) and finally copy
> your original particles image over this map with the >Edit >Paste Control
> set to "Transparent-white". This keeps only the particles with underlying
> white voronoi regions.
>
That's an interesting strategy as well, thanks for sharing.
Cheers,
Jan
[1]:
http://imagej.nih.gov/ij/docs/guide/146-30.html#sub:Analyze-Particles...
[2]:
http://imagej.nih.gov/ij/docs/guide/146-30.html#toc-Subsection-30.7>
> 2014-04-03 20:20 GMT+02:00 Dan McDonald <
[hidden email]>:
>
>> Dear List,
>>
>>
>>
>> I have been having an intermittent problem with using Analyze Particles
>> masks in a macro. My code usually works but every once in a while I get an
>> unexpected result: the contents of the entire mask gets "cleared".
>>
>>
>>
>> I use analyze particles with a size limit and a circularity limit on a
>> thresholded image with "Show" set to mask and "Clear Results" checked.
>>
>>
>>
>> The relevant code is below. It goes through the "Results Table" and
>> "Clears" every entry that has a lower aspect ratio than a specific value.
>> As the Results Table entries are cleared the associated particle is removed
>> from the mask. I can watch the particles that don't meet my shape criteria
>> disappear one by one as the macro executes.
>>
>>
>>
>> run("Analyze Particles...", "size="+size40+"-Infinity
>> circularity=0.00-"+circ40+" show=Masks clear record");
>>
>> for (n=0; n<nResults; n++) {
>>
>> X40c = getResult('XStart',n);
>>
>> Y40c = getResult('YStart',n);
>>
>> aspectRatio40 = getResult('AR',n);
>>
>> doWand(X40c,Y40c);
>>
>> if (aspectRatio40<aspra40) {
>>
>> run("Clear");
>>
>> }
>>
>> }
>>
>>
>> --------------------------
>>
>>
>>
>> Every once in a while (~4 times out of 150 image files) the macro will
>> clear
>> an entire mask. When watching the screen I can see the particles removed
>> as
>> expected but suddenly the entire mask is cleared. The macro seems to
>> continue to run through the Results Table unaware of what it's done to the
>> mask. It seems that only the mask is affected. The debug window at the
>> time of the unexpected clearing is below. I do not see an obvious
>> indication of a problem.
>>
>>
>>
>> The debug window shows the following after it clears the entire content of
>> the mask:
>>
>> aspra40 3
>>
>> n 1820
>>
>> X40c 2786
>>
>> Y40c 9117
>>
>> aspectRatio40 1.6813
>>
>> ---------------
>>
>>
>>
>> Is this a bug in ImageJ or am I doing something wrong?
>>
>>
>>
>> Thank you,
>>
>>
>>
>> Dan
>>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html