How can I reset the h and s channels?

I have an image in hsv and I would like to set the h and s channels to 0 in order to have the desaturated image. How can I do?

 Accepted Answer

NewImage = hsvimage;
NewImage(:, :, 1:2) = 0;
However if your purpose is to desaturate then you should only assign to the s channel, 2

3 Comments

ok, but how come if I write this code, that is the desaturated image, I do not get out of the desaturated image (ie gray), but it comes out with colors?
img = rgb2hsv(imread('peppers.png'));
img(:,:,2) = 0;
imshow(img);
//image is output
You forgot to convert back to rgb before displaying.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!