0

I just ran the following lines of codes and noticed that when i first read a rgb image and then convert the image to hsv model and then reconvert it back to rgb model the pixel values of the image changes before and after conversion.

in short :

rgb1 = rgb image before conversion ;

rgb2 = rgb image after converting to HSV and then re-converting back to rgb

rgb1 >= rgb2

why rgb1 is >= rgb2 ?? shouldn't it be equal on every pixels?

MATLAB CODE :

rgb1 = imread('peppers.png');
hsv = rgb2hsv(rgb1);
rgb2 = hsv2rgb(hsv);

g = find(rgb1<rgb2); 
%g returns empty matrix
%So rgb1 has to be >= rgb2 on every pixel value
1

1 Answer 1

0

First of all, rgb1 in uint8 format and you can check it with max(rgb1), however, rgb2 is in double format which is in range of 0-1.

To see, they should be equal and also are indeed equal after conversion:

rgb1_d = im2double(rgb1);
hsv = rgb2hsv(rgb1);
hsv = rgb2hsv(rgb1_d);
rgb2 = hsv2rgb(hsv);
imshow(rgb_d-rgb2)

You will get a black image which is as expected; however, don't do find(rgb_1>rgb2) because, there can be some deviations from zero in the order of 10^-15 or smaller may lead you wrong results. Instead, define a epsilon = 10^-3 or something and then make g = find(rgb1_d-rgb2<10e-3);

2
  • u r right. totally forgot about converting to double.... thanks a lot man... so the rgb1==rgb2 before and after conversion right?? Commented Oct 26, 2016 at 12:27
  • As I said, there could be some really small deviations. You need to check with a small epsilon neighborhood around zero. Commented Oct 26, 2016 at 12:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.