change white to gray in an image

21 views (last 30 days)
Maria Lancheros Vega
Maria Lancheros Vega on 2 Sep 2020
Answered: Ameer Hamza on 3 Sep 2020
I have this image and I want to turn all the white pixels to gray, but I don´t know how to do it, can somebody help me?.
thakns in advance

Answers (1)

Ameer Hamza
Ameer Hamza on 3 Sep 2020
Try this
im = imread('image.png');
im_gray = rgb2gray(im);
mask = imbinarize(im_gray);
im(mask(:,:,[1 1 1])) = 255*0.8; % 255*0 is black and 255*1 is white, any other value between is shade of gray
imshow(im);

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!