2011-05-27 125 views
1

我有一系列圖像保存在一個文件夾中,我寫了一個簡短的程序來打開這些圖像文件中的兩個,連接它們(最好是垂直,儘管現在我正在水平嘗試),然後將此新圖像保存到相同的文件夾中。這是我至今寫:連接來自文件夾的圖像

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文件,但格式可以很容易地轉換。

有關如何解決此錯誤的任何輸入信息,或執行此任務的更好方法,我們深表感謝!

乾杯,

阿米娜

回答

1

替換

[image1,map1] = imread(graph1); 

[image2,map2] = imread(graph2); 

通過

[image1,map1] = imread(file1); 

[image2,map2] = imread(file2); 

也檢查你是在正確的工作目錄。

1

除了由@Simon答案,你也需要改變

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

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

即你忘了'。此外,您的功能似乎不包括jpgext的定義。我希望你要像

jpgext = '.jpg'; 

最後,主要是編碼實踐問題的線路,但你可能要切換到使用fullfile建立自己完整的文件路徑。

此外,而不是擔心在正確的工作目錄是,如果你使用完整路徑您不必跟蹤你在哪個目錄保存自己 所以我建議:

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

相關問題