Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slpixlinnorm
Home > sltoolbox > imgproc > slpixlinnorm.m

slpixlinnorm

PURPOSE ^

SLPIXLINNORM Performs linear normalization on pixel values

SYNOPSIS ^

function dstimgs = slpixlinnorm(imgs, mu, sigma)

DESCRIPTION ^

SLPIXLINNORM Performs linear normalization on pixel values

 $ Syntax $
   - dstimgs = slpixlinnorm(imgs);
   - dstimgs = slpixlinnorm(imgs, mu, sigma)

 $ Arguments $
   - imgs:     the array of images
   - mu:       the mean pixel value to be normalized to (default = 0)
   - sigma:    the standard deviation relative to mean pixel (default = 1)

 $ Description $
   - dstimgs = slpixlinnorm(imgs, mu, sigma) performs linear normalization
     on the image pixels so that the average pixel value is set to mu
     while the standard deviation is set to sigma. The normalization is
     conducted on each page(channel) respectively.

   - dstimgs = slpixlinnorm(imgs) performs linear pixel value
     normalization using default values.

 $ History $
   - Created by Dahua Lin, on Aug 8th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function dstimgs = slpixlinnorm(imgs, mu, sigma)
0002 %SLPIXLINNORM Performs linear normalization on pixel values
0003 %
0004 % $ Syntax $
0005 %   - dstimgs = slpixlinnorm(imgs);
0006 %   - dstimgs = slpixlinnorm(imgs, mu, sigma)
0007 %
0008 % $ Arguments $
0009 %   - imgs:     the array of images
0010 %   - mu:       the mean pixel value to be normalized to (default = 0)
0011 %   - sigma:    the standard deviation relative to mean pixel (default = 1)
0012 %
0013 % $ Description $
0014 %   - dstimgs = slpixlinnorm(imgs, mu, sigma) performs linear normalization
0015 %     on the image pixels so that the average pixel value is set to mu
0016 %     while the standard deviation is set to sigma. The normalization is
0017 %     conducted on each page(channel) respectively.
0018 %
0019 %   - dstimgs = slpixlinnorm(imgs) performs linear pixel value
0020 %     normalization using default values.
0021 %
0022 % $ History $
0023 %   - Created by Dahua Lin, on Aug 8th, 2006
0024 %
0025 
0026 %% parse and verify input arguments
0027 
0028 if ~isa(imgs, 'double')
0029     imgs = im2double(imgs);
0030 end
0031 [h, w, n] = size(imgs);
0032 
0033 if nargin < 2 || isempty(mu)
0034     mu = 0;
0035 end
0036 
0037 if nargin < 3 || isempty(sigma)
0038     sigma = 1;
0039 end
0040 
0041 d = h * w;
0042 
0043 %% perform normalization
0044 
0045 if n == 1
0046     dstimgs = normalize_page(imgs, d, mu, sigma);
0047 else
0048     dstimgs = zeros(size(imgs));
0049     for i = 1 : n
0050         dstimgs(:,:,i) = normalize_page(imgs(:,:,i), d, mu, sigma);
0051     end
0052 end
0053 
0054 
0055 function dstimg = normalize_page(img, d, mu, sigma)
0056 
0057 curimg = img(:);
0058 
0059 % compute current mean value
0060 cur_mv = sum(curimg) / d;
0061 
0062 % shift to zero mean
0063 curimg = curimg - cur_mv;
0064 
0065 % compute current standard deviation
0066 cur_std = norm(curimg) / sqrt(d);
0067 
0068 % normalize to specified std dev
0069 k = sigma / cur_std;
0070 curimg = curimg * k;
0071 
0072 % shift to specified mean
0073 if mu ~= 0
0074     curimg = curimg + mu;
0075 end
0076 
0077 % reshape back to origin shape
0078 dstimg = reshape(curimg, size(img));
0079 
0080 
0081 
0082 
0083 
0084

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com