使用MATLAB/八度从RGB到HSV的图像转换回RGB [英] Converting image using matlab / octave from rgb to hsv back to rgb

查看:93
本文介绍了使用MATLAB/八度从RGB到HSV的图像转换回RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将彩色图像从rgb转换为hsv(进行更改),然后再转换回rgb.作为测试,我编写了这段代码,只是为了测试如何从rgb转到hsv回到rgb,但是当我查看图像时,它只是显示为黑色.我想念什么?

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我正在使用八度3.8.1,其工作原理类似于matlab

*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

下面的测试代码:

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图像的值在[0,1](浮点)范围内,uint8图像的值在[0,2^8-1]范围内(仅整数).使用uint8,您只需将0和1之间的值转换为黑色或接近黑色的0和1.

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.

使用im2uint8im2double转换图像,这些功能会自动将值缩放到适当的范围.

Use im2uint8 or im2double to convert images, these functions automatically rescale your values to the appropriate range.

这篇关于使用MATLAB/八度从RGB到HSV的图像转换回RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