# Detection of inhomogeneous illuminated object

Here is an image with an inhomogeneous illuminated disk shaped object in the center. It is illuminated from left. Therefore on the left it is brighter and at right it is dark.

By eye one can guess where the edges of the object are.

How would you detect this oject's center and radius?

What I tried is not very successfull:

img = Import["https://i.stack.imgur.com/RKFDd.png"];

binimg = DeleteSmallComponents[Binarize[img, 0.45], 70] pts = Values@ComponentMeasurements[binImg, {"Centroid", "EquivalentDiskRadius"}]

{{{80.99, 106.566}, 18.2557}}

18.2557

center = pts[[1, 1]]

{80.99, 106.566}

Show[img, Graphics[{Red, Point[center]}], Graphics[{Red, Circle[center, r]}]] The center is too far left and the radius is too large.

Manually I would draw the following circle: I don't think you can get a perfectly unbiased estimate of the center you're interested in. If you look at a 3d plot of the image data, it's clear that the "disk" isn't symmetric, and probably overexposed on the light side:

img = ColorConvert[Import["https://i.stack.imgur.com/RKFDd.png"],
"Grayscale"]
ListPlot3D[ImageData[img], PlotRange -> All] I think the best (and simplest) thing to do would be to use a linear filter kernel with a similar shape, i.e. a Gaussian derivative kernel:

Image[Rescale@GaussianMatrix[25, {0, 1}]] I would expect that filtering the image with a filter kernel that looks like this should give the highest value where the "bright sides" and the "dark sides" of the filter kernel and the object match:

match = ImageAdjust@ColorNegate@GaussianFilter[img, 25, {0, 1}] the bright peak looks close to the position you're interested in:

center = PixelValuePositions[match, "Max"][]
HighlightImage[img, Circle[center, 25]] • Perfect solution. Thank you very much for the answer.
– mrz
Mar 13, 2017 at 17:20