MATLAB Answers


matlab code to make a background of color image a uniform background?

Asked by ARUN SAI
on 21 May 2013

matlab code to make a background of color image mandi.tif which is in matlab , with uniform background?


2 Answers

Answer by Image Analyst
on 21 May 2013

Use imfreehand() to identify the foreground and background. You'll have a binary image that specifies this. Then just assign the color to the background.

% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Now call imfreehand and create binary image of background.
% Assign background color to background.
redChannel(backgroundImage) = desiredRedValueOfBackground;
greendChannel(backgroundImage) = desiredGreenValueOfBackground;
blueChannel(backgroundImage) = desiredBlueValueOfBackground;
newRGBImage = cat(3, redChannel, greenChannel, blueChannel);


i want code with some image as a example.

You must learn how to use imread() and imshow() - they will be indispensible to you.

rgbImage = imread('peppers.png');

Search Answers for imfreehand - I've posted my demo many times before. Then mark my answer as "Accepted".

I don't understand what your "Answer" meant.

Answer by ARUN SAI
on 22 May 2013

no i want code for color image with uniform background and add noise ie, white spot


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!