Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays MATLAB在二维阵列中的应用_Arrays_Matlab_Image Processing - Fatal编程技术网

Arrays MATLAB在二维阵列中的应用

Arrays MATLAB在二维阵列中的应用,arrays,matlab,image-processing,Arrays,Matlab,Image Processing,我想用一个2D数组来存储img1、img2的所有值以及img1和img2的比较值, 我想实现如下算法: % 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{

我想用一个2D数组来存储img1、img2的所有值以及img1和img2的比较值, 我想实现如下算法:

% 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
因此,使用我使用的2D数组(ssim_值)时存在错误,初始化它的正确方法是什么,以及如何实现保存我要存储的值的目的

谁能帮帮我吗。提前谢谢。

我假设“num”是您将提供的数字,例如5或其他数字。不能像在Python中那样在数组中混合类型。此外,正如@Schorsch指出的,在Matlab中使用括号索引数组

您尝试形成的二维阵列需要是二维单元阵列。例如:

a = {{"a",3},{"two",[1,2,3]};
在这种情况下,a{1,2}=3,a{2,1}=“2”

您可能事先不知道目录中有多少文件,因此可能无法预先初始化单元阵列。在任何情况下,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

你有python背景吗?在不使用方括号的情况下尝试使用
ssim_值。尝试类似的方法:
ssim_value{num,1}
谢谢,我尝试了你的方法,它可能会起作用,我需要加载整个文件夹图像以查看效果,tks。使用
fullfile
命令为文件/文件夹名创建字符串:
fullfile(somefolder,'*.jpg')
[somefolder'/*.jpg']
更好。