Eliminate the background of image
Show older comments
Hi all.
I'm beginner in Matlab. I have this picture. I want image inside the circle one. How do I can eliminate the background?

3 Comments
Image Analyst
on 17 May 2015
What does "eliminate" mean to you? Do you want to crop out that small chunk to its own small image? Do you want everything except for that black region to be set to some contrasting gray level, like white or some gray level that is not in that region?
Maximum
on 17 May 2015
Image Analyst
on 17 May 2015
Which one?!?!
Crop? Set to white? Set to some other gray level? Be super explicit. Maybe even attach a picture of your desired output.
Answers (1)
Image Analyst
on 17 May 2015
Maximum, I still don't know what you want. How about cropping like I suggested? Does this work for you?
clc;
workspace; % Make sure the workspace panel with all the variables is showing.
format long g;
format compact;
fontSize = 18;
%===============================================================================
% Read in a demo image.
folder = pwd;
baseFileName = 'try1.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
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% If it's really color, then convert to gray scale.
grayImage = grayImage(:,:,2);
end
% Display the original image.
subplot(1, 2, 1);
imshow(grayImage);
axis on;
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Let's crop the image
croppedImage = imcrop(grayImage, [275, 218, 42, 42]);
subplot(1, 2, 2);
imshow(croppedImage);
axis on;
title('Cropped Image', 'FontSize', fontSize);

Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!