Eliminate the background of image
3 ビュー (過去 30 日間)
古いコメントを表示
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150212/image.jpeg)
3 件のコメント
Image Analyst
2015 年 5 月 17 日
Which one?!?!
Crop? Set to white? Set to some other gray level? Be super explicit. Maybe even attach a picture of your desired output.
回答 (1 件)
Image Analyst
2015 年 5 月 17 日
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);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176905/image.jpeg)
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!