I'm trying to convert a color image from rgb to hsv (make changes) then back to rgb. As a test I made this code just to test how to go from rgb to hsv back to rgb but when I view the image it just shows up as black. What am I missing?
*PS I'm using octave 3.8.1 which works like matlab
Here are the octave 3.8.1 packages I have loaded:
>>> pkg list
Package Name | Version | Installation directory
--------------+---------+-----------------------
control *| 2.6.2 | /usr/share/octave/packages/control-2.6.2
general *| 1.3.4 | /usr/share/octave/packages/general-1.3.4
geometry *| 1.7.0 | /usr/share/octave/packages/geometry-1.7.0
parallel *| 2.2.0 | /usr/share/octave/packages/parallel-2.2.0
signal *| 1.2.2 | /usr/share/octave/packages/signal-1.2.2
specfun *| 1.1.0 | /usr/share/octave/packages/specfun-1.1.0
test code below:
f=imread('/tmp/bump.jpg'); %color image
%Hue - Saturation - Value
f_rgb2hsv=rgb2hsv(f); %convert image to HSV double
f_hsv2rgb=hsv2rgb(f_rgb2hsv);%convert to RGB double
f_to_image=uint8(f_hsv2rgb); %convert to uint8 to see image
imshow(f_to_image);
double
images have values in range [0,1] (float), uint8
images in range [0,2^8-1]
(only integers). Using uint8
you simply convert your values between 0 and 1 to 0 and 1 which is black or nearly black.
Use im2uint8
or im2double
to convert images, these functions automatically rescale your values to the appropriate range.
来源:https://stackoverflow.com/questions/31544618/converting-image-using-matlab-octave-from-rgb-to-hsv-back-to-rgb