I have the following image
where bright circular shaped objects are seen. The image
has usually an inhomogeneous background and the objects have different sizes and brightness's.
The aim is to remove the background noise and to detect all object's positions.
How can that be done best?
My solution for the example image
is:
fileNameOpen = SystemDialogInput["FileOpen"];
image = Import[fileNameOpen]
background = ImageConvolve[image, GaussianMatrix[7]];
subImage = Image[ImageData[image] - ImageData[background]];
t = FindThreshold[subImage, Method -> "Entropy"];
binImg = Binarize[subImage, t];
binImg = DeleteSmallComponents[binImg, 1];
resultImage =
Show[image,
Graphics[{Red, Thick,
Circle[#[[1]], #[[2]]] & /@
ComponentMeasurements[
ImageMultiply[image, binImg], {"Centroid",
"EquivalentDiskRadius"}][[All, 2]]}]]
fileNameSave = SystemDialogInput["FileSave"];
Export[fileNameSave, resultImage];
That gives as output:
The problem is that I have to adjust manually the radius of GaussianMatrix
and the number in DeleteSmallComponents
. Their optimum values depend also on the Method
used in FindThreshold
(e.g. "MinimumError"
can also be used") .