2013-09-22 86 views
0

我想用一个二维数组存储IMG1,IMG2和IMG1和IMG2, 的比较vlaue我想才达到的算法的所有值喜欢:MATLAB使用二维数组

% read in the images from a folder one by one: 
    somefolder = 'folder'; 
    filelist = dir([somefolder '/*.jpg']); 
    s=numel(filelist); 
    C = cell(length(filelist), 1); 
    for k=1:s 
     C{k}=imread([somefolder filelist(k).name]); 
    end 
%choose any of the two images to compare 
    for t=1:(s-1) 
     for r=(t+1):s 
      img1=C{r}; 
      img2=C{t}; 
      ssim_value[num][1]=img1; % first img 
      ssim_value[num][2]=img2; % second img 
      ssim_value[num][3]=mssim; % ssim value of these two images 

     end 
    end 

所以,关于使用我使用的二维数组(ssim_value)有错误,初始化它的正确方式是什么,以及如何实现保存我想要存储的值的目的。

有人可以帮助我。提前致谢。

+2

你有蟒蛇的背景?在没有方括号的情况下尝试'ssim_value'。尝试像这样:'ssim_value {num,1}' – Schorsch

+0

谢谢,我试过你的方法,它可能工作,我需要加载整个文件夹图像,看看如何,TKS。 – user2753594

+3

使用'fullfile'命令为文件/文件夹名称创建字符串:'fullfile(somefolder,'* .jpg')'比'[somefolder'/ *。jpg']'更好。 – Shai

回答

1

我假设“num”是一个你会提供的数字,比如5或者什么的。你不能像在Python中那样混合数组中的类型。另外,正如@Schorsch指出的那样,你使用括号来在Matlab中对数组进行索引。

您尝试形成的二维数组需要是2-D单元阵列。例如:

a = {{"a",3},{"two",[1,2,3]}; 

在这种情况下,{1,2} = 3和{2,1} =“two”。

您可能并不知道目录中有多少个文件,因此可能无法预先初始化单元阵列。无论如何,出于性能原因,Matlab数组只需要进行预初始化,并且您可以轻松找到有关在Matlab中初始化数组的信息。

鉴于此,我敢肯定你所要完成的是什么:

%choose any of the two images to compare 
    ssim_value = {}; 
    for t=1:(s-1) 
     for r=(t+1):s 
      img1=C{r}; 
      img2=C{t}; 
      ssim_value{num,1}=img1; % first img 
      ssim_value{num,2}=img2; % second img 
      ssim_value{num,3}=mssim; % ssim value of these two images 

     end 
    end