RGB image to HSV image conversion

27 views (last 30 days)
Algorithms Analyst
Algorithms Analyst on 9 Sep 2013
Commented: Image Analyst on 17 Sep 2015
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...

Answers (1)

Image Analyst
Image Analyst on 9 Sep 2013
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 Comments
azam sayeed
azam sayeed on 17 Sep 2015
Edited: Walter Roberson on 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
Image Analyst
Image Analyst on 17 Sep 2015
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!