PCA OF AN IMAGE...
이전 댓글 표시
I want to find PCA of an image... but when i run the code i get following error..
Error using - Integers can only be combined with integers of the same class, or scalar doubles. Error in pca (line 26) data = data - repmat(mn,1,N);
here is the code....'
function [signals,PC,V] = pca()
I = imread('C:\Users\div\Pictures\Picture1.png');
I = rgb2gray( I);
[irow, icol] = size(I);
data = reshape(I',irow*icol,1);
% [sR ,sC ,eR ,eC] = deal(1, 3, 2, 4);
% Compute the sum over the region using the integral image.
% PCA1: Perform PCA using covariance.
% data - MxN matrix of input data
% (M dimensions, N trials)
% signals - MxN matrix of projected data
% PC - each column is a PC
% V - Mx1 matrix of variances
[M,N] = size(data);
% subtract off the mean for each dimension
mn = mean(data,2);
data = data - repmat(mn,1,N);
% calculate the covariance matrix
covariance = 1 / (N-1) * data * data;
% find the eigenvectors and eigenvalues
[PC, V] = eig(covariance);
% extract diagonal of matrix as vector
V = diag(V);
% sort the variances in decreasing order
[junk, rindices] = sort(-1*V);
V = V(rindices); PC = PC(:,rindices);
% project the original data set
signals = PC * data;
채택된 답변
추가 답변 (3개)
yagnesh
2013년 5월 24일
0 개 추천
try data = double(data)- double(repmat(mn,1,N));
farahnaz
2014년 3월 22일
0 개 추천
please use this cod :
function [signals,PC,V] = pca() I=imread('G:\Users\farahnaz\Downloads\018.jpg'); b= im2double(I); imshow(b, []); [irow, icol] = size(b); data = reshape(b',irow*icol,1);
[M,N] = size(data);
mn = mean(data,2);
data = data - repmat(mn,1,N);
covariance = cov(data)';
[PC, V] = eig(covariance);
V = diag(V);
[junk, rindices] = sort(-1*V);
V = V(rindices); PC = PC(:,rindices);
댓글 수: 4
Shaveta Arora
2016년 1월 31일
how to show the image after this using principal components. Please answer!!
Image Analyst
2016년 1월 31일
With
imshow(pcimage, [])
Make sure you get your PC image as a 2D image.
Shaveta Arora
2016년 1월 31일
pls elaborate about the pcimage variable. how to get PC image as 2D
Image Analyst
2016년 1월 31일
I don't see how he's getting PC images. There aren't any. You can see my attached demo if you want.
Shaveta Arora
2016년 2월 1일
actually I want to recover the image using principal components after the following instruction:
% project the original data set
signals = PC * data;
pls help me in recovering the image.
카테고리
도움말 센터 및 File 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!