how to remove the background from an image ?
Ältere Kommentare anzeigen
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 :)

Akzeptierte Antwort
Weitere Antworten (2)
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));
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)
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



