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)

 採用された回答

DGM
DGM 2022 年 11 月 4 日
編集済み: DGM 2022 年 11 月 4 日

0 投票

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 件のコメント

Kalixta
Kalixta 2022 年 11 月 4 日
ow. okay sir. thank you for the help. i will keep these in mind. ^^

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2017b

質問済み:

2022 年 11 月 4 日

コメント済み:

2022 年 11 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by