MATLAB Answers

How to Remove Black Background from Photo (Only Keep Region of Interest)

7 views (last 30 days)
Brian Peoples
Brian Peoples on 26 Jun 2020
Commented: Brian Peoples on 26 Jun 2020
Here is my image:
My code so far only gets me my desired region but I wish to take out all the black parts so that I can do proper image analysis on the desired region without the rest interfering. Here is my image after I get my desired region:
My code is as follows:
I0 = imread('DSC_0043.jpg');
I1 = I0(:,:,3); % select 3d channel
I2 = im2bw(I1,graythresh(I1)-0.1); % binarization
h = msgbox('select region of interest');
p = ginput(1); % pick point
I3 = bwselect(~I2,p(1),p(2)); % select region of interest
I4 = cat(3,I3,I3,I3);
I5 = uint8(I4).*I0; % crop rgb image
%I5(I5 ==0) = [];
Please any help would be amazing and greatly appreciated.

Answers (0)

Community Treasure Hunt

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

Start Hunting!