Function: imfindcircles detects false circles.

조회 수: 1 (최근 30일)
Meghana Dinesh
Meghana Dinesh 2015년 4월 3일
댓글: Meghana Dinesh 2015년 4월 4일
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:

채택된 답변

Image Analyst
Image Analyst 2015년 4월 3일
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
Image Analyst
Image Analyst 2015년 4월 4일
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.');
Meghana Dinesh
Meghana Dinesh 2015년 4월 4일
Thanks a lot for the detailed explanation. Perfectly deals with my issue.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Anand
Anand 2015년 4월 3일
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);
  댓글 수: 1
Meghana Dinesh
Meghana Dinesh 2015년 4월 4일
It's completely white there. There is absolutely no variation in the pixel intensity. What made it locate circles there?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by