RGB image to HSV image conversion

Hello all
I have an rgb image and I want to convert it into HSV image and want to get only SV image.I have code like that
img=imread('lena.bmp');
[H S V]=rgb2hsv(img);
this computes each H,S and V channel individual I want to compute only SV only how can I do it..
it is not possible to o it like
cat(2,S,V);...?
or
rgbimage=img;
rgbimage(:,:,2)=S;
rgbimage(:,:,3)=V;
Any help is appreciated...

Réponses (1)

Image Analyst
Image Analyst le 9 Sep 2013

0 votes

No - none of that is right. For one, you can't get the separate channels out of rgb2hsv(), though that might be a nice new enhancement/feature to add. You can do this:
hsv = rgb2hsv(rgbImage);
h = hsv(:, :, 1); % Hue image.
s = hsv(:, :, 2); % Saturation image.
v = hsv(:, :, 3); % Value (intensity) image.
You certainly would not want to combine them into a 3D image called anything like rgbimage because that would be very deceptive since it's not an RGB image.

6 commentaires

Algorithms Analyst
Algorithms Analyst le 9 Sep 2013
Yeah thats right.Ok I got the H,S,V image.Now I want to work only on SV channel not individual but combine. how can I combine them.How can I show SV image?
I don't know what that means. You should work on them separately - how can you not and have it make any sense. For example if you combined them into a 3D matrix and did
meanValue = mean(SV(:));
you'd get total nonsense. It only makes sense to me to work on them separately.
You can use imshow(), imshowpair(), or imfuse() to display a composite image.
Algorithms Analyst
Algorithms Analyst le 9 Sep 2013
ok. Now I got the S image.from above code.
fs=1.25; ts=0.8;
I want to show some good appearance of S image according to algorithm
if (Simage<ts)
S_out=Simage.*fs; end if Simage>=ts S_out=1; end
S_out is the same vector like Simage for storing output image.But the result is same.I got the same result.There is no change when I apply the above condition.Am I doing any mistake here?
Jan
Jan le 9 Sep 2013
Modifié(e) : Jan le 9 Sep 2013
It depends on what "combine" exactly needs. What do you think is an SV image? To display it, you have to choose any value for hue, e.g. 0 or 0.5. Otherwise the color is not defined unequivocally.
azam sayeed
azam sayeed le 17 Sep 2015
Modifié(e) : Walter Roberson le 17 Sep 2015
sir when i apply meanValue to different images i still get the same mean value based on hue component
%window1
hsv2=rgb2hsv('testw1.png');
hueImage2 = hsv2(:,:, 1);
meanHue2 = mean2(hueImage2);
display(meanHue2 );
%window4
hsv3=rgb2hsv('test.png');
hueImage3 = hsv3(:,:, 1);
meanHue3 = mean2(hueImage3);
display(meanHue3);
output:
meanHue2 =
38.9913
meanHue3 =
38.9913
You need to send in an image to rgb2hsv, not a string that happens to be a filename:
rgbImage = imread('testw1.png'); % Get image from file
hsv2=rgb2hsv(rgbImage); % Convert image, not string.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by