how can remove circle from an image?

14 views (last 30 days)
hi I have this image
how can I remove the circles that are not fill?? when I use imfiil the images merge but I want to obtain this image as result:

Accepted Answer

Image Analyst
Image Analyst on 11 Oct 2014
Simple. Just ask regionprops for objects whos Euler number is 1 and use ismember to extract only those solid blobs.
measurements = regionprops(labeledImage, 'EulerNumber');
allEulerNumbers = [measurements.EulerNumber]
blobsToKeep = find(allEulerNumbers == 1)
outputImage = ismember(labeledImage, blobsToKeep) > 0; % Retain only these
Here's the full blown demo:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 36;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a standard MATLAB color demo image.
folder = 'C:\Users\sara\Documents\Temporary';
baseFileName = 'fff.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
% greenChannel = rgbImage(:, :, 2);
% blueChannel = rgbImage(:, :, 3);
% Get the binaryImage
binaryImage = redChannel > 40;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Label the image
labeledImage = bwlabel(binaryImage);
% Ask for Euler number
measurements = regionprops(labeledImage, 'EulerNumber');
allEulerNumbers = [measurements.EulerNumber]
blobsToKeep = find(allEulerNumbers == 1)
outputImage = ismember(labeledImage, blobsToKeep) > 0; % Retain only these
% Display the image.
subplot(2, 2, 3);
imshow(outputImage);
axis on;
title('Solid objects only', 'FontSize', fontSize);

More Answers (1)

SK
SK on 10 Oct 2014
Edited: SK on 10 Oct 2014
If thickness of circle boundary is exactly 1 pixel, then its easy.
Loop over each point. For any point, (i,j) there are four pairs of surrounding points:
left (i, j-1) right (i, j+1)
top (i-1, j) bottom (i+1, j)
top-left (i-1, j-1) bottom-right (i+1, j+1)
top-right (i-1, j+1) bottom-left (i+1, j-1)
If there is at least one pair with both points black AND at least one pair with both points white, then make the point black.
Maybe you can extend the idea to circles whose boundary has > 1 thickness.

Community Treasure Hunt

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

Start Hunting!