Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
PCA

Subject: PCA

From: Caio

Date: 5 Apr, 2011 19:11:05

Message: 1 of 6

Hi,
I am having problens with doing the PCA analysis. I want to plot the first and second principal components of a image histogram. Here is my rotine.
X1 and Y1 are columns of my histrogam


% Applying Principal Component Analysis - PCA
    
    %step 1, finding a mean and subtracting
    X1mean=mean(X1);
    Y1mean=mean(Y1);
    
    [a,b]=size(X1);
    X1new=X1-X1mean*ones(a,1);
    Y1new=Y1-Y1mean*ones(a,1);

    subplot(5,1,2);
    plot(X1,Y1, 'o');
    title('Histogram Data');
    
    subplot(5,1,3);
    plot(X1new,X1new, 'o');
    title('mean is deducted')
        
    % step 2 - Covariance Matrix
    covariancematrix=cov(X1new,Y1new);

    % step 3 - Finding Eigenvectors
    [V,D] = eig(covariancematrix);
    D=diag(D);
    maxeigval=V(:,find(D==max(D)));
    
    % step 4 - Deriving the new data set
    % Finding the projection onto the eigenvectors

    finaldata=maxeigval'*[X1new,Y1new]';
    subplot(5,1,4);
    stem(finaldata, 'DisplayName', 'finaldata', 'YDataSource', 'finaldata');
    title('PCA output ')

Someone can help me?
Thanks.

Subject: PCA

From: Florin Neacsu

Date: 5 Apr, 2011 21:01:19

Message: 2 of 6

"Caio " <caiovtrich@gmail.com> wrote in message <infpg9$6op$1@fred.mathworks.com>...
> Hi,
> I am having problens with doing the PCA analysis. I want to plot the first and second principal components of a image histogram. Here is my rotine.
> X1 and Y1 are columns of my histrogam
>
>
> % Applying Principal Component Analysis - PCA
>
> %step 1, finding a mean and subtracting
> X1mean=mean(X1);
> Y1mean=mean(Y1);
>
> [a,b]=size(X1);
> X1new=X1-X1mean*ones(a,1);
> Y1new=Y1-Y1mean*ones(a,1);
>
> subplot(5,1,2);
> plot(X1,Y1, 'o');
> title('Histogram Data');
>
> subplot(5,1,3);
> plot(X1new,X1new, 'o');
> title('mean is deducted')
>
> % step 2 - Covariance Matrix
> covariancematrix=cov(X1new,Y1new);
>
> % step 3 - Finding Eigenvectors
> [V,D] = eig(covariancematrix);
> D=diag(D);
> maxeigval=V(:,find(D==max(D)));
>
> % step 4 - Deriving the new data set
> % Finding the projection onto the eigenvectors
>
> finaldata=maxeigval'*[X1new,Y1new]';
> subplot(5,1,4);
> stem(finaldata, 'DisplayName', 'finaldata', 'YDataSource', 'finaldata');
> title('PCA output ')
>
> Someone can help me?
> Thanks.


Hi,

What is your objective ? What are you hopping to obtain from your PCA ?
Are you applaying PCA to two vectors, which are obtain from a histogram ?

Regards,

Florin

Subject: PCA

From: Caio

Date: 5 Apr, 2011 23:10:20

Message: 3 of 6

Hi,
First i manipulate my images from orange trees with citrus canker to obtain histograms. I think that applying the PCA method in this histograms i can observe the the time evolution of the disease. In this case, i have many histograms that each one can be a pair of vectors. My objective is try to see some relations when i plot the first and second principal components.
Are you understand?
Thanks.

"Florin Neacsu" <fneacsu2@gmail.com> wrote in message <infvuv$bl$1@fred.mathworks.com>...
> "Caio " <caiovtrich@gmail.com> wrote in message <infpg9$6op$1@fred.mathworks.com>...
> > Hi,
> > I am having problens with doing the PCA analysis. I want to plot the first and second principal components of a image histogram. Here is my rotine.
> > X1 and Y1 are columns of my histrogam
> >
> >
> > % Applying Principal Component Analysis - PCA
> >
> > %step 1, finding a mean and subtracting
> > X1mean=mean(X1);
> > Y1mean=mean(Y1);
> >
> > [a,b]=size(X1);
> > X1new=X1-X1mean*ones(a,1);
> > Y1new=Y1-Y1mean*ones(a,1);
> >
> > subplot(5,1,2);
> > plot(X1,Y1, 'o');
> > title('Histogram Data');
> >
> > subplot(5,1,3);
> > plot(X1new,X1new, 'o');
> > title('mean is deducted')
> >
> > % step 2 - Covariance Matrix
> > covariancematrix=cov(X1new,Y1new);
> >
> > % step 3 - Finding Eigenvectors
> > [V,D] = eig(covariancematrix);
> > D=diag(D);
> > maxeigval=V(:,find(D==max(D)));
> >
> > % step 4 - Deriving the new data set
> > % Finding the projection onto the eigenvectors
> >
> > finaldata=maxeigval'*[X1new,Y1new]';
> > subplot(5,1,4);
> > stem(finaldata, 'DisplayName', 'finaldata', 'YDataSource', 'finaldata');
> > title('PCA output ')
> >
> > Someone can help me?
> > Thanks.
>
>
> Hi,
>
> What is your objective ? What are you hopping to obtain from your PCA ?
> Are you applaying PCA to two vectors, which are obtain from a histogram ?
>
> Regards,
>
> Florin

