Function: imfindcircles detects false circles.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Meghana Dinesh
le 3 Avr 2015
Commenté : Meghana Dinesh
le 4 Avr 2015
I have come across this a few times. The function imfindcircles detects false circles (like at the corners shown below) even when there is no pixel intensity variation at those places. What could the reason be? How can I avoid this? Are there any other suitable methods to find circles apart from this?
I have attached an example image.
This is my code:
clear all;
close all;
A = imread('synthetic_img3.png');
BW1 = bwmorph(im2bw(A),'close');
figure;
imshow(BW1)
[centers,radii] = imfindcircles(BW1,[5,500]);
figure, imshow(BW1);
hold on
viscircles(centers, radii,'EdgeColor','b');
The resulting output:
0 commentaires
Réponse acceptée
Image Analyst
le 3 Avr 2015
If you want to segment out the small circles, you could also use thresholding and size filtering (use imclearborder and bwareaopen) instead of imfindcircles(). Then you could do things like find area, perimeter, location, etc. with regionprops().
3 commentaires
Image Analyst
le 4 Avr 2015
Meghana, try this. Change the folder and filename so that it will read in your image.
% Demo to measure area and centroid of small circles..
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 14;
%===============================================================================
% Read in a standard MATLAB gray scale demo image.
folder = 'D:\temporary stuff';
baseFileName = 'synthetic_img3.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Create a binary image
binaryImage = grayImage > 127;
% Get rid of white border touching the edge and center disc.
smallBlobs = binaryImage - bwareaopen(binaryImage, 10000);
% Display the binary image.
subplot(2, 2, 2);
imshow(smallBlobs, []);
title('Small blobs', 'FontSize', fontSize);
% Get rid of scratches, and other black things in the white blobs
smallBlobs = bwconvhull(smallBlobs, 'objects');
% Display the binary image.
subplot(2, 2, 3);
imshow(smallBlobs, []);
title('Small blobs', 'FontSize', fontSize);
% Label the blobs
labeledImage = bwlabel(smallBlobs);
measurements = regionprops(labeledImage, 'Area', 'Centroid');
% Get all the areas from a structure into a single array.
allAreas = [measurements.Area]
% Now, I'll show you how to get centroids.
% We can get the centroids of ALL the blobs into 2 arrays,
% one for the centroid x values and one for the centroid y values.
allBlobCentroids = [measurements.Centroid];
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
helpdlg('Done with demo. Look in command window for areas.');
Plus de réponses (1)
Anand
le 3 Avr 2015
Looks like the sensitivity is too high. I reduced the sensitivity from the default (0.85) to 0.8 and that helped get rid of the spurious circles.
[center, radii] = imfindcircles(BW1,[5 500],'Sensitivity',0.8);
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!