我顯然無法區分不同類型的向量和數組以及像string,cellstr,char等命令。我的代碼在另一個網絡上,但基本上,我得到一個錯誤,說我的imread語句中的參數必須是字符矢量。這個參數是一個1x30的文件名數組,因爲我使用了iscell命令,並且它返回了1,所以我嘗試了上面列出的命令的幾個組合,並且一直在閱讀我能夠做的所有事情,但無法確定如何更改將1x30單元格數組轉換爲字符向量,以便imread語句可以工作。文件名是從文件夾(使用uigetfile)作爲757-01.bmp,757-02.bmp ... 757-30.bmp讀入的。我想我需要讓他們'757-01.bmp','757-02.bmp'...'757-30.bmp',並可能成爲一個30x1矢量副1x30?或者,這對代碼將在下一次遇到的for循環無關緊要。謝謝你的任何援助...在MatLab中,如何從單元格數組創建一個字符向量?
[imagefiles,file_path]=uigetfile({'*.jpeg;*.jpg;*.bmp;*.tif;*.tiff;*.png;*.gif','Image Files (JPEG, BMP, TIFF, PNG and GIF)'},'Select Images','multiselect','on');
imagefiles = cellstr(imagefiles);
imagefiles = sort(imagefiles);
nfiles = length(imagefiles);
r = inputdlg('At what pixel row do you want to start the cropping? .','Row');
r = str2num(r{l});
c = inputdlg('At what pixel column do you want to start the cropping (Must be > 0)? .','Column');
c = str2num(c{l});
h = inputdlg('How many pixel rows do you want to include in the crop? .','Height');
h = str2num(h{l});
w = inputdlg('How many pixel columns do you want to include in the crop? .','Width');
w = str2num(w{l});
factor = inputdlg('By what real number factor do you want to enlarge the cropped image? .','Factor');
factor = str2num(factor{l});
outdimR = h * factor;
outdimC = w * factor;
for loop=l:nfiles
filename = imagefiles(loop);
[mybmp, map] = imread(filename);
myimage = ind2rgb(mybmp,map);
crop = myimage(r:r+h-1, c:c+w-1, :);
imwrite(crop, sprintf('crop757-%03i.bmp',loop));
end
你可以發表你的代碼如何使用imread?這可能是你的錯誤所在。 – Flynn
請發表[mcve]。 – beaker
代碼是裁剪圖像: – bpfreefly