How to remove background from an image?

I want to know how to remove background from an image and edge detection of the rest of the image

 採用された回答

Meshooo
Meshooo 2014 年 9 月 24 日

2 投票

There are many ways do remove background. If you have a colored image, then you can try this
If you have a gray scale image, then you can try this
Hope it helps you.
Meshoo

6 件のコメント

Opencv
Opencv 2014 年 9 月 24 日
Coooooool thanks a lot !!! you are a life saver !!!
Image Analyst
Image Analyst 2014 年 9 月 24 日
It's possible neither of those will help you. At best, it can't be determined until you show your image. If your question is not really answered, then start another discussion and post your image and say what you consider to be background or not.
You can do background subtraction (for fluorescence and x-ray), background division (most ordinary situations), or background replacement (for video), depending on your situation. If you don't use the correct method, you'll get nonsense.
poongothai rajan
poongothai rajan 2014 年 12 月 3 日
sir this is my image . i have extract color feature from human body.for that i need to remove background.can u give me the code for that.
Pallavi Rawat
Pallavi Rawat 2022 年 1 月 6 日
How can I remove the white background and have the hammer be displayed with ROI of its shape and could be dragged and dropped anywhere on the screen?
Vasudev
Vasudev 2023 年 2 月 16 日
編集済み: Vasudev 2023 年 2 月 16 日
Will this code run and display for all types of images, or any specific kind of images?
DGM
DGM 2023 年 5 月 5 日
What code?
The general answer is obviously no. You are not going to find any code which will universally discern intent and isolate any arbitrary and undefined foreground region from any arbitrary and undefined background region in any one of countless unspecified "types" of images, many of which MATLAB can't even open.
The more magical properties a solution requires, the more certain it is to not exist.

サインインしてコメントする。

その他の回答 (2 件)

Deepak Gala
Deepak Gala 2017 年 8 月 4 日

0 投票

3 件のコメント

Diah Junaidi
Diah Junaidi 2018 年 8 月 11 日
I got this error: _ *Undefined function 'checkCC' for input arguments of type 'struct'.
Error in regionprops (line 180) checkCC(CC);
Error in bwpropfilt (line 63) props = regionprops(CC, attrib);
Error in bwareafilt (line 34) bw2 = bwpropfilt(bw, 'area', p, direction, conn);
Error in testbgremove (line 9) mask = bwareafilt(mask,1);*_
Here the code:
if true
img = imread('C:\Users\diahj\OneDrive\Pictures\Data Test\11.jpg');
gray = rgb2gray(img);
SE = strel('Disk',1,4);
morphologicalGradient = imsubtract(imdilate(gray, SE),imerode(gray, SE));
mask = im2bw(morphologicalGradient,0.03);
SE = strel('Disk',3,4);
mask = imclose(mask, SE);
mask = imfill(mask,'holes');
mask = bwareafilt(mask,1);
notMask = ~mask;
mask = mask | bwpropfilt(notMask,'Area',[-Inf, 5000 - eps(5000)]);
showMaskAsOverlay(0.5,mask,'r');
h = impoly(imgca,'closed',false);
fcn = makeConstrainToRectFcn('impoly',get(imgca,'XLim'),get(imgca,'YLim'));
setPositionConstraintFcn(h,fcn);
gray = rgb2gray(img);
gray(~mask) = 255;
imshow(gray)
%(The image is of class uint8; 255 is the value of "white" for uint8 images.)
% Break down and mask the planes:
r = img(:,:,1);
g = img(:,:,2);
b = img(:,:,3);
r(~mask) = 255;
g(~mask) = 255;
b(~mask) = 255;
% Reconstruct the RGB image:
img = cat(3,r,g,b);
imshow(img)
shellMask = createShellMask(h,'thickness',3);
imshow(shellMask);
r = regionfill(r,shellMask);
g = regionfill(g,shellMask);
b = regionfill(b,shellMask);
img = cat(3,r,g,b);
imshow(img)
end
Vidhika Sirwani
Vidhika Sirwani 2020 年 5 月 4 日
gives an error..
undefined variable showMaskAsOverlay
Image Analyst
Image Analyst 2020 年 5 月 4 日
Try this:
% Display mask with 50% transparency over the "gray" image.
imshow(gray);
hold on;
h = image(255 * mask);
h.AlphaData = 0.5;

サインインしてコメントする。

shaadinama
shaadinama 2023 年 5 月 4 日

0 投票

There are several ways to remove the background from an image and perform edge detection on the remaining object. Here are some methods:
Using a photo editing software like Adobe Photoshop or GIMP: You can use the selection tools like Magic Wand, Lasso, or Quick Selection to select the background and delete it. Then, use the Edge Detection filter or tool to highlight the edges of the remaining object.
Using online tools: There are many free online tools like remove.bg, Clipping Magic, or Canva that allow you to remove the background of an image automatically. After removing the background, you can use the image editor in these tools to apply edge detection on the remaining object.

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2014 年 9 月 24 日

コメント済み:

DGM
2023 年 5 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by