Conversion from HSV to RGB

조회 수: 6(최근 30일)
Fed 2020년 8월 11일
댓글: Fed 2020년 8월 17일
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
  댓글 수: 2
Fed 2020년 8월 11일
편집: Fed 2020년 8월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Raunak Gupta
Raunak Gupta 2020년 8월 14일
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
Fed 2020년 8월 17일
Yes it’s very clear, thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by