please help me with this MATLAB error: To RESHAPE the number of elements must not change.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clc;
close all;
clear all;
x = imread('frame1.jpg');
x=x(:,:,1);
y = medfilt2(x); % required to find the correlation of the same image
xmean=mean(x(:));
ymean=mean(y(:));
xnew=x-xmean; % finding mean for correlation matrix
ynew=y-ymean;
cm=normxcorr2(xnew,ynew); % correlation matrix
s=size(cm);
n=min(s);
cm_square=cm(1:n,1:n);
[V,D] = eig(cm_square); % Finding Eigenvectors
cm_eig_vec = []; % Sorting Eigenvectors
eigValue=diag(D);
[eigValue,IX]=sort(eigValue,'descend');
cm_eig_vec=V(:,IX);
norm_eigVector=sqrt(sum(cm_eig_vec.^2)); % normailization
cm_eig_vec=cm_eig_vec./repmat(norm_eigVector,size(cm_eig_vec,1),1);
Eigenfaces = xmean * cm_eig_vec(:,1:1); % 1:dimensions (dimensionality reduction)
Ipc1 = reshape(Eigenfaces(:,1),size(x,1),size(x,2));
0 comentarios
Respuestas (1)
Walter Roberson
el 18 de Jun. de 2017
Let L be the smaller of the number of rows and columns of your image -- as in
YourImage = imread('frame1.jpg');
[r, c, p] = size(YourImage);
L = min([r, c]);
I used different variable names here because you write over your x variable and I did not want any ambiguity over which size was being discussed.
Then, your cm_eig_vec variable is going to come out as (2*L-1) x (2*L-1), and your Eigenfaces variable is going to come out as (2*L-1) x 1.
You then try to reshape that vector of length (2*L-1) into the full rows and columns of the image, r x c. This cannot work unless your original image was 1 x 1.
2 comentarios
Walter Roberson
el 18 de Jun. de 2017
Well, by the time you get to cm_eig_vec you have a variable which is roughly twice as many rows and twice as many columns as the minimum dimension of your original matrix, but you then take only a single column of that to construct Eigenfaces. There is no way you can get the larger dimension back by just reshape() of that result.
Ver también
Categorías
Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!