matlab - 如何在 MATLAB 中将裁剪后的人脸图像 reshape 为一维图像向量?

标签 matlab image-processing crop

我使用函数“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/

相关文章:

matlab - 以编程方式启用选项 "Confirm before exiting Matlab"

matlab - 即使在 Simulink 中使用过去的 SimState 时也可以设置自定义随机数生成器种子

string - 在 MATLAB 中,您可以将字符串视为列表中的一个对象吗?

python - python opencv中的倒角匹配错误

iOS8 - 裁剪和拉直图像作为内置照片工具

matlab - 识别叶子的裂片和凸起

PHP脚本GD库内存问题

image-processing - 创建HSV直方图时如何选择bin的数量?

PHP GD - 裁剪形状

c++ - openCv 裁剪图像