2012-04-04 155 views
0

我在阅读matlab文档中的rgb2hsv将返回一个m乘n乘3的图像数组,但是当我调用它时,我得到一个1乘3的矢量。我误解了什么吗? 下面是一个示例代码:Matlab rgb2hsv尺寸

image_hsv = rgb2hsv('filepath') 

和输出

image_hsv = 

     0.7108 0.3696 92.0000 

回答

2

不能调用rgb2hsv的文件路径 - 它必须在MATLAB图像矩阵被调用。尝试:

image_rgb = imread('filepath'); % load the image array to MATLAB workspace 
image_hsv = rgb2hsv(image_rgb); % convert this array to hsv 

你可以看到这些矩阵有:

>> whos image* % display all variables whose name begins with 'image' 
    Name    Size     Bytes Class  Attributes 

    image_hsv  480x640x3   7372800 double    
    image_rgb  480x640x3    921600 uint8  

你的原代码所做的就是将你的文件路径字符串以ASCII码,服用此数组的前三个值的RGB值和将其转换为HSV。

注意:本示例重点介绍了MATLAB弱输入系统的危险性,其中数据类型从一种类型静默转换为另一种类型。也可能缺少对rgb2hsv函数的正确输入检查。