2
votes

I want to modify luminance values of color image pixels. The modification rules are as follows: Assumption: Luminance values are normalised in [0, 1], 1 = White

  1. If a chosen pixel's luminance value is above a threshold (say thresh=0.5, pixel luminance value = 0.8), it's changed to a lower value (say 0.3), so that when the image is binarised, that pixel is shown as a black pixel.
  2. Similarly, if a chosen pixel's luminance value is below a threshold, the luminance is increased so that it binarises as white.

I have tried MATLAB's rgb2hsv()and hsv2rgb() functions to convert an RGB image to HSV, extract the luminance channel, modify it, and change the image back to RGB. But the results are not what I need.

What I need is:

  1. If a bright red pixel's luminance is decreased, it should become dark red, so it binarises to black.
  2. If a white pixel's luminance is decreased, it should become black.
  3. If a black pixel's luminance is increased, it should become white.

I have following issues/questions:

  1. When I decrease the luminance of a white pixel, it turns red instead of black.
  2. Is it possible to achieve the above mentioned goals without modifying any other channels of the HSV image, like Hue/Chrominance?
  3. Is the conversion between RGB and HSV loss-less?
  4. What would be an ideal way to achieve this?
2

2 Answers

2
votes

Well,

your first statements are opposite so if applied simultaneously they will invert an image. I guess you just point out 2 different action you want to take.

Regarding your issues:

When I decrease the luminance of a white pixel, it turns red instead of black.

This cannot happen. You have made some mistake here. If you just modify the Luminance then the color does not change (from white to red).

Is it possible to achieve the above mentioned goals without modifying any other channels of the HSV image, like Hue/Chrominance?

It is the only correct method to do. Do not modify the other channels.

Is the conversion between RGB and HSV loss-less?

It's loseless enough. If you apply the following command the result is on the verge of numerical stability:

im2 = hsv2rgb(rgb2hsv(im));
im=im2double(im);
sum(im2(:)-im(:))

ans =

   6.9403e-14

What would be an ideal way to achieve this?

This approach is good enough if you don't have any specific reason to believe otherwise.

1
votes
  1. You hare simply using the wrong colour space. Check the wikipedia article about HSV and HSL, especially the comparison graphic on the right. With V=1 you get any "pure" colour. As you are talking about luminance you should probably take the lighness channel of HSL. rgb2hls is avaliable at matlab file exchange.

  2. See 1, use HSL then you have to change the L channel

  3. As you want to change to black and white, you can detect the pixels to modify in the HSL image and set the pixels in the RGB image. The color space for RGB, HSV and HSL matches you only have precision errors. When using normalized colors (0,1) and double values, these errors are minor.