How can I remove the boundary(only) of this image?
11 views (last 30 days)
Show older comments
KALYAN ACHARJYA
on 14 May 2017
Commented: KALYAN ACHARJYA
on 16 May 2017
Please help to remove the circular boundary of this image ( I know using for loop wrapping in all side). I expect some other interesting techniques.
Thanks in Advance.
0 Comments
Accepted Answer
Image Analyst
on 14 May 2017
It's very simple and is basically 3 or 4 steps. Basically threshold and fill the mask so you get a solid disk. Then shrink it a bit with imerode() to exclude the outer ring. Then everything outside that ring in your original image should be set to white. Here's a full demo.
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 = 20;
%===============================================================================
% Read in a gray scale demo image.
folder = pwd;
baseFileName = 'image11.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
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.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% Threshold the image
binaryImage = grayImage < 128;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Fill the image
binaryImage = imfill(binaryImage, 'holes');
% Erode it a bit to come within the couter circle.
se = strel('disk', 5, 0); % Make round structuring element.
binaryImage = imerode(binaryImage, se);
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% "Erase" outside the mask by setting the original image to white.
grayImage(~binaryImage) = 255;
% Display the image.
subplot(2, 2, 4);
imshow(grayImage, []);
title('Final Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
3 Comments
Image Analyst
on 15 May 2017
Because it's not binary. It is not of type logical. It is a gray scale image with two levels: 0 and 255. To turn it into a binary/logical image from a uint8 image I thresholded it.
More Answers (1)
MathReallyWorks
on 14 May 2017
Hello Dear,
As you mentioned that you already know about loop warping on all sides, have a look at my approach. I hope you will find it interesting.
-> Convert the image from input image to feature space using a radial basis function by using the centre of the outer boundary as the basis vector.
-> Above process will give you some set of points at some particular distances.
-> For each distances find out the number of points(N) of input space which are mapped as a single point in feature space.
-> If the number of points(N) at a particular distance is greater than some threshold then remove those points from the matrix of Image.
-> Now plot the image again, this will not have the outer boundary.
Warning: Above method may remove some points which are within the outer boundary, so choose your threshold wisely.
The reason RBF is used, it maps all points which are at equidistant from basis vector into a point. So this will transform the outer boundary(which is a circle) into a point. From the image, we can say that only outer boundary will have maximum number of points at some point in feature space.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!