How to remove image background in Matlab

How would I remove the gray background in the grayscale image so i could put a white backgound instead? Please help.. I'm a newbie in Matlab. i'm out of touch on these.. it just an assignment sir.. can you lend me a hand .. please. :((
(original image)
(desired output)

 Akzeptierte Antwort

DGM
DGM am 4 Nov. 2022
Bearbeitet: DGM am 4 Nov. 2022
Here is one simplistic example.
% an image
A = imread('coins.png');
% basic thresholding to select objects
mk = A>100;
% fill any holes in objects
mk = imfill(mk,'holes');
% add colored overlay on background region
bgcolor = [0.7 0.3 1]; % white or any color
outpict = imoverlay(A,~mk,bgcolor);
imshow(outpict)
Bear in mind that if the goal is to change colors in an image, simple binary masking isn't always a good solution for all needs. It will always leave ragged edges on the output. If this is technical image processing where visual appearances aren't important, then logical is probably appropriate.
Similarly, color adjustment by constant replacement destroys all content in the altered regions. Sometimes that's intended, sometimes not.

1 Kommentar

Kalixta
Kalixta am 4 Nov. 2022
ow. okay sir. thank you for the help. i will keep these in mind. ^^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Gefragt:

am 4 Nov. 2022

Kommentiert:

am 4 Nov. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by