下面的程序是將文件夾中所有的圖像拼接在一起,例如文件夾中有80張圖像,想要將這80張圖像拼成8行10列的大圖像。
clc,clear;p = genpath('');% 獲得文件夾data下所有子文件的路徑,這些路徑存在字符串p中,以';'分割  length_p = size(p,2);%字符串p的長度  path = {};%建立一個單元數組,數組的每個單元中包含一個目錄  temp = []; for i = 1:length_p %尋找分割符';',一旦找到,則將路徑temp寫入path數組中      if p(i) ~= ';'          temp = [temp p(i)];      else           temp = [temp '/']; %在路徑的最后加入 '/'          path = [path ; temp];          temp = [];      end  end    clear p length_p temp;  %至此獲得data文件夾及其所有子文件夾(及子文件夾的子文件夾)的路徑,存于數組path中。  %設置一些參數nb_row=8;nb_colum=10;%合并圖像后nb_row行,nb_colum列IntervalBetweenImage=3;%兩個小圖像之間的間隔file_num = size(path,1);% 子文件夾的個數  reszie_width=100;resize_height=100;%下面是逐一文件夾中讀取圖像  for i = 1:file_num    file_path =  path{i}; % 圖像文件夾路徑      img_path_list = dir(strcat(file_path,'*.jpg'));      img_num = length(img_path_list); %該文件夾中圖像數量       p=0;    if img_num > 0          for j = 1:img_num                         if(p==10)                p=1;            else                p=p+1;            end            image_name = img_path_list(j).name;% 圖像名              image =  imread(strcat(file_path,image_name));  %image是要處理的圖像            f原圖是


最終的結果圖:
新聞熱點
疑難解答