Conversion from HSV to RGB

5 views (last 30 days)
Fed on 11 Aug 2020
Commented: Fed on 17 Aug 2020
Good afternoon,
I had to reproduce a "scotoma" condition on an image.
To do so I converted my RGB image to the HSV space, applied a gaussian bynary mask to the v channel and then reconverted from the HSV space to the RGB space. Here is the code:
A = imread('lena .bmp');
%conversion from RGB to HSV space
HSV = rgb2hsv(A);
%separation of the channels
[h,s,v] = imsplit(HSV);
%creation of the gaussian mask and application to the v channel
[r,c,~] = size(v);
[X Y] = meshgrid(1:r,1:c);
Z = mvnpdf([X(:) Y(:)], [r c]./2, diag(500.*[r c])); %maschera gaussiana
Z = (Z-min(Z(:)))./range(Z(:));
Z = reshape(Z',[c r])';
Z_gauss = 1-Z;
%reconstruction of the image
HSV_new = cat(3,h,s,Z_gauss); %immagine hsv dopo il filtraggio con la gaussiana
%conversion from HSV to RGB space
RGB_new = hsv2rgb(HSV_new);
By confronting the original RGB image with the modified one as shown below, I noticed that in the second image colors are not the same as the original image.
What I'd like to know is if this is a consequence of the conversion to the HSV space and then back to the RGB space or if there is the possibility to restore the original colors and in case how to do so.
Thank you in advance
Fed on 11 Aug 2020
Edited: Fed on 11 Aug 2020
Thank you for your answer.
Yes the output is the same as the input, the only thing that changes is the v channel value because of the application of a gaussian mask Z.

Sign in to comment.

Accepted Answer

Raunak Gupta
Raunak Gupta on 14 Aug 2020
Since the V channel is changed for original image with a gaussian mask the output has been changed. This is because while converting to RGB from HSV, each of the R,G,B channel are inter-dependent on H,S,V channel and even if only the v channel is changed in HSV it will affect the entire RGB image while reconstruct from HSV. In conclusion the output will be different even if only single channel out of HSV is changed and hsv2rgb is used to convert back to RGB format.
So, this is not the consequence of taking the image to HSV domain, because if you don’t change the V channel and reconstruct you will get the output same as input. It is just that some processing is applied on the image which will change the appearance.
Hope it clarifies!
  1 Comment
Fed on 17 Aug 2020
Yes it’s very clear, thank you for your help!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!