find circles with different levels of blur

23 visualizzazioni (ultimi 30 giorni)
Ratul Sabui
Ratul Sabui il 6 Apr 2024 alle 12:43
Commentato: Ratul Sabui il 19 Apr 2024 alle 13:57
I have an image with circles of different blur levels. I need to count the circles. What is the best way to remove the blurring and find the distinct circles(even the blurred ones). I have tried something but I need to know if theres a better way to do it.
Thanks in advance.
There are both dark circles and bright circles. Heres the image(the original is a tiff but I have converted it to jpeg for viewing)
Heres the jpeg:
As of now I have tried CLAHE:
clahe_img6 = adapthisteq(gray_img,'ClipLimit',0.06,'Distribution','rayleigh');
resultant image:
followed by weiner filters
smoothedImg = wiener2(img,[5 5]);
The resultant image is something like this:

Risposte (1)

Garmit Pant
Garmit Pant il 16 Apr 2024 alle 11:17
Modificato: Garmit Pant il 16 Apr 2024 alle 11:18
Hello Ratul Sabui
From what I gather, you're tackling the problem of identifying and counting circles in an image that vary in clarity due to different levels of blurring. Your approach using CLAHE (Contrast Limited Adaptive Histogram Equalization) followed by a Wiener filter is a solid strategy, as it aims to enhance the contrast and reduce the noise, respectively. Further image processing steps should be employed in addition to the ones that you have already used to enhance the quality of detection of the circles.
The following image processing techniques should be applied to the image prior to detecting the circles:
  • Step 1: Preprocessing: Continue using CLAHEadapthisteq to improve the contrast of the image, which is crucial for bringing out the edges of the blurred circles. However, consider experimenting with differentClipLimitvalues to see if a lower or higher limit yields better results for your specific image.
  • Step 2: Noise Reduction: Instead of solely relying on the Wiener filterwiener2, you can apply a bilateral filter using “imbilatfiltbefore or after the Wiener filter. The bilateral filter is effective at noise reduction while preserving edges, which might help in retaining the outlines of even the most blurred circles.
  • Step 3: Edge Enhancement: After noise reduction, applying an edge enhancement technique, such as using the unsharp mask imsharpenor a high-pass filter using “imfilter, can further delineate the circles from the background, making them more detectable by circle detection algorithms.
After applying the above image processing techniques, the circles can be detected using the Hough Circle Transform for detecting circles using the MATLAB function “imfindcircles. Given the variations in blur levels, you should try adjusting the sensitivity and edge threshold parameters to capture both clear and blurred circles effectively.
The following code snippet applies all the above steps and also iterates over some sample values of the parameters of the functions listed above to demonstrate the variations in detections based on the values of the parameters.
original_img = imread('cropped_image_grey_jpg.jpg');
gray_img = im2gray(original_img);
% Define parameter ranges for experimentation
wienerSizes = [3, 5]; % Window sizes for Wiener filter
bilatSpatialSigmas = [1, 2]; % Spatial-domain standard deviation for Bilateral filter
unsharpAmounts = [0.5, 1]; % Strength of sharpening for Unsharp Mask
clipLimits = [0.01, 0.03]; % ClipLimit values for CLAHE
sensitivities = [0.9, 0.95]; % Sensitivity values for circle detection
% Prepare for grid visualization
totalCombinations = length(wienerSizes) * length(bilatSpatialSigmas) * length(unsharpAmounts) * length(clipLimits) * length(sensitivities);
subplotRows = ceil(sqrt(totalCombinations));
subplotCols = ceil(totalCombinations / subplotRows);
figure;
combinationCounter = 0;
for wienerSize = wienerSizes
for bilatSpatialSigma = bilatSpatialSigmas
for unsharpAmount = unsharpAmounts
for clipLimit = clipLimits
for sensitivity = sensitivities
combinationCounter = combinationCounter + 1;
% Step 1: Apply CLAHE with current ClipLimit
clahe_img = adapthisteq(gray_img, 'ClipLimit', clipLimit, 'Distribution', 'rayleigh');
% Step 2: Apply Wiener Filter with current size
smoothedImg = wiener2(clahe_img, [wienerSize wienerSize]);
% Step 3: Apply Bilateral Filter with current spatial sigma
smoothedImg = imbilatfilt(smoothedImg, 'DegreeOfSmoothing', bilatSpatialSigma^2 * 2);
% Step 4: Apply Unsharp Mask with current amount
sharpenedImg = imsharpen(smoothedImg, 'Radius', 2, 'Amount', unsharpAmount);
% Detect bright circles with current Sensitivity
[centersBright, radiiBright] = imfindcircles(sharpenedImg, [8 100], 'ObjectPolarity', 'bright', 'Sensitivity', sensitivity, 'EdgeThreshold', 0.1);
numBrightCircles = size(centersBright, 1); % Count of bright circles
% Detect dark circles with current Sensitivity
[centersDark, radiiDark] = imfindcircles(sharpenedImg, [8 100], 'ObjectPolarity', 'dark', 'Sensitivity', sensitivity, 'EdgeThreshold', 0.1);
numDarkCircles = size(centersDark, 1); % Count of dark circles
% Visualize
subplot(subplotRows, subplotCols, combinationCounter);
imshow(sharpenedImg);
hold on; % Keep the image, overlay circles
viscircles(centersBright, radiiBright, 'EdgeColor', 'b');
viscircles(centersDark, radiiDark, 'EdgeColor', 'r');
hold off; % Release the hold to ensure next plots are separate
% Title with counts and parameters
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);
end
end
end
end
end
% Adjust subplot spacing
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]); % Maximize figure to fit all subplots
Following is a subset of the outputs generated by the code snippet:
I would suggest you refer to the links to the MathWorks documentation given below:
  1. imfindcirclesfunction- https://www.mathworks.com/help/releases/R2022b/images/ref/imfindcircles.html
  2. imbilatfilt” function – https://www.mathworks.com/help/releases/R2022b/images/ref/imbilatfilt.html
  3. imsharpen” function: https://www.mathworks.com/help/releases/R2022b/images/ref/imsharpen.html
Hope you find the above explanation and suggestions useful!
  1 Commento
Ratul Sabui
Ratul Sabui il 19 Apr 2024 alle 13:57
Thanks for the suggestions. Will definitely try out sharpening.

Accedi per commentare.

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by