我使用函数“fdetect”裁剪出检测到的面部,现在我尝试将获得的 2D 图像 reshape 为 1D 图像向量。我尝试了以下方法:
for k=1:length(files)
%read the images in the folder
imgs=imread(fullfile);
fdI=fdetect(imgs);
targetsize=[256 256];
img_resized=imresize(fdI,targetsize);
[irow icol]=size(img_resized',irow*icol,1);
T=[T temp] %1D image vector
end
但我收到错误:
函数 IMRESIZE 期望其第一个输入 A 非空。
我检查了函数“fdetect”的输出及其非空值,它给出了裁剪后的面孔。 任何人都可以指出我的错误或任何其他方法吗? 提前致谢。
最佳答案
将 2D 向量转换为 1D 的最简单方法就是使用冒号运算符:
img_resized(:) %// or fdI(:), not sure which you want to convert
但您也可以使用 reshape 功能:
reshape(img_resized, [], 1) %// Note that the second parameter specifies how many rows you want. You can be specific if you want, i.e. numel(img_resized), but by passing an empty vector, reshape calculates that dimension for you.
关于matlab - 如何在 MATLAB 中将裁剪后的人脸图像 reshape 为一维图像向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21037271/