original_img = imread('cropped_image_grey_jpg.jpg');
gray_img = im2gray(original_img);
bilatSpatialSigmas = [1, 2];
unsharpAmounts = [0.5, 1];
clipLimits = [0.01, 0.03];
sensitivities = [0.9, 0.95];
totalCombinations = length(wienerSizes) * length(bilatSpatialSigmas) * length(unsharpAmounts) * length(clipLimits) * length(sensitivities);
subplotRows = ceil(sqrt(totalCombinations));
subplotCols = ceil(totalCombinations / subplotRows);
for wienerSize = wienerSizes
for bilatSpatialSigma = bilatSpatialSigmas
for unsharpAmount = unsharpAmounts
for clipLimit = clipLimits
for sensitivity = sensitivities
combinationCounter = combinationCounter + 1;
clahe_img = adapthisteq(gray_img, 'ClipLimit', clipLimit, 'Distribution', 'rayleigh');
smoothedImg = wiener2(clahe_img, [wienerSize wienerSize]);
smoothedImg = imbilatfilt(smoothedImg, 'DegreeOfSmoothing', bilatSpatialSigma^2 * 2);
sharpenedImg = imsharpen(smoothedImg, 'Radius', 2, 'Amount', unsharpAmount);
[centersBright, radiiBright] = imfindcircles(sharpenedImg, [8 100], 'ObjectPolarity', 'bright', 'Sensitivity', sensitivity, 'EdgeThreshold', 0.1);
numBrightCircles = size(centersBright, 1);
[centersDark, radiiDark] = imfindcircles(sharpenedImg, [8 100], 'ObjectPolarity', 'dark', 'Sensitivity', sensitivity, 'EdgeThreshold', 0.1);
numDarkCircles = size(centersDark, 1);
subplot(subplotRows, subplotCols, combinationCounter);
viscircles(centersBright, radiiBright, 'EdgeColor', 'b');
viscircles(centersDark, radiiDark, 'EdgeColor', 'r');
titleStr = sprintf('Wiener: %d, Bilat: %.1f, Unsharp: %.1f, Clip: %.2f, Sens: %.2f\nBright: %d, Dark: %d', ...
wienerSize, bilatSpatialSigma, unsharpAmount, clipLimit, sensitivity, ...
numBrightCircles, numDarkCircles);
title(titleStr, 'Interpreter', 'none', 'FontSize', 8);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);