필터 지우기
필터 지우기

please help me with this MATLAB error: To RESHAPE the number of elements must not change.

조회 수: 2 (최근 30일)
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));

답변 (1개)

Walter Roberson
Walter Roberson 2017년 6월 18일
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
Harpreet Kaur
Harpreet Kaur 2017년 6월 18일
you are right, it works for 1x1. But I don't need a image with 1x1 dimensions. I have to process it further for detecting forgery.
Walter Roberson
Walter Roberson 2017년 6월 18일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by