Conversion from HSV to RGB
5 views (last 30 days)
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
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!