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:
Mean Normalization problem for PCA in GrayImage

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 2 Nov, 2010 15:02:04

Message: 1 of 10

I have arranged my 10 GRAY image array samples into 10 rows. Each row contains a gray image. The arranged array is "unit8". Now I want to subtract the mean from that array. I have calculated the mean. But the mean type is "double". So it cannot subtract from the arranged array. it says "Integers can only be combined with integers of the same class, or scalar doubles."

% B = rearranged image array which contains 10 rows and 256 columns
[r c] = size(B);
for i = 1: r % mean normalization
A(i,:) = B(i,:)- m;
end
the error shows here.

What should I do..?
btw.. I am doing this mean normalization to use PCA.

Subject: Mean Normalization problem for PCA in GrayImage

From: Sean

Date: 2 Nov, 2010 15:10:06

Message: 2 of 10

"Nehal " <arnab620@yahoo.com> wrote in message <iap95c$mah$1@fred.mathworks.com>...
> I have arranged my 10 GRAY image array samples into 10 rows. Each row contains a gray image. The arranged array is "unit8". Now I want to subtract the mean from that array. I have calculated the mean. But the mean type is "double". So it cannot subtract from the arranged array. it says "Integers can only be combined with integers of the same class, or scalar doubles."
>
> % B = rearranged image array which contains 10 rows and 256 columns
> [r c] = size(B);
> for i = 1: r % mean normalization
> A(i,:) = B(i,:)- m;
> end
> the error shows here.
>
> What should I do..?
> btw.. I am doing this mean normalization to use PCA.

%for the class/integer issue:
doc cast
doc uint8

%for the subtraction:
doc bsxfun

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 2 Nov, 2010 15:13:04

Message: 3 of 10

here...
m = mean(B);

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 2 Nov, 2010 15:30:09

Message: 4 of 10

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iap9ke$oef$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <iap95c$mah$1@fred.mathworks.com>...
> %for the class/integer issue:
> doc cast
> doc uint8
>
> %for the subtraction:
> doc bsxfun

still, I am not getting it. I have seen the examples. Should I convert unit8 to double or should I convert double to unit8? Which one should I do..?

Subject: Mean Normalization problem for PCA in GrayImage

From: Sean

Date: 2 Nov, 2010 15:52:04

Message: 5 of 10

"Nehal " <arnab620@yahoo.com> wrote in message <iapaq1$fl5$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iap9ke$oef$1@fred.mathworks.com>...
> > "Nehal " <arnab620@yahoo.com> wrote in message <iap95c$mah$1@fred.mathworks.com>...
> > %for the class/integer issue:
> > doc cast
> > doc uint8
> >
> > %for the subtraction:
> > doc bsxfun
>
> still, I am not getting it. I have seen the examples. Should I convert unit8 to double or should I convert double to unit8? Which one should I do..?

What are the ranges of your doubles? How big are the images? What do you want to do with the images?

My recommendations: for display purposes, gigantic matrices, and saving, use uint8; for math use double.

Subject: Mean Normalization problem for PCA in GrayImage

From: ImageAnalyst

Date: 2 Nov, 2010 16:08:27

Message: 6 of 10

Nehal:
Your mean is a floating point number, so your result will need to be
also. Just do this:
meanGrayLevel = mean(uint8Image(:));
diffFromMean = double(uint8Image) - meanGrayLevel ;

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 2 Nov, 2010 16:26:05

Message: 7 of 10

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iapc34$c4i$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <iapaq1$fl5$1@fred.mathworks.com>...
> > "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <iap9ke$oef$1@fred.mathworks.com>...
> > > "Nehal " <arnab620@yahoo.com> wrote in message <iap95c$mah$1@fred.mathworks.com>...
> What are the ranges of your doubles? How big are the images? What do you want to do with the images?
> My recommendations: for display purposes, gigantic matrices, and saving, use uint8; for math use double.
I am working on Sign Language translator and my image size is 16x16. I do not need to display it. I just need to use those images to train the matlab and then test with some other samples like those.

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 2 Nov, 2010 16:28:06

Message: 8 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <59c818af-29d8-49e3-8d6f-d1b68c65f7fc@f33g2000yqh.googlegroups.com>...
> Nehal:
> Your mean is a floating point number, so your result will need to be
> also. Just do this:
> meanGrayLevel = mean(uint8Image(:));
> diffFromMean = double(uint8Image) - meanGrayLevel ;

That's it? Coz i read somewhere that if I change a unit8Image into double, the values are changed. Changes in values will create problems, right..?

and what is floating point number..?

Subject: Mean Normalization problem for PCA in GrayImage

From: Image Analyst

Date: 2 Nov, 2010 21:05:08

Message: 9 of 10

Nehal :
That's it. Using double() does not change the numbers. Using imdouble() *will* change the numbers because it will normalize the numbers to between 0 and 1 - that's probably what you were thinking of.

A floating point number is a single or double type of variable that can take on fractional values, like 1.3456. An integer number is of type uint8, uint16, int32, etc. and can only take on integer values - no fractions allowed.

Subject: Mean Normalization problem for PCA in GrayImage

From: Nehal

Date: 3 Nov, 2010 03:02:04

Message: 10 of 10

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <iapue4$nr5$1@fred.mathworks.com>...
> Nehal :
> That's it. Using double() does not change the numbers. Using imdouble() *will* change the numbers because it will normalize the numbers to between 0 and 1 - that's probably what you were thinking of.
>
> A floating point number is a single or double type of variable that can take on fractional values, like 1.3456. An integer number is of type uint8, uint16, int32, etc. and can only take on integer values - no fractions allowed.
Thank You. Now it's clear.

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