Conversion from HSV to RGB
7 次查看(过去 30 天)
显示 更早的评论
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);
figure
imshow(RGB_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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/344533/image.jpeg)
2 个评论
Walter Roberson
2020-8-11
They are not supposed to be the same, as you modified them.
The question is whether the output is the same as the input except with a different Value (V).
采纳的回答
Raunak Gupta
2020-8-14
Hi,
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!