wolffd@0: function [x,sNorm] = som_norm_variable(x, method, operation) wolffd@0: wolffd@0: %SOM_NORM_VARIABLE Normalize or denormalize a scalar variable. wolffd@0: % wolffd@0: % [x,sNorm] = som_norm_variable(x, method, operation) wolffd@0: % wolffd@0: % xnew = som_norm_variable(x,'var','do'); wolffd@0: % [dummy,sN] = som_norm_variable(x,'log','init'); wolffd@0: % [xnew,sN] = som_norm_variable(x,sN,'do'); wolffd@0: % xorig = som_norm_variable(xnew,sN,'undo'); wolffd@0: % wolffd@0: % Input and output arguments: wolffd@0: % x (vector) a set of values of a scalar variable for wolffd@0: % which the (de)normalization is performed. wolffd@0: % The processed values are returned. wolffd@0: % method (string) identifier for a normalization method: 'var', wolffd@0: % 'range', 'log', 'logistic', 'histD', or 'histC'. wolffd@0: % A normalization struct with default values is created. wolffd@0: % (struct) normalization struct, or an array of such wolffd@0: % (cellstr) first string gives normalization operation, and the wolffd@0: % second gives denormalization operation, with x wolffd@0: % representing the variable, for example: wolffd@0: % {'x+2','x-2}, or {'exp(-x)','-log(x)'} or {'round(x)'}. wolffd@0: % Note that in the last case, no denorm operation is wolffd@0: % defined. wolffd@0: % operation (string) the operation to be performed: 'init', 'do' or 'undo' wolffd@0: % wolffd@0: % sNorm (struct) updated normalization struct/struct array wolffd@0: % wolffd@0: % For more help, try 'type som_norm_variable' or check out online documentation. wolffd@0: % See also SOM_NORMALIZE, SOM_DENORMALIZE. wolffd@0: wolffd@0: %%%%%%%%%%%%% DETAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: % wolffd@0: % som_norm_variable wolffd@0: % wolffd@0: % PURPOSE wolffd@0: % wolffd@0: % Initialize, apply and undo normalizations on a given vector of wolffd@0: % scalar values. wolffd@0: % wolffd@0: % SYNTAX wolffd@0: % wolffd@0: % xnew = som_norm_variable(x,method,operation) wolffd@0: % xnew = som_norm_variable(x,sNorm,operation) wolffd@0: % [xnew,sNorm] = som_norm_variable(...) wolffd@0: % wolffd@0: % DESCRIPTION wolffd@0: % wolffd@0: % This function is used to initialize, apply and undo normalizations wolffd@0: % on scalar variables. It is the low-level function that upper-level wolffd@0: % functions SOM_NORMALIZE and SOM_DENORMALIZE utilize to actually (un)do wolffd@0: % the normalizations. wolffd@0: % wolffd@0: % Normalizations are typically performed to control the variance of wolffd@0: % vector components. If some vector components have variance which is wolffd@0: % significantly higher than the variance of other components, those wolffd@0: % components will dominate the map organization. Normalization of wolffd@0: % the variance of vector components (method 'var') is used to prevent wolffd@0: % that. In addition to variance normalization, other methods have wolffd@0: % been implemented as well (see list below). wolffd@0: % wolffd@0: % Usually normalizations convert the variable values so that they no wolffd@0: % longer make any sense: the values are still ordered, but their range wolffd@0: % may have changed so radically that interpreting the numbers in the wolffd@0: % original context is very hard. For this reason all implemented methods wolffd@0: % are (more or less) revertible. The normalizations are monotonic wolffd@0: % and information is saved so that they can be undone. Also, the saved wolffd@0: % information makes it possible to apply the EXACTLY SAME normalization wolffd@0: % to another set of values. The normalization information is determined wolffd@0: % with 'init' operation, while 'do' and 'undo' operations are used to wolffd@0: % apply or revert the normalization. wolffd@0: % wolffd@0: % The normalization information is saved in a normalization struct, wolffd@0: % which is returned as the second argument of this function. Note that wolffd@0: % normalization operations may be stacked. In this case, normalization wolffd@0: % structs are positioned in a struct array. When applied, the array is wolffd@0: % gone through from start to end, and when undone, in reverse order. wolffd@0: % wolffd@0: % method description wolffd@0: % wolffd@0: % 'var' Variance normalization. A linear transformation which wolffd@0: % scales the values such that their variance=1. This is wolffd@0: % convenient way to use Mahalanobis distance measure without wolffd@0: % actually changing the distance calculation procedure. wolffd@0: % wolffd@0: % 'range' Normalization of range of values. A linear transformation wolffd@0: % which scales the values between [0,1]. wolffd@0: % wolffd@0: % 'log' Logarithmic normalization. In many cases the values of wolffd@0: % a vector component are exponentially distributed. This wolffd@0: % normalization is a good way to get more resolution to wolffd@0: % (the low end of) that vector component. What this wolffd@0: % actually does is a non-linear transformation: wolffd@0: % x_new = log(x_old - m + 1) wolffd@0: % where m=min(x_old) and log is the natural logarithm. wolffd@0: % Applying the transformation to a value which is lower wolffd@0: % than m-1 will give problems, as the result is then complex. wolffd@0: % If the minimum for values is known a priori, wolffd@0: % it might be a good idea to initialize the normalization with wolffd@0: % [dummy,sN] = som_norm_variable(minimum,'log','init'); wolffd@0: % and normalize only after this: wolffd@0: % x_new = som_norm_variable(x,sN,'do'); wolffd@0: % wolffd@0: % 'logistic' or softmax normalization. This normalization ensures wolffd@0: % that all values in the future, too, are within the range wolffd@0: % [0,1]. The transformation is more-or-less linear in the wolffd@0: % middle range (around mean value), and has a smooth wolffd@0: % nonlinearity at both ends which ensures that all values wolffd@0: % are within the range. The data is first scaled as in wolffd@0: % variance normalization: wolffd@0: % x_scaled = (x_old - mean(x_old))/std(x_old) wolffd@0: % and then transformed with the logistic function wolffd@0: % x_new = 1/(1+exp(-x_scaled)) wolffd@0: % wolffd@0: % 'histD' Discrete histogram equalization. Non-linear. Orders the wolffd@0: % values and replaces each value by its ordinal number. wolffd@0: % Finally, scales the values such that they are between [0,1]. wolffd@0: % Useful for both discrete and continuous variables, but as wolffd@0: % the saved normalization information consists of all wolffd@0: % unique values of the initialization data set, it may use wolffd@0: % considerable amounts of memory. If the variable can get wolffd@0: % more than a few values (say, 20), it might be better to wolffd@0: % use 'histC' method below. Another important note is that wolffd@0: % this method is not exactly revertible if it is applied wolffd@0: % to values which are not part of the original value set. wolffd@0: % wolffd@0: % 'histC' Continuous histogram equalization. Actually, a partially wolffd@0: % linear transformation which tries to do something like wolffd@0: % histogram equalization. The value range is divided to wolffd@0: % a number of bins such that the number of values in each wolffd@0: % bin is (almost) the same. The values are transformed wolffd@0: % linearly in each bin. For example, values in bin number 3 wolffd@0: % are scaled between [3,4[. Finally, all values are scaled wolffd@0: % between [0,1]. The number of bins is the square root wolffd@0: % of the number of unique values in the initialization set, wolffd@0: % rounded up. The resulting histogram equalization is not wolffd@0: % as good as the one that 'histD' makes, but the benefit wolffd@0: % is that it is exactly revertible - even outside the wolffd@0: % original value range (although the results may be funny). wolffd@0: % wolffd@0: % 'eval' With this method, freeform normalization operations can be wolffd@0: % specified. The parameter field contains strings to be wolffd@0: % evaluated with 'eval' function, with variable name 'x' wolffd@0: % representing the variable itself. The first string is wolffd@0: % the normalization operation, and the second is a wolffd@0: % denormalization operation. If the denormalization operation wolffd@0: % is empty, it is ignored. wolffd@0: % wolffd@0: % INPUT ARGUMENTS wolffd@0: % wolffd@0: % x (vector) The scalar values to which the normalization wolffd@0: % operation is applied. wolffd@0: % wolffd@0: % method The normalization specification. wolffd@0: % (string) Identifier for a normalization method: 'var', wolffd@0: % 'range', 'log', 'logistic', 'histD' or 'histC'. wolffd@0: % Corresponding default normalization struct is created. wolffd@0: % (struct) normalization struct wolffd@0: % (struct array) of normalization structs, applied to wolffd@0: % x one after the other wolffd@0: % (cellstr) of length wolffd@0: % (cellstr array) first string gives normalization operation, and wolffd@0: % the second gives denormalization operation, with x wolffd@0: % representing the variable, for example: wolffd@0: % {'x+2','x-2}, or {'exp(-x)','-log(x)'} or {'round(x)'}. wolffd@0: % Note that in the last case, no denorm operation is wolffd@0: % defined. wolffd@0: % wolffd@0: % note: if the method is given as struct(s), it is wolffd@0: % applied (done or undone, as specified by operation) wolffd@0: % regardless of what the value of '.status' field wolffd@0: % is in the struct(s). Only if the status is wolffd@0: % 'uninit', the undoing operation is halted. wolffd@0: % Anyhow, the '.status' fields in the returned wolffd@0: % normalization struct(s) is set to approriate value. wolffd@0: % wolffd@0: % operation (string) The operation to perform: 'init' to initialize wolffd@0: % the normalization struct, 'do' to perform the wolffd@0: % normalization, 'undo' to undo the normalization, wolffd@0: % if possible. If operation 'do' is given, but the wolffd@0: % normalization struct has not yet been initialized, wolffd@0: % it is initialized using the given data (x). wolffd@0: % wolffd@0: % OUTPUT ARGUMENTS wolffd@0: % wolffd@0: % x (vector) Appropriately processed values. wolffd@0: % wolffd@0: % sNorm (struct) Updated normalization struct/struct array. If any, wolffd@0: % the '.status' and '.params' fields are updated. wolffd@0: % wolffd@0: % EXAMPLES wolffd@0: % wolffd@0: % To initialize and apply a normalization on a set of scalar values: wolffd@0: % wolffd@0: % [x_new,sN] = som_norm_variable(x_old,'var','do'); wolffd@0: % wolffd@0: % To just initialize, use: wolffd@0: % wolffd@0: % [dummy,sN] = som_norm_variable(x_old,'var','init'); wolffd@0: % wolffd@0: % To undo the normalization(s): wolffd@0: % wolffd@0: % x_orig = som_norm_variable(x_new,sN,'undo'); wolffd@0: % wolffd@0: % Typically, normalizations of data structs/sets are handled using wolffd@0: % functions SOM_NORMALIZE and SOM_DENORMALIZE. However, when only the wolffd@0: % values of a single variable are of interest, SOM_NORM_VARIABLE may wolffd@0: % be useful. For example, assume one wants to apply the normalization wolffd@0: % done on a component (i) of a data struct (sD) to a new set of values wolffd@0: % (x) of that component. With SOM_NORM_VARIABLE this can be done with: wolffd@0: % wolffd@0: % x_new = som_norm_variable(x,sD.comp_norm{i},'do'); wolffd@0: % wolffd@0: % Now, as the normalizations in sD.comp_norm{i} have already been wolffd@0: % initialized with the original data set (presumably sD.data), wolffd@0: % the EXACTLY SAME normalization(s) can be applied to the new values. wolffd@0: % The same thing can be done with SOM_NORMALIZE function, too: wolffd@0: % wolffd@0: % x_new = som_normalize(x,sD.comp_norm{i}); wolffd@0: % wolffd@0: % Or, if the new data set were in variable D - a matrix of same wolffd@0: % dimension as the original data set: wolffd@0: % wolffd@0: % D_new = som_normalize(D,sD,i); wolffd@0: % wolffd@0: % SEE ALSO wolffd@0: % wolffd@0: % som_normalize Add/apply/redo normalizations for a data struct/set. wolffd@0: % som_denormalize Undo normalizations of a data struct/set. wolffd@0: wolffd@0: % Copyright (c) 1998-2000 by the SOM toolbox programming team. wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta juuso 151199 170400 150500 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% check arguments wolffd@0: wolffd@0: error(nargchk(3, 3, nargin)); % check no. of input arguments is correct wolffd@0: wolffd@0: % method wolffd@0: sNorm = []; wolffd@0: if ischar(method) wolffd@0: if any(strcmp(method,{'var','range','log','logistic','histD','histC'})), wolffd@0: sNorm = som_set('som_norm','method',method); wolffd@0: else wolffd@0: method = cellstr(method); wolffd@0: end wolffd@0: end wolffd@0: if iscell(method), wolffd@0: if length(method)==1 & isstruct(method{1}), sNorm = method{1}; wolffd@0: else wolffd@0: if length(method)==1 | isempty(method{2}), method{2} = 'x'; end wolffd@0: sNorm = som_set('som_norm','method','eval','params',method); wolffd@0: end wolffd@0: else wolffd@0: sNorm = method; wolffd@0: end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% action wolffd@0: wolffd@0: order = [1:length(sNorm)]; wolffd@0: if length(order)>1 & strcmp(operation,'undo'), order = order(end:-1:1); end wolffd@0: wolffd@0: for i=order, wolffd@0: wolffd@0: % initialize wolffd@0: if strcmp(operation,'init') | ... wolffd@0: (strcmp(operation,'do') & strcmp(sNorm(i).status,'uninit')), wolffd@0: wolffd@0: % case method = 'hist' wolffd@0: if strcmp(sNorm(i).method,'hist'), wolffd@0: inds = find(~isnan(x) & ~isinf(x)); wolffd@0: if length(unique(x(inds)))>20, sNorm(i).method = 'histC'; wolffd@0: else sNorm{i}.method = 'histD'; end wolffd@0: end wolffd@0: wolffd@0: switch(sNorm(i).method), wolffd@0: case 'var', params = norm_variance_init(x); wolffd@0: case 'range', params = norm_scale01_init(x); wolffd@0: case 'log', params = norm_log_init(x); wolffd@0: case 'logistic', params = norm_logistic_init(x); wolffd@0: case 'histD', params = norm_histeqD_init(x); wolffd@0: case 'histC', params = norm_histeqC_init(x); wolffd@0: case 'eval', params = sNorm(i).params; wolffd@0: otherwise, wolffd@0: error(['Unrecognized method: ' sNorm(i).method]); wolffd@0: end wolffd@0: sNorm(i).params = params; wolffd@0: sNorm(i).status = 'undone'; wolffd@0: end wolffd@0: wolffd@0: % do / undo wolffd@0: if strcmp(operation,'do'), wolffd@0: switch(sNorm(i).method), wolffd@0: case 'var', x = norm_scale_do(x,sNorm(i).params); wolffd@0: case 'range', x = norm_scale_do(x,sNorm(i).params); wolffd@0: case 'log', x = norm_log_do(x,sNorm(i).params); wolffd@0: case 'logistic', x = norm_logistic_do(x,sNorm(i).params); wolffd@0: case 'histD', x = norm_histeqD_do(x,sNorm(i).params); wolffd@0: case 'histC', x = norm_histeqC_do(x,sNorm(i).params); wolffd@0: case 'eval', x = norm_eval_do(x,sNorm(i).params); wolffd@0: otherwise, wolffd@0: error(['Unrecognized method: ' sNorm(i).method]); wolffd@0: end wolffd@0: sNorm(i).status = 'done'; wolffd@0: wolffd@0: elseif strcmp(operation,'undo'), wolffd@0: wolffd@0: if strcmp(sNorm(i).status,'uninit'), wolffd@0: warning('Could not undo: uninitialized normalization struct.') wolffd@0: break; wolffd@0: end wolffd@0: switch(sNorm(i).method), wolffd@0: case 'var', x = norm_scale_undo(x,sNorm(i).params); wolffd@0: case 'range', x = norm_scale_undo(x,sNorm(i).params); wolffd@0: case 'log', x = norm_log_undo(x,sNorm(i).params); wolffd@0: case 'logistic', x = norm_logistic_undo(x,sNorm(i).params); wolffd@0: case 'histD', x = norm_histeqD_undo(x,sNorm(i).params); wolffd@0: case 'histC', x = norm_histeqC_undo(x,sNorm(i).params); wolffd@0: case 'eval', x = norm_eval_undo(x,sNorm(i).params); wolffd@0: otherwise, wolffd@0: error(['Unrecognized method: ' sNorm(i).method]); wolffd@0: end wolffd@0: sNorm(i).status = 'undone'; wolffd@0: wolffd@0: elseif ~strcmp(operation,'init'), wolffd@0: wolffd@0: error(['Unrecognized operation: ' operation]) wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: return; wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% subfunctions wolffd@0: wolffd@0: % linear scaling wolffd@0: wolffd@0: function p = norm_variance_init(x) wolffd@0: inds = find(~isnan(x) & isfinite(x)); wolffd@0: p = [mean(x(inds)), std(x(inds))]; wolffd@0: if p(2) == 0, p(2) = 1; end wolffd@0: %end of norm_variance_init wolffd@0: wolffd@0: function p = norm_scale01_init(x) wolffd@0: inds = find(~isnan(x) & isfinite(x)); wolffd@0: mi = min(x(inds)); wolffd@0: ma = max(x(inds)); wolffd@0: if mi == ma, p = [mi, 1]; else p = [mi, ma-mi]; end wolffd@0: %end of norm_scale01_init wolffd@0: wolffd@0: function x = norm_scale_do(x,p) wolffd@0: x = (x - p(1)) / p(2); wolffd@0: % end of norm_scale_do wolffd@0: wolffd@0: function x = norm_scale_undo(x,p) wolffd@0: x = x * p(2) + p(1); wolffd@0: % end of norm_scale_undo wolffd@0: wolffd@0: % logarithm wolffd@0: wolffd@0: function p = norm_log_init(x) wolffd@0: inds = find(~isnan(x) & isfinite(x)); wolffd@0: p = min(x(inds)); wolffd@0: % end of norm_log_init wolffd@0: wolffd@0: function x = norm_log_do(x,p) wolffd@0: x = log(x - p +1); wolffd@0: % if any(~isreal(x)), ok = 0; end wolffd@0: % end of norm_log_do wolffd@0: wolffd@0: function x = norm_log_undo(x,p) wolffd@0: x = exp(x) -1 + p; wolffd@0: % end of norm_log_undo wolffd@0: wolffd@0: % logistic wolffd@0: wolffd@0: function p = norm_logistic_init(x) wolffd@0: inds = find(~isnan(x) & isfinite(x)); wolffd@0: p = [mean(x(inds)), std(x(inds))]; wolffd@0: if p(2)==0, p(2) = 1; end wolffd@0: % end of norm_logistic_init wolffd@0: wolffd@0: function x = norm_logistic_do(x,p) wolffd@0: x = (x-p(1))/p(2); wolffd@0: x = 1./(1+exp(-x)); wolffd@0: % end of norm_logistic_do wolffd@0: wolffd@0: function x = norm_logistic_undo(x,p) wolffd@0: x = log(x./(1-x)); wolffd@0: x = x*p(2)+p(1); wolffd@0: % end of norm_logistic_undo wolffd@0: wolffd@0: % histogram equalization for discrete values wolffd@0: wolffd@0: function p = norm_histeqD_init(x) wolffd@0: inds = find(~isnan(x) & ~isinf(x)); wolffd@0: p = unique(x(inds)); wolffd@0: % end of norm_histeqD_init wolffd@0: wolffd@0: function x = norm_histeqD_do(x,p) wolffd@0: bins = length(p); wolffd@0: inds = find(~isnan(x) & ~isinf(x))'; wolffd@0: for i = inds, wolffd@0: [dummy ind] = min(abs(x(i) - p)); wolffd@0: % data item closer to the left-hand bin wall is indexed after RH wall wolffd@0: if x(i) > p(ind) & ind < bins, wolffd@0: x(i) = ind + 1; wolffd@0: else wolffd@0: x(i) = ind; wolffd@0: end wolffd@0: end wolffd@0: x = (x-1)/(bins-1); % normalization between [0,1] wolffd@0: % end of norm_histeqD_do wolffd@0: wolffd@0: function x = norm_histeqD_undo(x,p) wolffd@0: bins = length(p); wolffd@0: x = round(x*(bins-1)+1); wolffd@0: inds = find(~isnan(x) & ~isinf(x)); wolffd@0: x(inds) = p(x(inds)); wolffd@0: % end of norm_histeqD_undo wolffd@0: wolffd@0: % histogram equalization with partially linear functions wolffd@0: wolffd@0: function p = norm_histeqC_init(x) wolffd@0: % investigate x wolffd@0: inds = find(~isnan(x) & ~isinf(x)); wolffd@0: samples = length(inds); wolffd@0: xs = unique(x(inds)); wolffd@0: mi = xs(1); wolffd@0: ma = xs(end); wolffd@0: % decide number of limits wolffd@0: lims = ceil(sqrt(length(xs))); % 2->2,100->10,1000->32,10000->100 wolffd@0: % decide limits wolffd@0: if lims==1, wolffd@0: p = [mi, mi+1]; wolffd@0: lims = 2; wolffd@0: elseif lims==2, wolffd@0: p = [mi, ma]; wolffd@0: else wolffd@0: p = zeros(lims,1); wolffd@0: p(1) = mi; wolffd@0: p(end) = ma; wolffd@0: binsize = zeros(lims-1,1); b = 1; avebinsize = samples/(lims-1); wolffd@0: for i=1:(length(xs)-1), wolffd@0: binsize(b) = binsize(b) + sum(x==xs(i)); wolffd@0: if binsize(b) >= avebinsize, wolffd@0: b = b + 1; wolffd@0: p(b) = (xs(i)+xs(i+1))/2; wolffd@0: end wolffd@0: if b==(lims-1), wolffd@0: binsize(b) = samples-sum(binsize); break; wolffd@0: else wolffd@0: avebinsize = (samples-sum(binsize))/(lims-1-b); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: % end of norm_histeqC_init wolffd@0: wolffd@0: function x = norm_histeqC_do(x,p) wolffd@0: xnew = x; wolffd@0: lims = length(p); wolffd@0: % handle values below minimum wolffd@0: r = p(2)-p(1); wolffd@0: inds = find(x<=p(1) & isfinite(x)); wolffd@0: if any(inds), xnew(inds) = 0-(p(1)-x(inds))/r; end wolffd@0: % handle values above maximum wolffd@0: r = p(end)-p(end-1); wolffd@0: inds = find(x>p(end) & isfinite(x)); wolffd@0: if any(inds), xnew(inds) = lims-1+(x(inds)-p(end))/r; end wolffd@0: % handle all other values wolffd@0: for i=1:(lims-1), wolffd@0: r0 = p(i); r1 = p(i+1); r = r1-r0; wolffd@0: inds = find(x>r0 & x<=r1); wolffd@0: if any(inds), xnew(inds) = i-1+(x(inds)-r0)/r; end wolffd@0: end wolffd@0: % scale so that minimum and maximum correspond to 0 and 1 wolffd@0: x = xnew/(lims-1); wolffd@0: % end of norm_histeqC_do wolffd@0: wolffd@0: function x = norm_histeqC_undo(x,p) wolffd@0: xnew = x; wolffd@0: lims = length(p); wolffd@0: % scale so that 0 and 1 correspond to minimum and maximum wolffd@0: x = x*(lims-1); wolffd@0: wolffd@0: % handle values below minimum wolffd@0: r = p(2)-p(1); wolffd@0: inds = find(x<=0 & isfinite(x)); wolffd@0: if any(inds), xnew(inds) = x(inds)*r + p(1); end wolffd@0: % handle values above maximum wolffd@0: r = p(end)-p(end-1); wolffd@0: inds = find(x>lims-1 & isfinite(x)); wolffd@0: if any(inds), xnew(inds) = (x(inds)-(lims-1))*r+p(end); end wolffd@0: % handle all other values wolffd@0: for i=1:(lims-1), wolffd@0: r0 = p(i); r1 = p(i+1); r = r1-r0; wolffd@0: inds = find(x>i-1 & x<=i); wolffd@0: if any(inds), xnew(inds) = (x(inds)-(i-1))*r + r0; end wolffd@0: end wolffd@0: x = xnew; wolffd@0: % end of norm_histeqC_undo wolffd@0: wolffd@0: % eval wolffd@0: wolffd@0: function p = norm_eval_init(method) wolffd@0: p = method; wolffd@0: %end of norm_eval_init wolffd@0: wolffd@0: function x = norm_eval_do(x,p) wolffd@0: x_tmp = eval(p{1}); wolffd@0: if size(x_tmp,1)>=1 & size(x,1)>=1 & ... wolffd@0: size(x_tmp,2)==1 & size(x,2)==1, wolffd@0: x = x_tmp; wolffd@0: end wolffd@0: %end of norm_eval_do wolffd@0: wolffd@0: function x = norm_eval_undo(x,p) wolffd@0: x_tmp = eval(p{2}); wolffd@0: if size(x_tmp,1)>=1 & size(x,1)>=1 & ... wolffd@0: size(x_tmp,2)==1 & size(x,2)==1, wolffd@0: x = x_tmp; wolffd@0: end wolffd@0: %end of norm_eval_undo wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: wolffd@0: