MATLAB Answers

how to remove specific area of an image

5 views (last 30 days)
hi everyone!
i want to remove only the specific area of my image i.e the floor (but not the whole floor).
for more explanation i attach the image actually i want to remove only the portions of my image that i marked with X sign and the rest of the grass in the middle and the humans remains still there in the image.
Can anyone help in code of doing the above metnion thing. i will be really thankful for that.
Note: background subtraction will not going to solve my problem i need something else more efficent and that fullfil my requirment as well..


Image Analyst
Image Analyst on 1 Nov 2020
Explain what "remove" means to you. Do you want to crop to the grass's bounding box? Do you want to erase the sidewalk (set it to zero)? You can't just "remove" it since images must remain rectangular not trapezoidal.
QuestionsAccount on 3 Nov 2020
by remove i meant to erase the sidewalk (set it to zero) and the rest of the humans and the grass in the center remains same.(only the pixels values in the side walk that i marked with X sign will be set to zero and the rest of the pixels values remains same).
one option that comes in my mide is to use color feature and set the color of side walk to zero while the rest of the colors remains same. but how can i do this in matlab please help me in code this because i didn't figure it out.
i also used K-means clustering for doing above mention work but that also didn't give me the desired results.
your help in codding is highly appreciated.thanx.
for sake of understanding what i desired, i attached image by manually draw the black color in it. output result that i want is attached as (test_img_2).

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 4 Nov 2020
Hi, you can use the interactive Color Thresholder app to achieve what you want. After performing segmentation, this app also generates the equivalent MATLAB code. Below is an example of the code generated by the Color Thresholder app.
I = imread('original.jpg');
% Define thresholds for channel 1 based on histogram settings
channel1Min = 203.000;
channel1Max = 245.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 202.000;
channel2Max = 234.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 197.000;
channel3Max = 227.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = I;
% Set background pixels where BW is true to zero.
maskedRGBImage(repmat(BW,[1 1 3])) = 0;
montage({I, BW, maskedRGBImage}, 'Size', [1 3])
title('RGB image | Segmentation mask | Segmented image')

  1 Comment

QuestionsAccount on 12 Nov 2020
@Subhadeep Koley thank you very much for your help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!