?? som_norm_variable.m
字號:
% initialize if strcmp(operation,'init') | ... (strcmp(operation,'do') & strcmp(sNorm(i).status,'uninit')), % case method = 'hist' if strcmp(sNorm(i).method,'hist'), inds = find(~isnan(x) & ~isinf(x)); if length(unique(x(inds)))>20, sNorm(i).method = 'histC'; else sNorm{i}.method = 'histD'; end end switch(sNorm(i).method), case 'var', params = norm_variance_init(x); case 'range', params = norm_scale01_init(x); case 'log', params = norm_log_init(x); case 'logistic', params = norm_logistic_init(x); case 'histD', params = norm_histeqD_init(x); case 'histC', params = norm_histeqC_init(x); case 'eval', params = sNorm(i).params; otherwise, error(['Unrecognized method: ' sNorm(i).method]); end sNorm(i).params = params; sNorm(i).status = 'undone'; end % do / undo if strcmp(operation,'do'), switch(sNorm(i).method), case 'var', x = norm_scale_do(x,sNorm(i).params); case 'range', x = norm_scale_do(x,sNorm(i).params); case 'log', x = norm_log_do(x,sNorm(i).params); case 'logistic', x = norm_logistic_do(x,sNorm(i).params); case 'histD', x = norm_histeqD_do(x,sNorm(i).params); case 'histC', x = norm_histeqC_do(x,sNorm(i).params); case 'eval', x = norm_eval_do(x,sNorm(i).params); otherwise, error(['Unrecognized method: ' sNorm(i).method]); end sNorm(i).status = 'done'; elseif strcmp(operation,'undo'), if strcmp(sNorm(i).status,'uninit'), warning('Could not undo: uninitialized normalization struct.') break; end switch(sNorm(i).method), case 'var', x = norm_scale_undo(x,sNorm(i).params); case 'range', x = norm_scale_undo(x,sNorm(i).params); case 'log', x = norm_log_undo(x,sNorm(i).params); case 'logistic', x = norm_logistic_undo(x,sNorm(i).params); case 'histD', x = norm_histeqD_undo(x,sNorm(i).params); case 'histC', x = norm_histeqC_undo(x,sNorm(i).params); case 'eval', x = norm_eval_undo(x,sNorm(i).params); otherwise, error(['Unrecognized method: ' sNorm(i).method]); end sNorm(i).status = 'undone'; elseif ~strcmp(operation,'init'), error(['Unrecognized operation: ' operation]) endend return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subfunctions% linear scalingfunction p = norm_variance_init(x) inds = find(~isnan(x) & isfinite(x)); p = [mean(x(inds)), std(x(inds))]; if p(2) == 0, p(2) = 1; end %end of norm_variance_initfunction p = norm_scale01_init(x) inds = find(~isnan(x) & isfinite(x)); mi = min(x(inds)); ma = max(x(inds)); if mi == ma, p = [mi, 1]; else p = [mi, ma-mi]; end %end of norm_scale01_init function x = norm_scale_do(x,p) x = (x - p(1)) / p(2); % end of norm_scale_dofunction x = norm_scale_undo(x,p) x = x * p(2) + p(1); % end of norm_scale_undo% logarithmfunction p = norm_log_init(x) inds = find(~isnan(x) & isfinite(x)); p = min(x(inds)); % end of norm_log_initfunction x = norm_log_do(x,p) x = log(x - p +1); % if any(~isreal(x)), ok = 0; end % end of norm_log_do function x = norm_log_undo(x,p) x = exp(x) -1 + p; % end of norm_log_undo % logisticfunction p = norm_logistic_init(x) inds = find(~isnan(x) & isfinite(x)); p = [mean(x(inds)), std(x(inds))]; if p(2)==0, p(2) = 1; end % end of norm_logistic_initfunction x = norm_logistic_do(x,p) x = (x-p(1))/p(2); x = 1./(1+exp(-x)); % end of norm_logistic_dofunction x = norm_logistic_undo(x,p) x = log(x./(1-x)); x = x*p(2)+p(1); % end of norm_logistic_undo% histogram equalization for discrete valuesfunction p = norm_histeqD_init(x) inds = find(~isnan(x) & ~isinf(x)); p = unique(x(inds)); % end of norm_histeqD_initfunction x = norm_histeqD_do(x,p) bins = length(p); inds = find(~isnan(x) & ~isinf(x))'; for i = inds, [dummy ind] = min(abs(x(i) - p)); % data item closer to the left-hand bin wall is indexed after RH wall if x(i) > p(ind) & ind < bins, x(i) = ind + 1; else x(i) = ind; end end x = (x-1)/(bins-1); % normalization between [0,1] % end of norm_histeqD_do function x = norm_histeqD_undo(x,p) bins = length(p); x = round(x*(bins-1)+1); inds = find(~isnan(x) & ~isinf(x)); x(inds) = p(x(inds)); % end of norm_histeqD_undo% histogram equalization with partially linear functionsfunction p = norm_histeqC_init(x) % investigate x inds = find(~isnan(x) & ~isinf(x)); samples = length(inds); xs = unique(x(inds)); mi = xs(1); ma = xs(end); % decide number of limits lims = ceil(sqrt(length(xs))); % 2->2,100->10,1000->32,10000->100 % decide limits if lims==1, p = [mi, mi+1]; lims = 2; elseif lims==2, p = [mi, ma]; else p = zeros(lims,1); p(1) = mi; p(end) = ma; binsize = zeros(lims-1,1); b = 1; avebinsize = samples/(lims-1); for i=1:(length(xs)-1), binsize(b) = binsize(b) + sum(x==xs(i)); if binsize(b) >= avebinsize, b = b + 1; p(b) = (xs(i)+xs(i+1))/2; end if b==(lims-1), binsize(b) = samples-sum(binsize); break; else avebinsize = (samples-sum(binsize))/(lims-1-b); end end end % end of norm_histeqC_initfunction x = norm_histeqC_do(x,p) xnew = x; lims = length(p); % handle values below minimum r = p(2)-p(1); inds = find(x<=p(1) & isfinite(x)); if any(inds), xnew(inds) = 0-(p(1)-x(inds))/r; end % handle values above maximum r = p(end)-p(end-1); inds = find(x>p(end) & isfinite(x)); if any(inds), xnew(inds) = lims-1+(x(inds)-p(end))/r; end % handle all other values for i=1:(lims-1), r0 = p(i); r1 = p(i+1); r = r1-r0; inds = find(x>r0 & x<=r1); if any(inds), xnew(inds) = i-1+(x(inds)-r0)/r; end end % scale so that minimum and maximum correspond to 0 and 1 x = xnew/(lims-1); % end of norm_histeqC_dofunction x = norm_histeqC_undo(x,p) xnew = x; lims = length(p); % scale so that 0 and 1 correspond to minimum and maximum x = x*(lims-1); % handle values below minimum r = p(2)-p(1); inds = find(x<=0 & isfinite(x)); if any(inds), xnew(inds) = x(inds)*r + p(1); end % handle values above maximum r = p(end)-p(end-1); inds = find(x>lims-1 & isfinite(x)); if any(inds), xnew(inds) = (x(inds)-(lims-1))*r+p(end); end % handle all other values for i=1:(lims-1), r0 = p(i); r1 = p(i+1); r = r1-r0; inds = find(x>i-1 & x<=i); if any(inds), xnew(inds) = (x(inds)-(i-1))*r + r0; end end x = xnew; % end of norm_histeqC_undo% evalfunction p = norm_eval_init(method) p = method; %end of norm_eval_initfunction x = norm_eval_do(x,p) x_tmp = eval(p{1}); if size(x_tmp,1)>=1 & size(x,1)>=1 & ... size(x_tmp,2)==1 & size(x,2)==1, x = x_tmp; end %end of norm_eval_dofunction x = norm_eval_undo(x,p) x_tmp = eval(p{2}); if size(x_tmp,1)>=1 & size(x,1)>=1 & ... size(x_tmp,2)==1 & size(x,2)==1, x = x_tmp; end %end of norm_eval_undo%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -