连接文件夹中的图像
我在一个文件夹中保存了一系列图像,并且我编写了一个简短的程序来打开其中两个图像文件,将它们连接起来(最好是垂直连接,尽管现在我正在尝试水平连接),然后将此新图像保存到同一个文件夹中。这是我到目前为止所写的:
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文件,但格式可以很容易地转换。
非常感谢任何有关如何修复此错误或执行此任务的更好方法的输入!
干杯,
阿米娜
I have a series of images saved in a folder, and I have written a short program to open two of these image files, concatenate them (preferably vertically, although for now I am trying horizontally), then save this new image to the same folder. This is what I have written so far:
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');
However, I keep getting an error that my files do not exist, though I am certain the names are copied correctly.
I am currently using jpg files, but the format can be easily converted.
Any input on how to fix this error, or a nicer way of preforming this task is greatly appreciated!
Cheers,
Amina
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
and
替换为
and
同时检查您是否位于正确的工作目录中。
Replace
and
by
and
Also check that you are in the right working directory.
除了@Simon的答案之外,您还需要更改
为
I.e.你忘记了一个'.此外,您的函数似乎不包含
jpgext
的定义。我希望您想要像 Lastly 这样的行,主要是编码练习问题,但您可能想切换到使用
fullfile
来构建完整文件路径。另外,如果您使用完整路径,则不必担心是否位于正确的工作目录中,而是可以不必跟踪自己所在的目录。
所以我建议:
等等
In addition to the answer by @Simon, you also need to change
to
I.e. you forgot a '. Also your function doesn't seem to include a definition of
jpgext
. I expect you want a line likeLastly, mostly a coding practice issue, but you might want to switch to using
fullfile
to build your full file path.Also, instead of worrying about being in the correct working directory, if you use full paths you save yourself from having to keep track of what directory you're in.
SO I would suggest:
etc