Effacer les filtres
Effacer les filtres

how to remove the background from an image ?

65 vues (au cours des 30 derniers jours)
Eric Vincent
Eric Vincent le 1 Nov 2021
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 :)

Réponse acceptée

Image Analyst
Image Analyst le 1 Nov 2021
Modifié(e) : Image Analyst le 1 Nov 2021
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.

Plus de réponses (2)

yanqi liu
yanqi liu le 1 Nov 2021
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 le 1 Nov 2021
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)

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by