Search code examples
matlabimage-processingcrop

How to reshape cropped face images into 1D image vector in MATLAB?


I cropped out the detected faces using function "fdetect" and now i am trying to reshape the obtained 2D images into 1D image vectors. I tried the following :

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

But i get the error:

Function IMRESIZE expected its first input A to be nonempty.

I checked the output of the function "fdetect" and its nonempyt, it gives the cropped faces. Can anyone point out my mistake please or any other way of doing this ? Thanks in advance.


Solution

  • The easiest way to make a 2D vector 1D is just to use the colon operator:

    img_resized(:)  %// or fdI(:), not sure which you want to convert
    

    But you can also use the reshape function:

    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.