连接文件夹中的图像

| 我将一系列图像保存在一个文件夹中,并且编写了一个简短的程序来打开其中的两个图像文件,并将它们连接起来(最好是垂直连接,尽管现在我是水平尝试),然后将新图像保存到同一文件夹中。到目前为止,这是我写的:
function concatentateImages

%this is the folder where the original images are located path=\'/home/packremote/SharedDocuments/Amina/zEXAMPLE/\';
file1 = strcat(cr45e__ch_21\', \'.pdf\');
[image1,map1] = imread(graph1);
file2 = strcat(\'cr45f__ch_24\', \'.jpg\');
[image2,map2] = imread(graph2);
image1 = ind2rgb(image1,map1);
image2 = ind2rgb(image2,map2);
image3 = cat(2,image1,image2);

%this is the directory where I want to save the new images
dircase=(\'/home/packremote/SharedDocuments/Amina/zEXAMPLE/\');
nombrejpg=strcat(dircase, \'test\', jpgext)
saveas(f, nombrejpg, \'jpg\')
fclose(\'all\');
但是,我不断收到错误消息,指出我的文件不存在,尽管我确定名称已正确复制。 我目前正在使用jpg文件,但是可以轻松转换格式。 非常感谢您提供有关如何解决此错误或更好的执行此任务的方法的意见! 干杯, 阿米娜     
已邀请:
        更换
[image1,map1] = imread(graph1);
[image2,map2] = imread(graph2);
通过
[image1,map1] = imread(file1);
[image2,map2] = imread(file2);
还要检查您是否在正确的工作目录中。     
        除了@Simon的答案,您还需要更改
file1 = strcat(cr45e__ch_21\', \'.pdf\');
file1 = strcat(\'cr45e__ch_21\', \'.pdf\');
即您忘记了\'。同样,您的函数似乎未包含
jpgext
的定义。我希望你想要一条像
jpgext = \'.jpg\';
最后,主要是编码实践问题,但您可能希望切换到使用ѭ9来构建完整的文件路径。 另外,如果您使用完整路径,则不必担心要放在正确的工作目录中,而不必跟踪自己所在的目录。 所以我建议:
dir1 =\'/home/packremote/SharedDocuments/Amina/zEXAMPLE/\';
file1 = fullfile(dir1, \'cr45e__ch_21.pdf\');
等等     

要回复问题请先登录注册