Subject: PCA

From: Florin Neacsu

Date: 5 Apr, 2011 23:49:04

Message: 4 of 6

"Caio " <caiovtrich@gmail.com> wrote in message <ing7gs$3g5$1@fred.mathworks.com>...
> Hi,
> First i manipulate my images from orange trees with citrus canker to obtain histograms. I think that applying the PCA method in this histograms i can observe the the time evolution of the disease. In this case, i have many histograms that each one can be a pair of vectors. My objective is try to see some relations when i plot the first and second principal components.
> Are you understand?
> Thanks.
>
> "Florin Neacsu" <fneacsu2@gmail.com> wrote in message <infvuv$bl$1@fred.mathworks.com>...
> > "Caio " <caiovtrich@gmail.com> wrote in message <infpg9$6op$1@fred.mathworks.com>...
> > > Hi,
> > > I am having problens with doing the PCA analysis. I want to plot the first and second principal components of a image histogram. Here is my rotine.
> > > X1 and Y1 are columns of my histrogam
> > >
> > >
> > > % Applying Principal Component Analysis - PCA
> > >
> > > %step 1, finding a mean and subtracting
> > > X1mean=mean(X1);
> > > Y1mean=mean(Y1);
> > >
> > > [a,b]=size(X1);
> > > X1new=X1-X1mean*ones(a,1);
> > > Y1new=Y1-Y1mean*ones(a,1);
> > >
> > > subplot(5,1,2);
> > > plot(X1,Y1, 'o');
> > > title('Histogram Data');
> > >
> > > subplot(5,1,3);
> > > plot(X1new,X1new, 'o');
> > > title('mean is deducted')
> > >
> > > % step 2 - Covariance Matrix
> > > covariancematrix=cov(X1new,Y1new);
> > >
> > > % step 3 - Finding Eigenvectors
> > > [V,D] = eig(covariancematrix);
> > > D=diag(D);
> > > maxeigval=V(:,find(D==max(D)));
> > >
> > > % step 4 - Deriving the new data set
> > > % Finding the projection onto the eigenvectors
> > >
> > > finaldata=maxeigval'*[X1new,Y1new]';
> > > subplot(5,1,4);
> > > stem(finaldata, 'DisplayName', 'finaldata', 'YDataSource', 'finaldata');
> > > title('PCA output ')
> > >
> > > Someone can help me?
> > > Thanks.
> >
> >
> > Hi,
> >
> > What is your objective ? What are you hopping to obtain from your PCA ?
> > Are you applaying PCA to two vectors, which are obtain from a histogram ?
> >
> > Regards,
> >
> > Florin

Hi,

I don't fully understand. Your inputs are 2 vectors. Are these vectors coming from one histogram or more ?

Florin

Subject: PCA

From: Caio

Date: 6 Apr, 2011 11:41:04

Message: 5 of 6

This two vectors come just from one histogram, but i have many histograms for differents days.

Subject: PCA

From: Florin Neacsu

Date: 6 Apr, 2011 15:57:04

Message: 6 of 6

"Caio " <caiovtrich@gmail.com> wrote in message <inhjgg$fa3$1@fred.mathworks.com>...
> This two vectors come just from one histogram, but i have many histograms for differents days.

Hi,

I really am trying to understand what you are doing, but I have a hard time. Are you using imhist ? Are your images grayscale or binary ?

In any case, my understanding is that PCA is used to reduce the dimensionality of a system. Let's say you have a cloud of points that aren't random but in the vicinity of a line. You can use PCA to obtain a vector that would give you this line. Or charactarize countries by food habits ... These are the classic examples I can think of. My point is, if you only have 2 vectors from one histogram, what are you expecting to obtain ? Remeber that a histogram for a grayscale image will tell you how many pixels you have for each level. So if you take one column it will look something like [113,100] with 113=gray level and 100=number of pixels.

I don't know if this helps. Maybe I am way off the topic here.
Good luck.

Florin

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us