我显然无法区分不同类型的向量和数组以及像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