# "Spurious disk" detection with ComponentMeasurements

Using this code a third "spurious" disk is detected.

fig = Rasterize[Graphics[{Black, Rectangle[{0, 0}, {1, 1}], White,
Disk[{0.5, 0.5}, 0.1], Disk[{0.75, 0.75}, 0.05]}],
ImageResolution -> 25];
Show[fig,
Graphics[{Red, Circle[#[[1]], #[[2]]]}] & /@ data[[;; , 2]]
]


Quite weird since it arises from a completely black region.

• Interestingly, I get a slightly different result (OS X): i.stack.imgur.com/5Lb8L.png I see this in all versions since 9.0.1. Nov 18 '15 at 13:11
• I am using version 10.1. If you go for ellipsis detection it is not giving that. Nov 18 '15 at 13:13

This happens because:

• The region is not completely black. It has a white margin.

• As I understand, EquivalentDiskRadius does not detect a disk. It takes every component, regardless of shape, and constructs a disk of the same area.

The third circle is in the middle of the white image border, but it is much smaller than it as it must match the area of white pixels.

Why is there a white border?

First, notice that fig is not an Image. It is a Graphics. When you apply an image processing function, it automatically gets converted to an Image. Let us avoid this and create the Image directly using

Rasterize[..., "Image"]


It's easier to see if we invert the image, but you can also see if if you just click it in the notebook and observe the orange border.

What can we do to fix this?

First of all, to set the background of a Graphics, use the Background option instead of placing a rectangle in the background. Graphics have padding and a margin too.

This is what we get if we try it:

There is still a white line at the bottom. This is likely due to rounding things to integer pixel dimensions. The white comes from the DefaultStyleDefinitions of the front end. To fix this, we must set the rasterization background, not the graphics background. If we do this, we might as well remove Background from within Graphics. Now it's good:

To sum up, we needed to:

• Make sure that Rasterize creates an Image
• Set the rasterization background (normally inherited determined by front end settings) to black.

Final code:

fig = Rasterize[
Graphics[{White, Disk[{0.5, 0.5}, 0.1], Disk[{0.75, 0.75}, 0.05]}],
"Image", ImageResolution -> 25, Background -> Black]


• (+1) I have one correction: the Background is inherited not from the styles of the EvaluationNotebook[] but seemingly from the global DefaultStyleDefinitions accessible from Options[\$FrontEndSession, DefaultStyleDefinitions]. Nov 18 '15 at 14:19