Image Normalization using Standard deviation - example source code

You can understand Standard deviation normalization, referenced on this web page.
http://www.d.umn.edu/~deoka001/Normalization.html
This web page introduce that..(wrote by Siddharth Deokar)

-------------------------------------------------------------------------
Normalization by Standard Deviation
We normalize the attribute values by using standard deviation.

For Example:

Consider 5 instances which has attribute A with the follwing values: {-5, 6, 9, 2, 4}

First we calculate the mean as follows:

Mean = (-5+6+9+2+4) / 5 = 3.2

Second, we subtract the mean from all the values and square them:

(-5-3.2)^2 = 67.24
(6-3.2)^2 = 7.84
(9-3.2)^2 = 33.64
(2-3.2)^2 = 1.44
(4-3.2)^2 = 0.64

Then we find the deviation as follows:

Deviation = sqrt ((67.24 + 7.84 + 33.64 + 1.44 + 0.64) / 5) = 4.71

Now we normalize the attribute values:

x => (x - Mean) / Deviation

-5 => (-5 - 3.2) / 4.71 = -1.74
6 => (6 - 3.2) / 4.71 = 0.59
9 => (9 - 3.2) / 4.71 = 1.23
2 => (2 - 3.2) / 4.71 = -0.25
4 => (4 - 3.2) / 4.71 = 0.17

-------------------------------------------------------------------------



This is sample source code:

//

int i,j,z;
 double sum=0; 
 double Mean;
 
 //sum, mean
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {
   sum = sum + Pdata[i][j];
  }
 }

 Mean = sum/(Height*Width);
 
 //Deviation
 double dSum=0;
 double deviation;
 double std_dev; 
 
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {        
   Pdata[i][j] = (Pdata[i][j] - Mean);

   dSum = dSum + (Pdata[i][j]*Pdata[i][j]);
  }
 }
 
 deviation = dSum / (Width*Height);
 std_dev = sqrt(deviation);
 
 //Normalization
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {        
   Pdata[i][j] = (Pdata[i][j] / std_dev);
  }
 }

Comments

Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

(C, C++) TinyXML , xml read & write