how PCA is applied to a set of 10 images for making a model

조회 수: 17 (최근 30일)
raj kumar
raj kumar 2014년 6월 20일
답변: Uttiya Ghosh 2020년 7월 15일
anybody please give me a matlab code for applying PCA to a set ofimages for obtaining a model.

답변 (1개)

Uttiya Ghosh
Uttiya Ghosh 2020년 7월 15일
Hi Raj,
As per my understanding you want to apply PCA to a set of images. There are multiple ways to do it. You can either read the images and reshape them as row vectors and then apply pca on the matrix created by the combination of all such row vectors or you can use bagOfFeatures to extract important features from the images and then apply it. In the following code I have used the former option.
setDir = fullfile(matlabroot,'toolbox','nnet','nndemos', ...
'nndatasets','DigitDataset');
imds = imageDatastore(setDir,'IncludeSubfolders',true,'LabelSource',...
'foldernames');
img = readimage(imds,1);
data = zeros(length(imds.Files),numel(img));
for i = 1:length(imds.Files)
img = readimage(imds,i);
data(i,:) = reshape(img,[1 numel(img)]);
end
coeffs = pca(data);
For more information, refer to the following links.

카테고리

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