连接文件夹中的图像

发布于 2024-11-10 06:29:31 字数 860 浏览 4 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

菩提树下叶撕阳。 2024-11-17 06:29:31

[image1,map1] = imread(graph1);

and

[image2,map2] = imread(graph2);

替换为

[image1,map1] = imread(file1);

and

[image2,map2] = imread(file2);

同时检查您是否位于正确的工作目录中。

Replace

[image1,map1] = imread(graph1);

and

[image2,map2] = imread(graph2);

by

[image1,map1] = imread(file1);

and

[image2,map2] = imread(file2);

Also check that you are in the right working directory.

夏末染殇 2024-11-17 06:29:31

除了@Simon的答案之外,您还需要更改

file1 = strcat(cr45e__ch_21', '.pdf');

file1 = strcat('cr45e__ch_21', '.pdf');

I.e.你忘记了一个'.此外,您的函数似乎不包含 jpgext 的定义。我希望您想要像 Lastly 这样的行

jpgext = '.jpg';

,主要是编码练习问题,但您可能想切换到使用 fullfile 来构建完整文件路径。

另外,如果您使用完整路径,则不必担心是否位于正确的工作目录中,而是可以不必跟踪自己所在的目录。
所以我建议:

dir1 ='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = fullfile(dir1, 'cr45e__ch_21.pdf');

等等

In addition to the answer by @Simon, you also need to change

file1 = strcat(cr45e__ch_21', '.pdf');

to

file1 = strcat('cr45e__ch_21', '.pdf');

I.e. you forgot a '. Also your function doesn't seem to include a definition of jpgext. I expect you want a line like

jpgext = '.jpg';

Lastly, 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:

dir1 ='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = fullfile(dir1, 'cr45e__ch_21.pdf');

etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文