Digitization errors in small circles

38 views
Skip to first unread message

Adam Hughes

unread,
Feb 17, 2014, 7:35:44 PM2/17/14
to scikit...@googlegroups.com
Hi,

I was trying to measure the circularity as a function of circle radius using the underlying circle object from skimage.draw().  I got some strange results, and tried to outline the exercise as well as the confusing outcome in a notebook.  Essentially, the circularity as a function of particle radius does not seem to converge to 1.0, and in addition, at very small radii, the circularity does not agree with what one would expect from the circularity of a pixel (ie rectangle).

I was hoping that an expert could have a glance at the notebook and offer some feedback?  Hoping that I made an obvious mistake or assertion somewhere.

The notebook actually uses my "pyparty" library that I posted a while back for drawing and storing the descriptors; however, I verified that these are the same descriptors that one gets using skimage.labels() directly (this is not show in the notebook).

Here's the static view:


Thanks.

Juan Nunez-Iglesias

unread,
Feb 17, 2014, 8:14:10 PM2/17/14
to scikit...@googlegroups.com
Your first error is the circularity of a square of side 1, which according to your formula should be 4 * pi * 1 / (4^2) = pi / 4 ≈ 0.785.

I don't know anything about the Canvas object so I'll let others comment on the rest, but clearly this is very dependent on how perimeter is computed: are we computing the perimeter of a polygon with the boundary vertices of the rasterization, or the perimeter along the (square) pixel boundaries, or the *convex* polygon enveloping the rasterized circle? Based on your numbers, I'd bet on one of the first two. Again, I'll let someone else deal with the correctness of the approach. =)

Juan.



--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Adam Hughes

unread,
Feb 17, 2014, 8:40:33 PM2/17/14
to scikit...@googlegroups.com
On Monday, February 17, 2014 8:14:10 PM UTC-5, Juan Nunez-Iglesias wrote:
Your first error is the circularity of a square of side 1, which according to your formula should be 4 * pi * 1 / (4^2) = pi / 4 ≈ 0.785.

Doh!  Duh, right.
 

I don't know anything about the Canvas object so I'll let others comment on the rest, but clearly this is very dependent on how perimeter is computed: are we computing the perimeter of a polygon with the boundary vertices of the rasterization, or the perimeter along the (square) pixel boundaries, or the *convex* polygon enveloping the rasterized circle? Based on your numbers, I'd bet on one of the first two. Again, I'll let someone else deal with the correctness of the approach. =)

Canvas is actually just wrapping skimage.draw and region_props, so it uses the same rasterization that scikit image uses when a user draws a circle.  Here's an example that uses pure scikit:


I'm pretty sure that the results in the canvas are correct for the plotted circularity.  Assuming that the calls to skimage.draw() are correct, would you know which perimeter of the methods you listed would be returned by region_props?
 
Thanks Juan

Juan Nunez-Iglesias

unread,
Feb 17, 2014, 9:32:20 PM2/17/14
to scikit...@googlegroups.com
Adam,


On Tue, Feb 18, 2014 at 12:40 PM, Adam Hughes <hughes...@gmail.com> wrote:
would you know which perimeter of the methods you listed would be returned by region_props?

The region_props documentation describes it pretty well:

**perimeter** : float
    Perimeter of object which approximates the contour as a line
    through the centers of border pixels using a 4-connectivity.

Nothing is more precise than code though:

Maybe this is not the right way to do it. As you mentioned, circularity should probably converge to 1. 

Juan.

Adam Hughes

unread,
Feb 19, 2014, 12:42:19 PM2/19/14
to scikit...@googlegroups.com
Thanks Juan.  Ya I had read that, sorry to make you post the source link.  I guess I just wanted to confirm that what I was seeing made sense and was a product of the drawing routine rather than some sort of error or misinterpretation.  

Juan Nunez-Iglesias

unread,
Feb 19, 2014, 10:17:48 PM2/19/14
to scikit...@googlegroups.com
On Thu, Feb 20, 2014 at 4:42 AM, Adam Hughes <hughes...@gmail.com> wrote:
Thanks Juan.  Ya I had read that, sorry to make you post the source link.  I guess I just wanted to confirm that what I was seeing made sense and was a product of the drawing routine rather than some sort of error or misinterpretation.  

No worries. I'd like to be more help but this is not my code so I'm as familiar with it as you are. If you figure out a better approximation, a pull request would be very welcome! =)

Juan.

Adam Hughes

unread,
Feb 20, 2014, 12:56:27 PM2/20/14
to scikit...@googlegroups.com
Thanks.  I suspect that the algorithm you guys have is probably a good solution for the encoding, and the fact that it gets a bit fuzzy at very low pixel count is just the price one pays for having a very applicable encoding algorithm.  I noticed that imageJ's encoding outputs the same area and perimiter by the way, but they apply some sort of the correction before outputting circularity.  If I get a chance to see what the circularity correction is; if it's not too hard, maybe I can put in a PR for a new descriptor called circularity to circularity_adjusted.



--
You received this message because you are subscribed to a topic in the Google Groups "scikit-image" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scikit-image/vjOMjwaWwg4/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to scikit-image...@googlegroups.com.

Juan Nunez-Iglesias

unread,
Feb 20, 2014, 8:25:22 PM2/20/14
to scikit...@googlegroups.com
I saw your post on the ImageJ list! =) imho that PR would be most welcome.



--
You received this message because you are subscribed to the Google Groups "scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image...@googlegroups.com.

Adam Hughes

unread,
Feb 20, 2014, 8:55:10 PM2/20/14
to scikit...@googlegroups.com
Thanks Juan.  I'm trying to write a section for a paper about imaging nanoparticles and one of the key criteria is finding the lower limit in resolution at which it's still safe to trust the encoding routines, otherwise I wouldn't be so pedantic.  I'll try to followup and see if I can get a PR like that in.  Hope it's kosher to cross post with this stuff.
Reply all
Reply to author
Forward
0 new messages