필터 지우기
필터 지우기

how to remove the background from an image ?

조회 수: 65 (최근 30일)
Eric Vincent
Eric Vincent 2021년 11월 1일
답변: Chunru 2021년 11월 1일
i want to remove the background from the image so i can get the grapes only ... but i don't know how to... pls help :) .. i attached the image..... thanks in advance :)

채택된 답변

Image Analyst
Image Analyst 2021년 11월 1일
편집: Image Analyst 2021년 11월 1일
Very easy. Just use the Color Thresholder on the Apps tab.
  1. Load the Color Thresholderapp
  2. Load the image
  3. choose hsv color space.
  4. Adjust thresholds for green
  5. Click the Export Function button.
See attached m-file
If you want, you can use find() or regionprops() to find the bounding box of the mask and crop the image to the bounding box.

추가 답변 (2개)

yanqi liu
yanqi liu 2021년 11월 1일
clc; clear all; close all;
im = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/785503/image.jpeg');
jm = rgb2lab(im);
vm = mat2gray(jm(:,:,3));
bw = im2bw(vm);
im2 = im;
im2(~cat(3,bw,bw,bw)) = 255;
figure; imshow(mat2gray(im2));

Chunru
Chunru 2021년 11월 1일
There are many image segmentation techniques availble in image processing toolbox. Search "image segmentation" in documentation. Below is one technique:
RGB = imread("image.jpeg");
imshow(RGB);
L = superpixels(RGB, 500);
% foreground
f = drawrectangle(gca, 'Position', [2000 1000 1500 600], 'Color', 'g');
foreground = createMask(f, RGB);
% background
b = drawrectangle(gca, 'Position', [10 10 4500 600], 'Color', 'r');
background = createMask(b, RGB);
% Segmentation
BW = lazysnapping(RGB, L, foreground, background);
RGBseg = RGB;
RGBseg(repmat(~BW, [1 1 3])) = 0;
figure
imshow(RGBseg)

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by